Howto setup mysql-cluster (beginners tutorial)

August 12, 2010 7 comments

Introduction

This HOWTO is designed for a classic setup of two servers behind a load-balancer. The aim is to have true redundancy – either server can be unplugged and yet the site will remain up.

Notes:

You MUST have a third server as a management node but this can be shut down after the cluster starts. Also note that I do not recommend shutting down the management server (see the extra notes at the bottom of this document for more information). You can not run a MySQL Cluster with just two servers And have true redundancy.

Although it is possible to set the cluster up on two physical servers you WILL NOT GET the ability to “kill” one server and for the cluster to continue as normal. For this you need a third server running the management node.

we are going to talk about three servers:

node01.example.com 192.168.0.10

node02.example.com 192.168.0.20

node03.example.com 192.168.0.30

Servers node01 and node02 will be the two that end up “clustered”. This would be perfect for two servers behind a loadbalancer or using round robin DNS and is a good replacement for replication. Server node03 needs to have only minor changes made to it and does NOT require a MySQL install. It can be a low-end machine and can be carrying out other tasks.

Get the software:

For Generally Available (GA), supported versions of the software, download from

http://www.mysql.com/downloads/cluster/

Make sure that you select the correct platform – in this case, “Linux – Generic” and then the correct architecture (for LINUX this means x86 32 or 64 bit).

Note: Only use MySQL Server executables (mysqlds) that come with the MySQL Cluster installation.

STAGE1: Installation of Data and SQL nodes on node01 and node02

On each of the machines designated to host data or SQL nodes(in our case node01 and node02), perform the following steps as the system root user:

  1. create a new mysql user group, and then add a mysql user to this group:
    shell> groupadd mysql

    shell> useradd -g mysql mysql


  2. Change location to the directory containing the downloaded file, unpack the archive, and create a symlink to the mysql directory named mysql. Note that the actual file and directory names vary according to the MySQL Cluster version number.
    shell> cd /var/tmp

    shell> tar -C /usr/local -xzvf mysql-cluster-gpl-7.1.5-linux-x86_64-glibc23.tar.gz

    shell> ln -s /usr/local/mysql-cluster-gpl-7.1.5-linux-i686-glibc23 /usr/local/mysql

    shell> export PATH=$PATH:/usr/local/mysql/bin

    shell> echo “export PATH=\$PATH:/usr/local/mysql/bin” >> /etc/bash.bashrc

  3. Change location to the mysql directory and run the supplied script for creating the system databases:
    shell> cd mysql

    shell> ./scripts/mysql_install_db –user=mysql

  4. Set the necessary permissions for the MySQL server and data directories:
    shell> chown -R root .

    shell> chown -R mysql data

    shell> chgrp -R mysql .

  5. Copy the MySQL startup script to the appropriate directory, make it executable, and set it to start when the operating system is booted up:
    shell> cp support-files/mysql.server /etc/init.d/mysql

    shell> chmod +x /etc/init.d/mysql

    shell> update-rc.d mysql defaults

STAGE2: Installation of Management node on node03

Installation of the management node does not require the mysqld binary. Only the MySQL Cluster management server (ndb_mgmd) is required; I assume that you have placed mysql-cluster-gpl-7.1.5-linux-i686-glibc23.tar.gz in /var/tmp.

As system root perform the following steps to install ndb_mgmd and ndb_mgm on the Cluster management node host (node02):

  1. Change location to the /var/tmp directory, and extract the ndb_mgm and ndb_mgmd from the archive into a suitable directory such as /usr/local/bin:
    shell> cd /var/tmp

    shell> tar -zxvf mysql-cluster-gpl-7.1.5-linux-i686-glibc23.tar.gz

    shell> cd /usr/local/mysql-cluster-gpl-7.1.5-linux-i686-glibc23

    shell> cp bin/ndb_mgm* /usr/local/bin

  2. Change location to the directory into which you copied the files, and then make both of them executable:
    shell> cd /usr/local/bin

    shell> chmod +x ndb_mgm*

STAGE3: Configuration of Management node

The first step in configuring the management node is to create the directory in which the configuration file can be found and then to create the file itself. For example (running as root):

shell> mkdir /var/lib/mysql-cluster

shell> cd /var/lib/mysql-cluster

shell> vi config.ini

For our setup, the config.ini file should read as follows:

[ndbd default]

NoOfReplicas=2

DataMemory=80M

IndexMemory=18M

[tcp default]

[ndb_mgmd]

hostname=192.168.0.30 # Hostname or IP address of MGM node

datadir=/var/lib/mysql-cluster # Directory for MGM node log files

[ndbd]

hostname=192.168.0.10 # Hostname or IP address

datadir=/usr/local/mysql/data # Directory for this data node’s data files

[ndbd]

hostname=192.168.0.20 # Hostname or IP address

datadir=/usr/local/mysql/data # Directory for this data node’s data files

[mysqld]

hostname=192.168.0.10 # Hostname or IP address

[mysqld]

hostname=192.168.0.20 # Hostname or IP address

STAGE4: Configuration of Data and SQL nodes

The first step in configuring the management node is to create the directory in which the configuration file can be found and then to create the file itself. For example (running as root):

shell> vi /etc/my.cnf

Note :
We show vi being used here to create the file, but any text editor should work just as well.

For each data node and SQL node in our setup, my.cnf should look like this:

[client]

port = 3306

socket = /tmp/mysql.sock

[mysqld]

port = 3306

socket = /tmp/mysql.sock

skip-locking

ndbcluster # run NDB storage engine

ndb-connectstring=192.168.0.30 # location of management server

[mysql_cluster]

ndb-connectstring=192.168.0.30 # location of management server

Important :
Once you have started a mysqld process with the NDBCLUSTER and ndb-connectstring parameters in the [mysqld] in the my.cnf file as shown previously, you cannot execute any CREATE TABLE or ALTER TABLE statements without having actually started the cluster. Otherwise, these statements will fail with an error.

STAGE4: Starting the MySQL Cluster

Starting the cluster is not very difficult after it has been configured. Each cluster node process must be started separately, and on the host where it resides. The management node should be started first, followed by the data nodes, and then finally by any SQL nodes:

  1. On the management host(node03), issue the following command from the system shell to start the management node process:
    shell> ndb_mgmd -f /var/lib/mysql-cluster/config.ini –configdir=/var/lib/mysql-clusetr
  2. On each of the Data/SQL node hosts, run these commands to start the ndbd and mysql server process:
    shell> /usr/local/mysql/bin/ndbd

    shell> /etc/init.d/mysql start

If all has gone well, and the cluster has been set up correctly, the cluster should now be operational. You can test this by invoking the ndb_mgm management node client. The output should look like that shown here:

node03:~# ndb_mgm

– NDB Cluster — Management Client –

ndb_mgm> SHOW

Connected to Management Server at: localhost:1186

Cluster Configuration

———————

[ndbd(NDB)] 2 node(s)

id=2 @192.168.0.10 (mysql-5.1.44 ndb-7.1.5, Nodegroup: 0, Master)

id=3 @192.168.0.20 (mysql-5.1.44 ndb-7.1.5, Nodegroup: 0)

[ndb_mgmd(MGM)] 1 node(s)

id=1 @192.168.0.30 (mysql-5.1.44 ndb-7.1.5)

[mysqld(API)] 2 node(s)

id=4 @192.168.0.10 (mysql-5.1.44 ndb-7.1.5)

id=5 @192.168.0.20 (mysql-5.1.44 ndb-7.1.5)

STAGE5: Testing the Setup

If you are OK to here it is time to test mysql. On either server node01 or node02 enter the following commands: Note that we have no root password yet:

shell> mysql

create database testdb;

use test;

CREATE TABLE cluster_test (i INT) ENGINE=NDBCLUSTER;

INSERT INTO cluster_test (i) VALUES (1);

SELECT * FROM cluster_test;

You should see 1 row returned (with the value 1).

If this works, now go to the other server and run the same SELECT and see what you get. Insert from that host and go back to previous host and see if it works. If it works then congratulations!

Save 90% on international calls and sms with Vopium

March 15, 2010 2 comments

If you are living abroad or frequently call your family and friends abroad you can save upto 90% on international calls and sms with Vopium, a Copenhagen – Denmark based company. VopiumVopium provides it’s users variety of simple ways to make international calls and sms via it’s web portal and mobile application, Vopium is a mobile phone application supported on variety of platforms (symbian, iphone, android, java).

Apart from international calls and sms plans, Vopium enables it’s users to talk and chat using Skype, Google Talk, Msn and Yahoo.

Currently Vopium is available in 18 countries including Australia, Belgium, Denmark, France, Finland, Germany, Netherlands, Italy, Norway, Spain, Switzerland, Sweden, UK & USA.

To find out more and get started with Vopium, visit vopium.com

retrieve skype contact photos using python

September 5, 2009 1 comment

tonight i was looking for a way to retrieve display pictures of my skype contacts from .dbb files and ended up with this small piece of code. i don’t find it much useful though but someone might be interesting so here it is.

#!/usr/bin/env python
#
# Author Ghulam Mustafa <mustafa.pk@gmail.com>
#
## This program is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License version
## 2 as published by the Free Software Foundation.

## This program is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
## General Public License version 2 for more details.

## You should have received a copy of the GNU General Public License
## version 2 along with this program; if not, write to the Free
## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
## MA 02110-1301, USA.

profile = '/home/mustafa/.Skype/cyrenity/'

skypefiles = ["user256", "user1024", "user4096", "user16384", "user32768", "user65536",
              "profile256", "profile1024", "profile4096", "profile16384", "profile32768"]

##retrieve contents of skype binary files and store them in a single variable
skbin = []
n = 0
for f in skypefiles:
 fil = "%s%s.dbb" % (profile, f)
 try: skbin.append(file(fil, "rb").read())
 except: pass
 n = n + 1

binary = "".join(skbin)
##

## get_icon(username, binary)
## returns
##    True if successfull
##     None if failed
##    -1 if user not found
def get_icon(buddy, binary):
 startmark = "\xff\xd8"
 endmark = "\xff\xd9"

 startfix = 0
 endfix = 2

 nick_start = "\x03\x10%s" % buddy
 nick_end = "0"

 nickstart = binary.find(nick_start)
 if nickstart == -1: return -1
 nickend = binary.find(nick_end, nickstart)
 handle = binary[nickstart+2:nickend]
 blockstart = binary.rfind("l33l", 0, nickend)
 imgstart = binary.find(startmark, blockstart, nickend)
 imgend = binary.find(endmark, imgstart)

 imgstart += startfix
 imgend += endfix
 if (imgstart < 1): return None
 ##print "JPG %s from %d to %d" % (handle, imgstart, imgend)
 jpg = binary[imgstart:imgend]
 jpgfile = file("%s.jpg" % (handle), "wb")
 jpgfile.write(jpg)
 jpgfile.close()
 return True

users = ['cyrenity', 'gmustafa9']
for user in users:
 status = get_icon(user, binary)
 if status and status != -1:
  print "success [%s]" % user
 else:
  print "failed[%s] [%s]" % (status, user)


p.s. you are encouraged to send me update if you found a bug or fix something. :)

howto install Karaka: xmpp gateway to skype!

July 16, 2009 2 comments

You came here searching for howto install karaka. Vipdia Limited doesn’t tell much on how to setup karaka step by step, yesterday someone asked this question on karaka-discuss mailing list, this post is helpful for you if you are thinking about giving karaka a try.

more here: http://groups.google.com/group/karaka-discuss/browse_thread/thread/d6eb8fcd61bd3e05

update and retrieve twitter timeline from linux shell

January 24, 2009 8 comments

you can update your twitter status and follow feeds using linux shell, this is a quick tip for linux lover’s, this is the reason i prefer linux over other operating systems is it’s total usefullnes,

to post your status on twitter type:

curl -s -u username:password -d status="your_status_message goes here" http://twitter.com/statuses/update.xml > /dev/null

replace username, password and message to post with the your own.

to follow feeds from twitter.

curl -s -u username:password http://twitter.com/statuses/friends_timeline.rss | grep title | sed -e 's/]*>//g'

replace username and password with your own. above command will retrieve recent rss entries from your twitter timeline.

one more cool thing you can do with this long command is to enclose it put it in a text file, let’s say “/usr/local/bin/get-twits” and make it exectuable by issuing

chmod a+x /usr/local/bin/get-twits

now open a new terminal windows and type:  watch --interval=60 get-twits

this command will keep your terminal windows updated with recent twitter updates.

enjoy :-)

cloning harddrives over network

December 30, 2008 5 comments

To clone identical drives in a linux system you can use dd command, dd command makes it really easy.

dd if=/dev/hda of=/dev/hdb

above command will clone hda to hdb (partitions, boot record etc), but what if you have to clone a drive that is not attached to same system?

I found a really interesting way to transfer files over the network simple by using netcat and dd.

  • Boot the machine (where second drive is attached) with a live cd distro like Ubuntu or Knoppix. Setup networking or let the DHCP server assign an ip automatically. My DHCP assigned this machine ip 192.168.0.21
  • run following command on this machine
    nc -l -p 7777 | dd of=/dev/hdb
    (where /dev/hdb is the target drive)
  • Now come to the machine where you have attached the drive to be cloned and issue following command.
    dd if=/dev/hda | nc 192.168.0.21 7777
    (/dev/hda is the drive to be cloned)

It will take time (usually several hours) depending on size of the drive. If you are worried about bandwidth you can pipe through gzip to compress and uncompress the streamed data on source and destination machine respectively, to do this you would run following commands.

On target machine:

nc -l -p 7777 | gzip –dfc | dd of=/dev/hdb

And on source machine.

dd if=/dev/hda | gzip –cf | nc 192.168.0.21 7777

have fun with dd and nc :)

Categories: linux, ubuntu Tags: , , ,

asterisk 1.2 with realtime ldap driver

December 28, 2008 9 comments

I have created an auto install script based on http://www.cahilig.org/install-asterisk-12-auto-install-script-centos-4-and-centos-5 to install Asterisk 1.2 with ldap realtime driver support (modified original script to enable realtime ldap support).

This script should work almost with any(Redhat, Centos, Mandrake, Debian, Slackware) Linux distro

Before running this script you must install following packages.

For Centos, Redhat:

yum install openldap-devel gcc kernel-devel bison openssl-devel libtermcap-devel ncurses-devel

For Debian, Ubuntu:

apt-get install libldap2-dev build-essential linux-headers-`uname -r` libncurses5-dev libssl-dev

You can download the script from here, simply run the script to start installation process.

download Asterisk schema for OpenLdap here

Installer and installation process is not tested, if you find any problem please let me know.

#!/bin/sh
#Asterisk Download page
ZAPTEL="http://downloads.digium.com/pub/zaptel/releases/zaptel-1.2.9.tar.gz"
ASTERISK="http://downloads.digium.com/pub/asterisk/releases/asterisk-1.2.30.tar.gz"
ASTERISKADDONS="http://downloads.digium.com/pub/asterisk/releases/asterisk-addons-1.2.9.tar.gz"
RTLDAP="http://free.oxymium.net/Asterisk/res_config_ldap.tgz"
RTLDAPPATCH="http://mustafa.pk.googlepages.com/res_config_ldap.c.patch"
CONFIGPATCH="http://mustafa.pk.googlepages.com/config.c.patch"
MAKEFILEPATCH="http://mustafa.pk.googlepages.com/resmkfile.patch"
#Asterisk Package
ZAPPACKAGE="zaptel-1.2.9.tar.gz"
ASTPACKAGE="asterisk-1.2.30.tar.gz"
ASTADDONSPACKAGE="asterisk-addons-1.2.9.tar.gz"
#Asterisk Folder
ZAPFOLDER="zaptel-1.2.9"
ASTFOLDER="asterisk-1.2.30"
ASTADDONSFOLDER="asterisk-addons-1.2.9"
REALTIMEDIRVER="res_config_ldap.tgz"
if [ -f /etc/redhat-release ] ; then
DISTRO="redhat"
elif [ -f /etc/debian_version ] ; then
DISTRO="debian"
elif [ -f /etc/SUSE-release ] ; then
DISTRO="redhat"
elif [ -f /etc/mandrake-release ] ; then
DISTRO="mandrake"
elif [ -f /etc/slackware-release ] ; then
DISTRO="slackware"
elif [ -f /etc/gentoo-release ] ; then
DISTRO="gentoo"
fi

echo "Downloading and extracting zaptel and asterisk source"
cd /usr/local/src/
if [ ! -e $ZAPPACKAGE ]; then
  wget $ZAPTEL
fi
if [ ! -e $ASTPACKAGE ]; then
  wget $ASTERISK
fi
if [ ! -e $ASTADDONSPACKAGE ]; then
  wget $ASTERISKADDONS
fi
tar -zvxf $ZAPPACKAGE
tar -zvxf $ASTPACKAGE
tar -zvxf $ASTADDONSPACKAGE 

echo "Installing zaptel"
cd $ZAPFOLDER
make clean
make
make install
cd ..

echo "Installing asterisk"
cd $ASTFOLDER
echo "Downloading patches"
wget $CONFIGPATCH
wget $MAKEFILEPATCH
patch -p0<resmkfile.patch
patch -p0<config.c.patch
echo "Downloading Realtime Ldap driver"
cd res
wget $RTLDAP
tar -zxvf $REALTIMEDIRVER
wget $RTLDAPPATCH
patch -p0<res_config_ldap.c.patch
cd ../configs
wget http://mustafa.pk.googlepages.com/extconfig.conf.sample
wget http://mustafa.pk.googlepages.com/res_ldap.conf.sample
cd ..
make clean
make
make install
make samples
cp contrib/init.d/rc.$DISTRO.asterisk /etc/init.d/asterisk
cd ..

echo "Installing asterisk-addons"
cd $ASTADDONSFOLDER
make clean
make
make install

echo "Loading ztdummy driver"
modprobe zaptel
modprobe ztdummy

echo "adding rules to /etc/rc.local"

echo "modprobe zaptel
modprobe ztdummy
" >> /etc/rc.local

echo "Downloading open source g729 codec"
cd /usr/lib/asterisk/modules/
wget http://asterisk.hosting.lv/bin12/codec_g729-ast12-gcc4-glibc-pentium4.so

echo "Running Asterisk"
/etc/init.d/asterisk start

echo "***********************************************************************"
echo "*             INSTALLATION SUCCESSFUL                                 *"
echo "***********************************************************************"
echo "* You can test if Asterisk installed successfully using               *"
echo "* asterisk -ncrvvv and start configuring your dial plan               *"
echo "***********************************************************************"
exit

“kill -9″ song by monzy

December 27, 2008 1 comment

really funny rap song about “kill -9″ command by Monzy at stanford university.

check it out: audio, video, lyrics

Categories: linux, videos Tags: , ,

open source social networking with elgg

December 27, 2008 4 comments

if you are planning to create your own social networking website, instead of working from scratch, check out Elgg. Elgg is an open source social networking platform.

from their website:

“Elgg is an open, flexible social networking engine, designed to run at the heart of any socially-aware application. Building on Elgg is easy, and because the engine handles common web application and social functionality for you, you can concentrate on developing your idea.”

Elgg can be extended through plugins, plugins provide ways of adding functionality to Elgg like facebook applications.

evolution of a programmer

December 15, 2008 3 comments

High School/Junior High

  10 PRINT "HELLO WORLD"
  20 END

First year in College

  program Hello(input, output)
    begin
      writeln('Hello World')
    end.

Senior year in College

  (defun hello
    (print
      (cons 'Hello (list 'World))))

New professional

  #include
  void main(void)
  {
    char *message[] = {"Hello ", "World"};
    int i;

    for(i = 0; i < 2; ++i)
      printf("%s", message[i]);
    printf("\n");
  }

Seasoned professional

  #include
  #include 

  class string
  {
  private:
    int size;
    char *ptr;

  public:
    string() : size(0), ptr(new char('')) {}

    string(const string &s) : size(s.size)
    {
      ptr = new char[size + 1];
      strcpy(ptr, s.ptr);
    }

    ~string()
    {
      delete [] ptr;
    }

    friend ostream &operator <<(ostream &, const string &);
    string &operator=(const char *);
  };

  ostream &operator<<(ostream &stream, const string &s)
  {
    return(stream << s.ptr);
  }

  string &string::operator=(const char *chrs)
  {
    if (this != &chrs)
    {
      delete [] ptr;
     size = strlen(chrs);
      ptr = new char[size + 1];
      strcpy(ptr, chrs);
    }
    return(*this);
  }

  int main()
  {
    string str;

    str = "Hello World";
    cout << str << endl;

    return(0);
  }

Master Programmer

  [
  uuid(2573F8F4-CFEE-101A-9A9F-00AA00342820)
  ]
  library LHello
  {
      // bring in the master library
      importlib("actimp.tlb");
      importlib("actexp.tlb");

      // bring in my interfaces
      #include "pshlo.idl"

      [
      uuid(2573F8F5-CFEE-101A-9A9F-00AA00342820)
      ]
      cotype THello
   {
   interface IHello;
   interface IPersistFile;
   };
  };

  [
  exe,
  uuid(2573F890-CFEE-101A-9A9F-00AA00342820)
  ]
  module CHelloLib
  {

      // some code related header files
      importheader();
      importheader();
      importheader();
      importheader("pshlo.h");
      importheader("shlo.hxx");
      importheader("mycls.hxx");

      // needed typelibs
      importlib("actimp.tlb");
      importlib("actexp.tlb");
      importlib("thlo.tlb");

      [
      uuid(2573F891-CFEE-101A-9A9F-00AA00342820),
      aggregatable
      ]
      coclass CHello
   {
   cotype THello;
   };
  };

  #include "ipfix.hxx"

  extern HANDLE hEvent;

  class CHello : public CHelloBase
  {
  public:
      IPFIX(CLSID_CHello);

      CHello(IUnknown *pUnk);
      ~CHello();

      HRESULT  __stdcall PrintSz(LPWSTR pwszString);

  private:
      static int cObjRef;
  };

  #include
  #include
  #include
  #include
  #include "thlo.h"
  #include "pshlo.h"
  #include "shlo.hxx"
  #include "mycls.hxx"

  int CHello::cObjRef = 0;

  CHello::CHello(IUnknown *pUnk) : CHelloBase(pUnk)
  {
      cObjRef++;
      return;
  }

  HRESULT  __stdcall  CHello::PrintSz(LPWSTR pwszString)
  {
      printf("%ws\n", pwszString);
      return(ResultFromScode(S_OK));
  }

  CHello::~CHello(void)
  {

  // when the object count goes to zero, stop the server
  cObjRef--;
  if( cObjRef == 0 )
      PulseEvent(hEvent);

  return;
  }

  #include
  #include
  #include "pshlo.h"
  #include "shlo.hxx"
  #include "mycls.hxx"

  HANDLE hEvent;

   int _cdecl main(
  int argc,
  char * argv[]
  ) {
  ULONG ulRef;
  DWORD dwRegistration;
  CHelloCF *pCF = new CHelloCF();

  hEvent = CreateEvent(NULL, FALSE, FALSE, NULL);

  // Initialize the OLE libraries
  CoInitializeEx(NULL, COINIT_MULTITHREADED);

  CoRegisterClassObject(CLSID_CHello, pCF, CLSCTX_LOCAL_SERVER,
      REGCLS_MULTIPLEUSE, &dwRegistration);

  // wait on an event to stop
  WaitForSingleObject(hEvent, INFINITE);

  // revoke and release the class object
  CoRevokeClassObject(dwRegistration);
  ulRef = pCF->Release();

  // Tell OLE we are going away.
  CoUninitialize();

  return(0); }

  extern CLSID CLSID_CHello;
  extern UUID LIBID_CHelloLib;

  CLSID CLSID_CHello = { /* 2573F891-CFEE-101A-9A9F-00AA00342820 */
      0x2573F891,
      0xCFEE,
      0x101A,
      { 0x9A, 0x9F, 0x00, 0xAA, 0x00, 0x34, 0x28, 0x20 }
  };

  UUID LIBID_CHelloLib = { /* 2573F890-CFEE-101A-9A9F-00AA00342820 */
      0x2573F890,
      0xCFEE,
      0x101A,
      { 0x9A, 0x9F, 0x00, 0xAA, 0x00, 0x34, 0x28, 0x20 }
  };

  #include
  #include
  #include
  #include
  #include
  #include "pshlo.h"
  #include "shlo.hxx"
  #include "clsid.h"

  int _cdecl main(
  int argc,
  char * argv[]
  ) {
  HRESULT  hRslt;
  IHello        *pHello;
  ULONG  ulCnt;
  IMoniker * pmk;
  WCHAR  wcsT[_MAX_PATH];
  WCHAR  wcsPath[2 * _MAX_PATH];

  // get object path
  wcsPath[0] = '';
  wcsT[0] = '';
  if( argc > 1) {
      mbstowcs(wcsPath, argv[1], strlen(argv[1]) + 1);
      wcsupr(wcsPath);
      }
  else {
      fprintf(stderr, "Object path must be specified\n");
      return(1);
      }

  // get print string
  if(argc > 2)
      mbstowcs(wcsT, argv[2], strlen(argv[2]) + 1);
  else
      wcscpy(wcsT, L"Hello World");

  printf("Linking to object %ws\n", wcsPath);
  printf("Text String %ws\n", wcsT);

  // Initialize the OLE libraries
  hRslt = CoInitializeEx(NULL, COINIT_MULTITHREADED);

  if(SUCCEEDED(hRslt)) {

      hRslt = CreateFileMoniker(wcsPath, &pmk);
      if(SUCCEEDED(hRslt))
   hRslt = BindMoniker(pmk, 0, IID_IHello, (void **)&pHello);

      if(SUCCEEDED(hRslt)) {

   // print a string out
   pHello->PrintSz(wcsT);

   Sleep(2000);
   ulCnt = pHello->Release();
   }
      else
   printf("Failure to connect, status: %lx", hRslt);

      // Tell OLE we are going away.
      CoUninitialize();
      }

  return(0);
  }

Apprentice Hacker

  #!/usr/local/bin/perl
  $msg="Hello, world.\n";
  if ($#ARGV >= 0) {
    while(defined($arg=shift(@ARGV))) {
      $outfilename = $arg;
      open(FILE, ">" . $outfilename) || die "Can't write $arg: $!\n";
      print (FILE $msg);
      close(FILE) || die "Can't close $arg: $!\n";
    }
  } else {
    print ($msg);
  }
  1;

Experienced Hacker

  #include
  #define S "Hello, World\n"
  main(){exit(printf(S) == strlen(S) ? 0 : 1);}

Seasoned Hacker

  % cc -o a.out ~/src/misc/hw/hw.c
  % a.out

Guru Hacker

  % cat
  Hello, world.
  ^D

New Manager

  10 PRINT "HELLO WORLD"
  20 END

Middle Manager

  mail -s "Hello, world." bob@b12
  Bob, could you please write me a program that prints "Hello,
 world."?
  I need it by tomorrow.
  ^D

Senior Manager

  % zmail jim
  I need a "Hello, world." program by this afternoon.

Chief Executive

  % letter
  letter: Command not found.
  % mail
  To: ^X ^F ^C
  % help mail
  help: Command not found.
  % damn!
  !: Event unrecognized
  % logout
Categories: Uncategorized Tags: ,
Follow

Get every new post delivered to your Inbox.