Sunday, 23 September 2012

Pylab spectogram with log. frequency scale

Since the IPython notebook is coolest Open Source project I know, I started doing many prototyping tasks with IPython. The notebook is a great tool not only for DSP, but also for data analysis (SQL), debugging and testing. With Firefox it is easy to create a PDF from your work and show it to colleagues or a customer.

For audio programming I often need a spectrogram that has a logarithmic frequency scale. Matplotlib hasn't got that feature (it doesn't work) and I couldn't find a module on the web, so I hacked a few lines, it uses numpy, scipy and matplotlib. The memory and performance optimisation might be a bit off-the-wall, but it works well.

Saturday, 22 September 2012

IPython notebook display tools for database cursors and dictionaries

While doing some data analysis I hacked these pretty printers for the IPython notebook. I used it with sqlite, mysql and python dicts.
Call html_settings() one time in your notebook.

Update 26-Sept-12: Python3 compatibility and cleanup.

Thursday, 20 September 2012

Bash history of unique commands

Ctrl-r in the bash is a great feature. I use it like bookmarks in a webbrowser. But you loose commands very fast, they are pushed out of the history. There are many native ways (HISTCONTROL) to make bash history entries unique. None worked for me, native bash settings either work for joining multiple bash sessions or enforcing uniqueness, both features at once doesn't work seamless.

I hacked a small python script that cleans the bash history the way I like it.
  • If it removes duplicated entries it will remove the oldest
  • It will only change the history when you enter a new command
  • It will notify you with a + sign that it added a command
  • It will only write to the harddisk if you added a new command
  • It will not loose commands like using HISTCONTROL when joining multple bash sessions history
  • It locks the history file, to avoid race-conditions (usually you don't enter commands in two windows at once, but you never know)
I use it for 2 month by now and I use the bash everyday, every few minutes while working at the moment I have 2665 unique commands:
Sherlock:~ ganwell$ wc -l .my_history 
    2665 .my_history

Changes to .profile:
profile.sh
The source of unique_history:
unique_history.py

Sunday, 16 September 2012

SSH to a host and take your tmux.conf and vimrc

The script connects to a remote host and sets tmux and vim up. You should customize this to suit your workflow. Out of the box it supports most unix, I wrote a special case that was needed to find tmux on Solaris using OpenCSW.

It uses a share master connection, you should create the directory: ~/.ssh/cm

rmux.bash