Tim Keller

Web, IT, Telecoms, Development, Networks, Photography, Life.

Archive for the ‘OSX’ tag

Google Go

without comments

Go Logo

Google is touting its new Go language as a modern systems programming language which is expressive, concurrent, garbage-collected. Go takes the development speed of working in a dynamic language like Python, and combines it with the performance and safety of a compiled language like C or C++.

In its Go FAQ, Google explains the main motivations behind the project:

No major systems language has emerged in over a decade, but over that time the computing landscape has changed tremendously. There are several trends:

  • Computers are enormously quicker but software development is not faster.
  • Dependency management is a big part of software development today but the “header files” of languages in the C tradition are antithetical to clean dependency analysis—and fast compilation.
  • There is a growing rebellion against cumbersome type systems like those of Java and C++, pushing people towards dynamically typed languages such as Python and JavaScript.
  • Some fundamental concepts such as garbage collection and parallel computation are not well supported by popular systems languages.
  • The emergence of multicore computers has generated worry and confusion.

Bold words from Google, especially considering the number of new languages which have come and gone over the years. Surely its too risky to put the corporate name behind the project? Not once you hear who’s on the team.

The project is being staffed by some serious Computer Science heavyweights: Robert Griesemer, Rob Pike (Unix Team, Plan 9 OS, UTF-8, Inferno), Ken Thompson (inventor of B – forerunner of C, UTF-8, shepherd Unix and Plan 9), Ian Taylor, Russ Cox, Jini Kim and Adam Langley.

Coming from a C/C++ background during my university days, my first Go experience felt quite nostalgic. I grabbed the source via Mercurial, compiled it in the Terminal, and configured some shell environment variables. What I was left with was a native Go compiler for my x64 architecture (6g) and a Go linker (6l). These are the recommended compilation tools until the GCC-based (gccgo) version catches up.

Installation on Snow Leopard

Before you follow these steps, you should have XTools installed. You should also be running Snow Leopard as your OS. These instructions should also work for 10.5 Leopard, but you may have to use GOARCH=386.

Environment

Go needs a couple of shell/environment parameters to be set prior to installation.

Add the following lines to your ~/.bashrc file:

export GOROOT=\$HOME/Go
export GOOS=darwin
export GOARCH=amd64
export GOBIN=\$HOME/bin

Now use the source command to apply those changes:

source ~/.bashrc

Next we need to add the bin directory for Go, and map it on the system path:

mkdir -p $HOME/bin
echo "$HOME/bin" > go
sudo mv go /etc/paths.d/
eval `/usr/libexec/path_helper -s`

Source Code

The Go team are currently using Mercurial to handle the source code. If you don’t already have it installed, you can install it quickly and easily with the following command:

sudo easy_install mercurial

I encountered an issue whereby UTF-8 was not set as my locale language type. While some will not experience this, I had to force this by adding the following lines to your ~/.profile file:

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8

Adjust according to your locale, if neccesary. Big thanks to ricafeal for this.

This will use the Python easy_install tool to install the mercurial package on your system. Once complete, its time to checkout a copy of the Go source code:

hg clone -r release https://go.googlecode.com/hg/ $GOROOT

This will place a full directory of Go source in the directory defined in ~/.bashrc as $GOROOT

Installation

All the Mac OS X particulars are done and you can follow the standard installation procedure. That includes:

cd $GOROOT/src
./all.bash

If you get a message stating…

--- cd ../test
N known bugs; 0 unexpected bugs

… you should be good to go (oh the puns).

Hello World

package main
import "fmt"
func main() {
fmt.Printf("hello, world\n")
}

To compile:

$ 6g hello.go
$ 6l hello.6

To execute:

$ ./6.out
hello, world

You may also want to check out Jeremy’s great little script which lets you compiler (6g) and ink (6l) in one, well, go.

More Go later this week!

Written by Tim Keller

November 16th, 2009 at 5:17 am

PHP+MySQL from the Mac OSX Terminal

without comments

I had to write a CLI PHP script today as part of the job-parser for the SMS module in ChirpSchool. The parser executes every 5 minutes as a cron-job and dispatches waiting messages in the Message Queue.

I ran into a small problem in that the Command-Line-Interface PHP binary was different to the one running on my Apache+Mysql+PHP stack so the CLI PHP didn’t know which MySQL socket to attach to:

Warning: mysqli_connect(): (HY000/2002): Can’t connect to local MySQL server through socket ‘/var/mysql/mysql.sock’

The solution is simple. I am using Mac OSX 10.5.4 Leopard and XAMPP.

  1. Find out which PHP you are using from the terminal by typing ‘whereis php’. It is no doubt /usr/bin/php.
  2. Create a php.ini in /etc. Type ‘sudo cp /etc/php.ini.default /etc/php.ini
  3. Then open this new file in something… I did a ‘sudo nano /etc/php.ini’.
  4. Edit the mysqli.default_socket parameter (or mysql if you aren’t using the new improved driver) to point to the MySQL socket Apache is using. Mine was at /Applications/xampp/xamppfiles/var/mysql/mysql.sock (your’s may be at /tmp/mysql.sock)
  5. Be sure to save this new php.ini. Remember, /etc is protected so you won’t be able to save the file unless you have sudo’d yourself admin rights.
  6. Commenter ferzkopp kindly reminds us that an Apache restart may be neccesary to get this activated. Thanks for the Tip!

Hope this helps!

Written by Tim Keller

July 13th, 2008 at 6:24 am

Posted in Uncategorized

Tagged with , , , , , , , ,