OSX Fish Functions to open Chrome from the Shell

These functions are quite handy, and allow you to do things such as copy and paste errors and google for them without having to manually open a browser. You have to enclose arguments to both functions in single quotes, e.g. ‘chrome ‘http://www.google.co.uk’ and google ‘one two three four’. You should add these to your config file at ~/.config/fish/config.fish and make sure Google Chrome is already installed.

function chrome
  /usr/bin/open -a '/Applications/Google Chrome.app' $argv[1:]
function google
  /usr/bin/open -a '/Applications/Google Chrome.app' "https://www.google.co.uk/search?q=$argv[1]"

Working with Fish Shell, ffmpeg, MP4Box and sox to generate audio files

More adventures with Fish shell. I have scripted the generation of a bunch of test asset audio files in mp4 format suitable for dash streaming. I have used the audio file commandline tools ffmepg MP4Box and sox in this script, they are pretty powerful and worth installing via homebrew on OSX.

Thoughts: I think that instead of quoting you can just output $variable, which is probably better coding style. I’m still working out good way to return variables from functions, it seems that you need to echo out the output and that gets picked up by the calling function, which is a bit messy.

#!/usr/bin/env fish
# move to the asset output directory..
cd ..

# Generate .m4a file for file, and all the associated .mp4 dash assets
function generateDash
  set bitrate $argv[1]
  set input_filename $argv[2]
  set output_filename "$input_filename"-"$bitrate".m4a
  ffmpeg -i "$input_filename" -ab "$bitrate"k "$output_filename"
  MP4Box -dash 10000 "$output_filename"

# Generate 3 second sine wave in a specified bitrate at a specified frequency
function generateWav
  set bitrate $argv[1]
  set filename $argv[2]
  set frequency $argv[3]
  set wavfilename "$filename"-"$bitrate".wav
  sox -n --norm=-3 -b "$bitrate" "$wavfilename" synth 3 sine "$frequency"
  echo $wavfilename

# Main loop, generate 128,192 and 320 bitrate dashed .mp4s for 16bit and 32bit 3 second sine waves
for i in (seq 24)
  set freq (math "$i * 64.5")
  set wavfilename (generateWav 16 "output$i" "$freq")
  generateDash 128 "$wavfilename"
  generateDash 192 "$wavfilename"
  generateDash 320 "$wavfilename"
  set wavfilename (generateWav 24 "output$i" "$freq")
  generateDash 128 "$wavfilename"
  generateDash 192 "$wavfilename"
  generateDash 320 "$wavfilename"

Fish Shell Scripting

A few months ago I switched across from Bash onto the Fish shell, on my main development machine. I can’t get enough of its fast autosuggestions and its sane scripting language. Compared to Bash it is very fun to use.

Today I wrote a script to automate the backup of my development workspace onto a private bitbucket account. Bitbucket is good because it allows unlimited private repositories, but it caps the size of these repos at 2GB max, with some features disabled after 1GB. This means that I want to find out the size of my repo before automatically backing it up. This script does this:

#!/usr/bin/env fish

set size (du -sm . | awk '{print $1}')
echo "Workspace is $size MB"
if math "$size > 1000"
  echo "Workspace too big to commit!"
  echo "Workspace is under 1GB, OK to commit"

git add .
git commit -m "Automated backup"
git push origin master

Each individual directory additionally usually has its own git config which is synced to the separate repos for the code I’m actually working on. But if my development machine is stolen or somehow destroyed, or I want to quickly replicate my environment on another machine with access to the original repos, then I can regenerate the associations between the different directories. It also makes me mindful of not committing images or other video assets.

Top 5 Recommended Upgrades for your PC

I have made a lot of different upgrades and modifications to my PC, as you can see here. Some of the upgrades have made more of a difference than others though. Here is what I think you should be concentrating on, if you’re looking to upgrade.


  • Solid State Hardisk (SSD) – Solid State hard drives use flash memory instead of the moving disk platters of traditional hard disks. It is the same type of storage as your USB stick. This type of storage is a lot faster to access compared to magnetic storage. Upgrading will result in a huge performance increase for most systems if you are changing from a traditional hard disk. Get as big a size as you can afford. If you play computer games or do a lot of media production work, then the added space will be useful. They have reduced in price over the years, the first SSD I bought was £120 for 120GB SSD back in 2012, in 2015 I just bought a 250GB SSD for £50. So it’s definitely affordable now.
  • Large Monitor – If you can get a 27″-32″ monitor then do so. It has made so much difference to the day to day usage of my PC. I would recommend 1440p if you can. 1440p is half the resolution of 4K. I wouldn’t recommend a 4K monitor yet in 2015 as I don’t think they have enough software support, and the cost is considerable for a decent screen. If you’re a gamer, then you might want to aim for a higher refresh speed, but I’d say this should be a secondary consideration to the screen space. Look on TFTCentral for reviews and guides to the different screen types available.
  • Good Soundcard and Surround Sound Speaker System – Headphones are OK, but even a basic surround sound soundcard and speaker system is going to be so much better. I have a Asus Xonar Phoebus Solo which I recommend, it’s a 7.1 surround sound card. I have a cheap £60 set of surround sound speakers, Logitech Z506 Surround Sound Speakers. Surround sound really makes a difference in gaming and movies. I think it’s the seperate subwoofer that has the most effect, so if you are not that convinced by surround sound, you could get a 2.1 (two speakers and a subwoofer) setup for a bit less.
  • Ergonomic Mouse and good mousemat – Chances are, most of the time you’re at your PC, you will be using the mouse. It is therefore really important you have a good mouse that won’t damange your hand after a few years use and is comfortable to use. Modern mice use laser scanners to track the position of the mouse on a flat surface. A higher resolution laser (measured in DPI – dots per inch) means that you can get more accurate tracking. Therefore look for high DPI mice for gaming or fine detail work as well as an ergonomic fit and lots of buttons. I recommend Logitech mice, after having had several Razer mice that didn’t last very long. I would also pick up a steel mousemat, as they never get tangled up in your mouse like the fibre mousemats do.
  • Recent Graphics Card – If you are into gaming or 3D modelling work, you would often prioritise this over any other upgrade. A new graphics card means that your existing games will run faster on higher detail settings, and you can play new games on higher settings with better framerate. I don’t think it matters too much whether you go for Nvidea or AMD as long as you can run the games you want to run. If you are not interested in running the latest games, then perhaps you don’t need this, but you may be missing out in the future.

Too much Scrolling! – Tips for Dealing with Mouse-Wheel Finger Repetitive Strain Injury

Recently I had noticed I’d been having quite bad problems with my fingers based on the fact that I had been scrolling the mouse wheel too much when scrolling through web pages. Here are a number of options you can take if you are in a similar situation as me:

Change OS’s scrolling speed to its maximum

This is the easiest change on most modern OSs, and will result in less scroll movements made by your fingers, because each scroll movement will move the screen down by a full screen height, (equivalent to a page down). This can be a bit annoying though as you lose accuracy when you want to just scroll down a small amount, it takes a bit of getting used to. Also you are still using the same muscles, just not as often.

Use keyboard shortcuts for scrolling

Space and shift-space should perform scrolling up and down in Firefox and Chrome on OSX and Windows. The more you avoid using the mouse and use the keyboard, the less you will use the same muscle in your fingers each time. Of course you may develop keyboard-related RSI, but so far I haven’t been affected by this.

Change to an Ergonomic Mouse

At work I now use an ergonomic Logitch mouse which has a responsive scroll wheel, and an option to ‘unlock’ the movement of the scroll wheel, allowing it to freely spin which results in greater comfort. Before I was using a work mouse which had a scroll wheel which you had to press down very hard to get it to do anything.

Use a Touchpad

You can get freestanding touchpads for Windows and OSX, which operate like a laptop’s touchpad. This has the advantage that you can also use trackpad gestures – Windows 8 onwards and modern versions of OSX have their own sets of handy gestures for speeding up use. I recommend the Logitech T650 Wireless Touchpad for Windows 8 onwards, and the – expensive but very impressive – Apple Magic Pad 2 for OSX . You can also get the Apple Magic Pad 1 which is half the price, but the feedback and gesture support isn’t quite as good. A trackpad is not much use for gaming but for normal browsing and office use it’s fine.

Biggest Disappointment Purchases for PC – Razer Tiamat + Lightpack

As you can see, I buy a lot of bits and pieces for my PC. Occasionally though, I buy something that I feel was a disappointment, or not worth the investment. This post is meant to caution against other people making the same mistake.

Razer Tiamat – 7.1 Surround Sound Gaming Headset, with microphone (http://www.razerzone.com)


This was a big dissapointment in a couple of ways. The first, and most obvious in hindsight now I’m actually working on spatial audio for a living at BBC R&D, is that 7.1 surround sound headsets are a joke. There is no way you can get enough seperation between the different speaker drivers when your ears are so close to the speakers. If you have a soundcard or motherboard that supports surround sound, do yourself a favour and get a surround sound speaker set.

The second problem is that the Razer Tiamat has issues with electrical hum from the unshielded cables it uses. I replaced it with the ROCCAT Kave XTD 5.1 Analog surround sound headset which is better, although still not anything like the surround sound speaker setup which I now have.

Lightpack – Backlight kit with adaptive lighting for games (www.lightpack.tv)


I took a risk on this, it was a kickstarter idea which offered the promise of an ‘intelligent’ backlight which changed colours depending on what was on the screen. And it did work pretty well.. back when I was running Windows 7. Since upgrading to Windows 10, I haven’t been able to get it to work properly when playing games with Playclaw, which is my main use for it. I even had to purchase Playclaw, as the software which comes with Lightpack doesn’t work well. It still has limited use for me in terms of a colour spectrum effect for music when I throw a party, through using third-party software such as Ambibox. But the company really should improve its software to work with Windows 10 gaming. It didn’t even work well for me under Windows 8.

My Favourite OSX Apps for Development

I’ve just recently bought a Macbook Pro for myself, after having used a MBP at work for 4 years. I find it to be a really powerful development environment for the development I do, in languages such as Java, PHP, Ruby, Python and JS. Here is what I use day-to-day:

OSX El Capitan

I haven’t found anything not to like about this upgrade. I don’t use a lot of external devices, for which Bruce has found problems with El Capitan’s new restricted driver management for Arduinos and others. I like the fact I can use split screen functionality to side-by-side two windows easily, a feature that I very much like in Windows 10 too.

iTerm 2

This is an awesome terminal, better than OSX’s terminal. Nothing much more to say about it.

Fish Shell

This shell has fast and smart command-line completion which is very handy and I’d highly recommend it if you use the commandline a lot and are not totally won over by Bash. It looks nice too.


This is pretty much essential for command line OSX. It is a package manager which downloads and compiles the latest version of open source packages on your Mac. If you don’t use it already, get used to it.

IntelliJ WebStorm

WebStorm is great for debugging JavaScript applications, which I seem to be doing a lot of lately. I recommend the IntelliJ IDEA family of IDEs, once you get use to them, they are a great help in productive development. There are also vim and Emacs keybindings.


If you are a fan of vim you will know what I mean when I say I can’t be without it. My Dotfiles show my .vimrc and plugin configuration.


Thankfully the BBC has moved over to Github, meaning all my coding uses Git. It is so useful, and not just for storing code, you can store anything.


I use Apple Music, and iTunes Match, so iTunes is a must. It annoys me at times, but I just have to live with it.


Alfred is a replacement for Spotlight search in OSX. It has a lot of functionality that I’m still getting my head around, but it speeds up my OSX workflow a lot when undertaking frequent tasks such as Google searching.


Evernote is so useful for making and sharing notes on my phone, mac, work computer.. anywhere


This is something someone only recently recommended to me. It seems very useful from what I’ve seen, great way to share images files, screenshots, webcasts.. anything. Also it has as expiry policy for media, like Snapchat, so it doesn’t exist on the internet for generations to come.

Use Siri, Apple Earphones and Apple Music Together

This requires you to have a subscription to Apple Music and a 3G/4G/wireless data connection, but it is so useful! Using this tip, you can be walking along with your iPhone in your pocket and your Apple earphones in, and then change music just by pressing a button on the earphones remote control and saying ‘Play (your favourite band)’.

blog post image

1. Activate Siri and subscribe to Apple Music. I used to subscribe to Spotify so I switched to Apple Music when I realised the advantages of the integration on my phone, and the wider selection of music. You will also need to set Siri to stream music over your cellular network, this can be done in the ‘Music’ section of iOS settings.

2. Put the iPhone in your pocket with the standard Apple Earphones plugged in. With the standard Apple Earphones, there is a remote control on the cable with one button on it. To activate Siri, hold that button down for a couple of seconds until you hear the ‘Siri’ ‘bleep’.

3. Say ‘Play The Prodigy’ if you want to listen to The Prodigy, for example. This may require a couple of tries occasionally, but usually it just works.

4. Siri should look up The Prodigy on Apple Music, find their most popular songs, put them in a playlist, start streaming them and playing them through your earphones. To skip a song, press the remote control button twice in quick succession. To adjust the volume, press the edges of your remote control, the top edge to increase volume, the bottom edge to decrease. To pause all music playback, just press the remote control button once. To resume playback, press the remote control button once again.

A limitation of this is that you have to be in an area with good reception, enough to stream your tracks from Apple Music. You shouldn’t have a problem if you live in a city like Manchester, I usually get 4G across the whole city.

My Aeron Chair

A good ergonomic chair is a wise investment if you’re going to spend a lot of time at your computer. One of the better known ergonomic models is the Herman Miller Aeron Task Chair.

Picture of Aeron Chair

What Other People Say About the Aeron

Jeff Atwood (from Coding Horror) says:

In fact, after browsing chairs for the last few years of my career, I’ve come to one conclusion: you can’t expect to get a decent chair for less than $500. If you are spending less than that on seating – unless you are getting the deal of the century on dot-bomb bankruptcy auctions – you’re probably making a mistake.

I still believe this to be true, and I urge any programmers reading this to seriously consider the value of what you’re sitting in while you’re on the job. In our profession, seating matters:

Chairs are a primary part of the programming experience. Eight hours a day, every day, for the rest of your working life – you’re sitting in one. Like it or not, whatever you’re sitting in has a measurable impact on your work experience.

Cheap chairs suck. Maybe I’ve become spoiled, but I have yet to sit in a single good, cheap chair. In my experience, the difference between the really great chairs and the cheap stuff is enormous. A quality chair is so comfortable and accommodating it effortlessly melts into the background, so you can focus on your work. A cheesy, cheap chair constantly reminds you how many hours of work you have left.

Chairs last. As I write this, I’m still sitting my original Aeron chair, which I purchased in 1998. I can’t think of any other piece of equipment I use in my job that has lasted me ten full years and beyond. While the initial sticker shock of a quality chair may turn you off, try to mentally amortize that cost across the next ten years or more.

Joel Spolsky (from Joel On Software) says:

Let me, for a moment, talk about the famous Aeron chair, made by Herman Miller. They cost about $900. This is about $800 more than a cheap office chair from OfficeDepot or Staples.

They are much more comfortable than cheap chairs. If you get the right size and adjust it properly, most people can sit in them all day long without feeling uncomfortable. The back and seat are made out of a kind of mesh that lets air flow so you don’t get sweaty. The ergonomics, especially of the newer models with lumbar support, are excellent.

They last longer than cheap chairs. We’ve been in business for six years and every Aeron is literally in mint condition: I challenge anyone to see the difference between the chairs we bought in 2000 and the chairs we bought three months ago. They easily last for ten years. The cheap chairs literally start falling apart after a matter of months. You’ll need at least four $100 chairs to last as long as an Aeron.

There was a post with a large set of comments on Hacker News about chairs and cheap alternatives to Aeron Chairs, with a lot of people saying that there is no cheap alternative to a good chair.

What I Say About the Aeron

I just got a refurbished Aeron chair for Christmas. I am really pleased with it. It comes in three base sizes, being larger than normal I went for the Size C. Once it arrived it was a good fit, but it was easily configurable to make it into an excellent fit. I prefer my chair not to recline, so I can’t comment on whether it is not a good chair for reclining, as Jeff Atwood says, but I will say it felt comfortable and stable reclining.

The real benefit so far has been on my posture; I did not know how much back pain I was having before with my really cheap office chair. Only when I got up from a 4 hour session on my Aeron chair did I notice how much better my back was feeling. It moulds your back into a good position, and I have noticed my back clicking and popping into its proper shape, after using the chair for a couple of days.

I ordered my chair from simplyaeron.co.uk, who I am very happy with, as they provided an MK2 Size C chair with lumbar support for less than £400, which is an absolute bargain compared to the retail price of a new chair. This also included delivery! It seems like new – there are no scuff marks and everything works perfectly.

I highly recommend getting an Aeron chair or an equivalent ergonomic chair recommended in the above resources, as I have really noticed a significant difference.

Tailing a log file and Running an Application at the Same Time


A quick tip this, but a useful one. You can tail a log file in the background while running a script in the foreground. So for example, I frequently execute the following commands:


tail -f /var/log/httpd.log &
/etc/init.d/apache restart

2. (The log file will spool onto the terminal as Apache is restarted.)

3. Once you are finished viewing the log file, foreground the log file process and kill it:


Then terminate the foregrounded log tail with a control-c.

With this technique you can run as many commands as you want, and see the real-time effects on your log file, without having to open a new terminal. You will also see your program output interspersed with your log file output, which can be helpful when tracing down particular problems.

Monitoring a Slow Internet Connection in OSX


I am currently on holiday in Tenerife, and although I really like it here, one thing I do not like is the internet connection we have in our resort. Sometimes networked applications will just hang with no warning and there will be minutes where it’s not clear what is going on. Here are some ways you can find a little bit more about what is happening when an application is slow or seems to hang when you have a poor internet connection. Execute the following commands each in a separate terminal window.

Log Files

tail -f /var/log/*

This will give you an indication of what is happening in OSX. For example, I was installing the XCode Command Line Utils from within XCode. The installation progress information is severely lacking, it just shows a bar which moves from left to right. However I was able to find out what was happening by tailing the log files in /var/log, which provided me with an updated breakdown of the installer progress. You can exit tail by using Control-C which will return you to the shell.

Constant Ping

ping www.google.com

When I have problems with my internet connection, I always keep a ping running in the background in a terminal. The interesting information here is the ICMP RTT time shown as the milliseconds next to the ‘time’ label, and how many packets were dropped shown by the number of ‘request timeout’ messages. Google does not mind you pinging it, just like hundreds of thousands of other people do, and so you can keep this up constantly, monitoring problems with your internet connection. When you get ‘no route to host’ printed, this usually means that your gateway or wireless connection is down, which means you usually have to reestablish a connection manually.


sudo tcpdump en0 -vvv

Do you really want to see what is happening on your computers network connection? Turn the floodgates on then, and use tcpdump. This will output information on each packet that your computer sends out and is received in a slightly Matrix-style torrent of information. If you are downloading something via an application or have a number of active web connections such as AJAX Facebook pages loaded, you would expect to see a lot of traffic. If you don’t have a lot of traffic, and you’re expecting a lot, then something may be wrong. You can use tcpdump to get a general feel of what data is being passed around, and to what IP address, which you can then look up later for more clarity. You can also use grep and some basic TCP/IP networking knowledge to find out what exactly is happening on the network level.

Network Connection Status of Each Application

sudo lsof -i tcp

Want to find out information about applications are using your internet connection, and the connection state of each TCP connection? Use lsof. You will be given the name of the application that is using each TCP connection, the IP address to which it is connected to, and the TCP connection state (established is good, time wait can be a problem sign). Run this regularly to check on the connection state of your programs. This won’t monitor UDP connections, but should cover your web browsers.

Hopefully this information will give you a bit more insight into what is actually happening on your OSX machine when your internet connection is being unreliable and you want more information about what is going on. Once you have this information, you can use it to inform actions such as toggling the wireless off and on again to reestablish a connection, reloading webpages that have hung, restarting application downloads, or possibly finding a new hotel or resort with a better internet connection 🙂

Reverting back to a previous version in CVS – the magic “undo” feature

If you’ve committed some code into to CVS, and made a mistake on that commit, you will want to know how to revert to a previously saved version. Here is the command line command for CLI versions of CVS:

$ cvs update -D '1 week ago'

Run this command in the main directory of your checked out working copy. This will revert your working copy to the version of the code that was checked in ‘1 week ago’ from the present date. You also use commands like “1 day ago” and “5 days ago”.

Then simply commit the changes with a log message:

$ cvs commit -m "Oops! Made a mistake, had to revert back to the 21/1/2011 version"

Netbeans for simple Java GUI Applications

I’ve been writing some simple Java GUI applications using the Netbeans IDE. It allows you to quickly make event-driven GUI applications, and generates a lot of skeleton code that you’ll need, but don’t necessarily want to type out. It reminds me of the IDE designer of Visual Basic 6, which allowed you to mock up simple GUIs with code in almost no time at all, although the VB language itself often proved difficult. With Netbeans you are using Java, and so you can make some powerful software with little effort.

Applications I Reccomend

Software I use on my macbook & PC:

DVDRipper Pro for Mac – DVD ripping, can also rip to ISO
Handbrake for Mac – Transcoding from DVD rip to iPhone-playable file
iMovie for Mac – Video editing
BabasChess for Windows – Best chess client for internet play
Hypercam 2 – Best screencapture utility
Skype for both – For reliable messaging as well as voice and video chat
Virtual Clone Drive for Windows – For mounting ISO images
iTunes for Mac – Best music player, and keeps media synced with iPhone
VLC Player for both – For watching movies
DVD Player for Mac – For watching DVDs

iPhone Apps:

Skype – Best messenger
iBooks – Best ebook reader
London Buses – Best London transport router, can route via tube, bus, cycle path and foot
Tube Status – Displays the status of all lines, with any disruptions summarised
NextBuses – Great app that gives you lots of info on the buses and bus stops in your area.
Apple Remote – Apple remote, allows you to control the music on any wi-fi linked iTunes library
Chess.com’s Chess – Great chess game for vs. computer play
TasteKid – Type in a film, author, tv series.. and it will give you similar recommendations
Google Earth – Brilliant for navigational help, although I use iPhone’s inbuilt Maps first, for most things.
SomaFM – Chilled out relaxing electronica

Tip for watching the completion of a large file copy

Forget the wonderful windows progress bar, and imagine I’m in the world of command-line Linux, and I want to copy a 484MB file, called VMware-server-2.0.2-203138.i386.tar.gz, from my home directory to a remote server. But I want to figure out how long it’s going to take.

1. First I can run a “du -m” command to get the total MB size of the original file:

du -m /home/david/VMware-server-2.0.2-203138.i386.tar.gz


david@believe:~$ du -m VMware-server-2.0.2-203138.i386.tar.gz
484 VMware-server-2.0.2-203138.i386.tar.gz

Now I know it is approximately 484MB.

2. Then I run the copy. I’m copying the file from /home/david/ to /opt/remote/myserver, which is a remotely mounted directory on a server somewhere in Canada.

david@believe:~$ cp ./VMware-server-2.0.2-203138.i386.tar.gz /opt/remote/myserver/

At this point cp will just hang until it’s finished. There is normally no progress indicator or anything. But I want to figure out how much of the file has been copied, so I can figure out how much is left to copy, and get a rough idea of the progress.

3. So I SSH into the remote server in Canada, and run this command

david@myserver:~$ watch du -m ./VMware-server-2.0.2-203138.i386.tar.gz

the copy command by default seems to be incremental, ie: piece by piece, not all at once. Therefore with the “Watch” command, you can watch the size, in MB, of the new file as it accumulates. The watch command will refresh every 2 seconds, so you’ll be updated as the copy goes on.

You can probably invoke a progress meter with the cp command, or use rsync. Rsync is much better for large file copies, and remote file copies. But the advantage of the method above is that you can watch file copies already executed without any special arguments, which I sometimes find very useful when I remember that that file I already started copying isn’t 200MB.. it’s actually 2.5GB.

Useful OSX commands for Linux users

I wrote this list to remind me, as a newcomer to OSX, how the command line differed from the Linux commandline. I thought I’d expand on it, and share it:

To mount any iso:

hdiutil mount sample.iso

To download a file as you would using wget:

curl http://ftp.heanet.ie/pub/linuxmint.com/stable/8/LinuxMint-8.iso -o linuxmint.iso -C -

the -o specifies the output file (required)
the -C – specifies automatically resuming if possible.

To burn a bootable iso to CD, DVD or USB key:

use the “diskutil” program as described in: http://forums.macrumors.com/showthread.php?t=598291

Monitor disk io utilisation.. poll once per second

iostat -c 99999

will run until 99999 seconds have passed.

Monitor CPU and memory utilisation.. polling per second


Just like Linux.

Mount Windows Shares

mount -t smbfs //@/ 


mount -t smbfs //davec@SERVER/Dev samba-to-netdev

then it will appear mounted in /Volumes with the mount point name you supplied, ie: /Volumes/samba-to-netdev/.

Long Bash History Files are Great.

When I’m installing software, or doing some complicated stuff on the linux command line, which nowadays is pretty much all the time, I will sometimes want to remember exactly what I typed.

Now the normal /home/david/.bash_history file is usually fine for that. Run this command, for example, and you will see the commands you typed in before you logged out of the server last time you used it:

cat ~/.bash_history

You can also find out what you typed in this session, ie: since you logged in, by typing this:


This is great, and it’s even more useful if you add a grep pipeline, so you can search through the previous commands you typed in for a particular phrase or command, ie:

history | grep apt-get

However what I really want nowadays is an almost infinite bash_history file, so I can find out not just what I did last week, but two weeks ago, or last month or perhaps last year. Now there are obvious security risks involved with this, and to make sure you don’t accidently store mistyped passwords to other systems, or other things, you should probably make sure you never type them in on the command line. This is good practice anyway, and since I use key’d sshd logins exclusively nowadays, there is not much chance of me tripping up, typing a password into the terminal, and then forgetting about it. In theory however, using long/infinite bash_history files does mean that if anyone compromised your shell account, they’d have any passwords to systems that you mistyped.

So I’m careful with this. You can also clear your history file quite quickly if you do accidently find you’ve messed up. Log out, log back in again, and just do this:

echo  > ~/.bash_history

Then that will delete all the previous logged commands.

Apart from serving as a major memory aid to complicated install work, and a log for those increasingly complicated chained, piped, one-liners that I’m fond of but only really want to have to type once, there are other benefits to keeping a large bash_history file. The main one is that it makes it easy to convert your previous commands into a handy shell script or two, which you can set to run at a specific time of day via cron.. or even make into a system-wide command for other users to use.

OK so hopefully I’ve convinced you that it can be very useful to have a long, persistent, bash_history file. But how do you configure the shell so that it does this for you? The following is the magic customization lines that I use on my personal desktops, laptops, and any other trusted computers that I think are reasonably free from the risk of people hacking in just to retrieve my .bash_history file..:

## bash history db
# increase the history file size to 20,000 lines
export HISTSIZE=20000
# append all commands to the history file, don't overwrite it at the start of every new session
shopt -s histappend

The above will give you an (almost) infinite bash_history file. It will start deleting old commands at 20,000 lines, ie: 20,000 commands. Make sure you have enough disk space for that. My .bash_history file is currently at around 200KB, not a huge file by any means. I’d say it will grow to 400-600KB max. If you want to calculate approximatly how much it will use, then in bytes, it’s the number of characters in your average linux command x 20,000.

MicroKORG + Python = MIDI fun!

microKORG and cat

So, about a month ago I got a second-hand microKORG from Ebay. Fiddling around with the preset patches, and creating new patches is great fun, even though I only know a few chords. Recently I plugged it in to my PC via my M-Audio Uno USB->MIDI interface, and soon was using Ableton Live to program drums in time with the microKORG’s arp.

I thought I’d experiment the music libraries available in python, and see if I could send notes to the synth via MIDI. Turns out that the M-Audio Uno is supported under Ubuntu, all you have to do is install the midisport-firmware package. With the help of pyrtmidi, a set of python wrappers around the C++ audio library rtmidi I was able to recieve MIDI signals in realtime from the microKORG, and send them in realtime also. With the help of this old midi file reader/writer library that I found posted to a python mailing list, I’ve made some progress in writing a simple MIDI file player that sends notes to the ‘KORG.

Eclipse 3.4.2 + Pydev + Eclim = win

So, after saying all that stuff about how vimplugin and EasyEclipse was great, I actually started to use the setup heavily, and it started to annoy me.

For one, EE is not a recent build of eclipse, nor does it come with a full set of recent plugins. This makes it annoyingly difficult to use when you want to use more than the set of plugins it packages for you. As far as vimplugin goes, it does not provide the vim integration I thought it might from embedded vim. Not really even close.

What I use now, after lots of trial and error, and at least 4 reinstalls of Eclipse, is a combination of Eclipse 3.4.2, Eclim, (which is the most mature of the free vi-binding plugins around, and actually includes an improved version of the vimplugin previously mentioned), and the latest pydev, Mylyn and Subeclipse.

I’m using it now to refactor a largeish python project, and I’m really appreciating the help it gives me. Definitely worth trying an Eclipse setup similar to this if you’re writing any python apps that are more than small-scale.

EasyEclipse + Vimplugin for Python Development

Up until now, I’ve always used the terminal for programming development on my projects. Because I’m so familiar with the advanced text editor vim, I can get a lot done on the command line, and it doesn’t detract away from what is actually going on behind the scenes, as a lot of IDEs seem to do.

However, in reading the book Foundations of Agile Python Development (which I recommend highly), and through working in software houses using IDEs only, I’ve come to realise that I need to gain at least some familiarity with an IDE.

So I’ve decided to try out Eclipse. I fiddled around with the Eclipse version in the Ubuntu 8.10 repositories for a while, with little success. I wanted to install pydev and vimplugin. Pydev is an eclipse python development environment. Vimplugin allows vim keybindings, and can actually embed the gvim editor within Eclipse. I tried for a few hours, but couldn’t get it all working with the stock Eclipse version in the Ubuntu repositories.

So I thought I’d try out EasyEclipse. EasyEclipse bundles a stable version of Eclipse with pydev in its “Easy Eclipse for Python Development” distribution, and that worked a charm. I then installed vimplugin which worked immediately when enabled, and supported embedded VIM mode within Eclipse. In the screenshot below, you should be able to (just about!) see what I mean, gvim is embedded into Eclipse:

Linux under Hyper-V

This is an overview of current Linux support under Hyper-V, the free Windows Server 2008 virtualisation product.

As you probably know, virtual servers allow the emulation of hardware in software. So you have a single physical ‘virtual server’. This virtual server emulates the physical hardware for several ‘virtual machines’ which sit on top of the virtual server. As far as the operating system on the virtual machine is concerned, it doesn’t notice anything different at all – it thinks it is running on a full set of dedicated hardware. However in reality, the virtual server is sharing its real physical resouces amongst the collection of virtual machines, assigning for example – 3GB of its memory to virtual machine A, and 1GB to virtual machine B.

Hyper-V requires a package called the ‘integration components’ to be installed on each virtual machine. This makes it easier for the virtual machine operating system kernel to talk with the virtual server, speeds up and increases the reliability of the emulation of virtual machine hardware by the virtual server.

Hyper-V supports the Xen virtualisation layer. Xen is a Linux-only virtualisation platform that requires a patched kernel on the virtual machine in order for the virtual server to communicate with the virtual machine.

The only officially supported distribution is SuSE Enterprise Linux 10, Service Packs 1 + 2. However because of the way the Hyper-V works, any Xen kernel in theory can be patched to run under Hyper-V.

In fact, this is exactly what you have to do in order to get any Linux distro fully working under the Hyper-V virtual server. So:

  1. Download the kernel source for the Xen kernel for your distro
  2. Patch it with the Hyper-V integration services patch
  3. Compile the kernel

.. and bingo – you should have Linux ‘fully supported’ by Hyper-V.

Now it remains to be seen whether there are any problems with running Linux under Hyper-V in a live environment. I know that we encountered multiple problems with Linux under VMWare ESX Server – and VMWare is the most mature virtualisation product available.

Those problems included: network interfaces dropping packets and the virtual machine system clock ‘drifting’ – running too fast or slow. These are NOT problems you want in a live enviroment, and so it remains to be seen whether Hyper-V can support Linux with the same ease as it supports Windows OSs.