Tuesday, April 26, 2011

Programmer tips for Mac OSX

Some tips for programmers on the Mac.

emacs: the best place to get emacs for Mac seems to be here http://emacsformacosx.com/ which is also the most no nonsense website design ever

Not really a Mac tip, but I stick my .emacs configuration file in a Dropbox folder, along with any emacs libraries and emacs lisp code I write. Then where-ever I install emacs I make a simple .emacs that points to the one in the Dropbox folder. This also forces me to make sure any platform specific emacs stuff is properly handled.

Clipboard: copy and paste between the terminal and other apps can be done with pbcopy and pbpaste. For example a long complicated command line you want to email to yourself, just do:

echo "long complicated bash command line you don't want to retype" | pbcopy

And then you can Command-V that into your email window. Going the other way is just as simple; Command-C the text you want and pop it into the terminal window with pbpaste.

Open: If you want open an application from the command line you can do it like this:

open -a SomeApp /Users/yourname/SomeFile.hai

You can open a folder in finder

open /Folder/

or

open /Folder/SomeFile.hai

to open that file with it's default application.

Check out the help 'man open', to see other stuff like how you pipe stdout into an application.

Finally check out this guys OpenTerminalHere script. This pops an icon in finder that lets you open a terminal window in the highlighted folder.








MovieRatings

A little side project I did when learning about Clojure was to grab movie ratings from Rotten Tomatoes, which I did a post about here:


This is just an update that I've posted the whole leiningen project onto github




Monday, April 25, 2011

Talking to mysql from Python on Mac OS X 10.6




image by Sam Pullara

Here's a problem I couldn't solve with Google, although it seems to be a moving target so YMMV.

I wanted to do some work driving a MySQL database with Python. On Windows and Linux I've used MySQLdb so I decided to do the same on Mac.

For reference I got mysql (client and server) through mac ports.

mysql5 --version
mysql5 Ver 14.14 Distrib 5.1.45, for apple-darwin10.4.0 (i386) using readline 6.1

and Python is the stock version:

Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin

First download from here http://sourceforge.net/projects/mysql-python/ and extract the file somewhere...

mkdir ~/pythondb
cd ~/pythondb
tar -vxf ~/Downloads/MySQL-python-1.2.3.tar.gz

Then you need open up the site.cfg file and make a change as below. Your mysql_config5 maybe in a different spot. You can find out with the command 'which mysql_config5'.

# The path to mysql_config.
# Only use this if mysql_config is not on your PATH, or you have some weird
# setup that requires it.
mysql_config = /opt/local/bin/mysql_config5
Now execute the following:

python setup.py build
python setup.py install

If everything works you can now import MySQLdb in your python program and start interacting with mysql.