Thursday, December 22, 2011

View markdown on Mac OS X

Use the Quicklook plugin from here.

Simpy drop the QLMarkdown.qlgenerator to ~/Library/QuickLook or /Library/QuickLook

Now whenever you select a markdown file (.md) it will format the file and show the formatted version to you through quicklook.

Monday, December 19, 2011

The "page flash" on the kindle

The "page flash" on the Kindle 4 - the sudden turning of all the pixels black and then white, before the page is displayed - occurs every 6 page turns. It seems to be necessary because a certain amount of 'dirt' accumulates inbetween - bold letters (and also normal text) seem to leave traces pixels around the edges of the letters after they have been wiped after a page turn. The 'flash' wipes these pixels out and makes the page look crisp again.

I don't know if this is a flaw in the driver software, or a shortcoming in the e-ink display itself (that leaves the traces).

Thursday, December 15, 2011

Quick state machine in Python

SM = {
  'TEND0': {'TRIALEND': 'TEND1'},

nextstate = SM[currentstate].get(input,currentstate)

Wednesday, December 14, 2011

matplotlib installation

  1. freetype2
    sudo make install
  2. libpng (
    sudo make install
  3. sudo easy_install matplotlib

Monday, December 12, 2011

Bye bye eclipse, hello PyCharm and QT creator

I ditched eclipse for C when I found QT Creator. But I still kept it around for my python code, but it got annoying. Then I found PyCharm. I like it. Bye bye eclipse.

Changing how numpy arrays are printed

Use numpy.set_printoptions. One of the things I like most about pylab (and numpy) is this flexibility, especially the summarization feature, which, when the array is very large, prints ellipses (...) instead of clobbering you with lines and lines of output. I like to set the threshold low (default is 1000) and I do this with pylab.set_printoptions(threshold=10)

Wednesday, December 7, 2011

Mac OS Lion : install matplotlib

  1. Download source
  2. "Building mpl on Mac OS X is a nightmare" - John Hunter
  3. Use his very effective make.osx:
  4. sudo make -f make.osx PREFIX=/temp/build/dir PYVERSION=2.7 fetch deps mpl_install_std
  5. Remove old ~/.matplotlib directory (some weird warnings)

Tuesday, December 6, 2011

Mac OS X install pytables and h5py

  1. Install tables - need NumPy version 1.6
  2. Get NumPy from sourceforge and install - need Python 2.7
  3. Install python 2.7 on Lion, open new terminal (or refresh path)
  4. curl | python
  5. curl | python
  6. sudo pip install ipython
  7. sudo pip install tables
  8. need numexpr > 1.4.1, 
  9. Download anc ompile numexpr -> wants to compile using gcc-4.2
  10. sudo ln -s gcc gcc-4.2
  11. sudo pip install cython
  12. Get HDf5 from
  13. /configure and compile
  14. Copy the hdf5 folder whereever you want
  15. python build --hdf5=/path/to/hdf5 (from the unzipped source of h5py)
  16. sudo python install --hdf5=/usr/local/hdf5/ (in the unzipped dir of pytables)
In contrast, to get h5py working on Ubuntu:

sudo apt-get install libhdf5-serial-dev
sudo easy_install h5py 

Dealing with strict key checking for SSH


While using sftp (or some other ssh related service) the following warning shows up and we can't use the service:

Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
Please contact your system administrator.
Add correct host key in /Users/xxx/.ssh/known_hosts to get rid of this message.
Offending key in /Users/xxx/.ssh/known_hosts:28
RSA host key for has changed and you have requested strict checking.
Host key verification failed.
Connection closed


Remove the key by doing
sed -i "28 d" ~/.ssh/known_hosts

We know it is line 28, because that came up in the warning message.

github project page checkout for working

git clone -b gh-pages

Mac OS Lion

Things I like
  1. New tab in terminal opens in same folder
  2. Preview can make pdfs by stringing msic documents together
I don't like
  1. Preview is sooo sluggish
  2. Preview messes up some transparency in pdfs
  3. No save as (gotta duplicate etc etc)

Saturday, December 3, 2011

Reading Plexon files into Python

  1. Sample C code is at plx2csv, rather striaghtofrward reading of the plexon binary file
  2. Needed to load the data into Python, so looked at Boost.Python and pybindgen, but then
  3. decided that pickling the data from the c code and loading it into python scripts would be fine and so used
  4. The PicklingTools library.

Thursday, December 1, 2011

++i OR i++ ?

From discussions on stack overflow we have:
  1. ++i does not expect to return a value while i++ might need to return a value.
  2. A modern compiler, for simple data types (i.e. integer) will treat the two the same if the context is right e.g. in a for loop
  3. For an object (e.g. an interator), however, ++i will be faster than i++ because a compiler cannot optimize away the creation of a temporary object for i++