caps lock

To all my VI and Terminal users out there…Your not using your caps lock anyway, remap it to control and keep that pinky on the home row and save yourself some carpal tunnel, hehe:

Caps Lock

Vim cheat sheet

Since I have been using Vim almost exclusively lately I made myself a cheat sheet to help me remember some stuff.  This is certainly not an exhaustive list, just some things that I don’t know how to do off the top of my head that I wrote down and ended up getting a little carried away.  Just thought I would share:

Un-close apps with Mac task switcher

Everyone knows you can switch between apps with cmd-tab.  You can even do several things on an application such as cmd-q to quit, cmd-h to hide or cmd-w to close.  I find myself doing the latter on apps quite often because its easier to get to than cmd-h (at least for me).  However thats where I get myself into trouble.  If I used cmd-h instead, then when you cmd-tab to that app it will pop back to the foreground…not the case if you closed it with cmd-w.  So what is one to do?  It took me like 5 years to figure it out, but if you hold down option when you select an application that has been closed, it too will pop back to the foreground.  You’ll give yourself a cramp if you try to do all of this with your left hand, so use your right hand to hold down the option key.  So it goes like this.  Command tab to the app that is closed, hold down option with your right hand, let go of command with your left hand, the app will pop to the foreground.

VI rediscovered


I titled this article VI rediscovered, but it could have probably been more accurately titled, “I discovered the power of Vim”.  My first introduction to VI was when I was learning to use Linux back in the 90’s.  I needed an editor to modify all of the configuration files, and VI seemed like the editor of choice.  I made it through the initial learning curve, but never really considered it for more than editing a single file here and there.  I had no idea that when configured properly, it could have the power of an IDE.


Sometime in late 2004 or early 2005, my brother sent me a link to this new web technology called Ruby on Rails.  When I watched it, I am not sure which I found more amazing, Ruby on Rails or the TextMate editor.  Prior to that I was a big Windows guy and used Visual Slickedit which is an IDE of sorts.  I really liked that you could program multiple languages with it.  I could write scripts or code C++ all from the same environment.  But TextMate seemed like a whole new paradigm to me and I had to have it.  That is when I bought my first Mac, because TextMate only runs on the Mac platform.  I really liked the Bundles technology in TextMate and of course the tab completions.  Tab completions were not available in Slickedit which is sad because they really boost productivity.  The more I used TextMate the more I liked it, although I never really utilized all of its power.  But I came to rely on things like cmd-t, a method to located any file in your project with just a few keystrokes.  However as time marched on, updates to TextMate were marginal.  I was beginning to wonder if the project had died and sought out alternatives.


Around 2010 I ran into a discounted version of RubyMine and decided to give it a try.  Ruby seems to be the bulk of the code that I am writing these days and RubyMine provids an IDE like interface that I used to have in Slickedit.  With an IDE you can do things like autocomplete, refactoring, property and method lookups and debugging.  However it has one major problem…it is written and java and therefore it comes with all the problems inherent with java apps like poor memory management and poor performance.  I don’t mind autocomplete when its instant, but when it takes seconds, it starts to get in the way rather than help.

Sublime Text 2

A few months back I ran into Sublime Text 2.  It is sort of a happy medium between TextMate and RubyMine.  Its sort of like TextMate with autocomplete but not really a full fledged IDE.  I started using this a bit because its a native Mac application and therefore did not suffer from the performance problems of RubyMine.  But I had become accustomed to some of the features provided by RubyMine.  So while it tends to fill some the gaps from TextMate, it doesn’t quite fulfill enough of the features I’ve come to depend on RubyMine.


Over the weekend I was interested in learning more about a new technology called Backbone.js.  So I ran across this guy and he was rockin Vim!  He stutters a little bit, but he really knows his stuff when it comes to Javascript and Backbone.js.  However I was really intrigued by his use of Vim.  I had no idea you could do some of those things.  I buy a lot of books from Pragmatic Bookshelf and in an email I had received was a book on Vim that I had not payed much attention to.  So I went and bought it and spent all weekend reading it and playing with Vim.  Holy cow is all I can say.  Who knew?  Its like an IDE inside of an editor these days.  It has plugins that extend it to do just about anything you could imagine.  So I spent the weekend grabbing a couple of plugins and configuring my .vimrc.  I didn’t go crazy, but here is what I ended up with:

Pathogen: This one is like the ring in Lord of the Rings, it rules all of the other addons.  You really need to install it first, it makes installing all of the other addons a piece of cake.  Once installed you simply create a directory under ~/.vim called bundle, then to install another addon its as simple as: git clone addon.git in that directory.

CommandT: Its really a nonstarter for me these days if an editor doesn’t at least provide this capability.  CommandT is based on the TextMate cmd-t action that allows you to look up any file in your project by typing just a couple of keystrokes.

Neocomplcache: Who knew Vim now had autocomplete?  Apparently just me, hehe.  At any rate, neocomplcache enhances autocomplete to feel just like what I’ve become accustomed to in RubyMine…without the lag.  There is a sister addon that provides some snippets technology similar to what you would find in TextMate.  Apparently this used to be included in the Neocomplcache addon but the author broke it out into its own addon for some reason.

Tcomment: Tcomment allows you to comment code by line or block with a simple keystroke.  It doesn’t care if the code is a different language nested within another, it figures it out and does the right thing.  Another feature I picked up from TextMate that I really enjoy.  I’m not suggesting TextMate invented, I’m not sure who did, I just discovered it there.

Fugitive: Git wrapper from inside Vim.  It allows you to make commits, view the log, blame, and status, as well as move, add, and delete all from within Vim and handles the buffer that may point to non existant files after some of the operations properly.

Ack: Apparently there is a better grep than grep…a grep written for programmers.  Where have I been?  The website is even called  This addon interfaces ack and allows it to be used from within Vim to do project wide search.  Cmd-shift-f in TextMate.

Vim-rails: Being a rails developer this one intrigued me a bit but I don’t have much time with it.  The site claims that it will help with syntax highlighting, create partials from a block (like you can do in TextMate), jump between related files, and provide access to rake among other things without leaving Vim.

I’m running a Mac and I wanted to use the console version of Vim because I wanted to use it in conjunction with tmux which I also grokked this weekend, but thats another blog post.  However this creates 2 problems:

  1. The first addon I downloaded CommandT has some ruby requirement that has to be compiled into the executable.  The one that ships with Lion doesn’t seem to have this compiled in.
  2. You can’t seem to map the Command key in the console version for reasons that I do not understand.  You can map it in the vim GUI, but not the console version, I’m not able to recreate thing like cmd-t and cmd-shift-f just for example.  I would love for someone to prove me wrong and show me how to do this.

However I was able to overcome problem 1) by installing macvim.  I installed it through homebrew.  It installs a command called macvim that will launch the GUI version of Vim.  However macvim also provides a console version.  I believe the GUI is just a light wrapper around the console version but I could be wrong.  Its not obvious how to call up the console version that it uses but I found a little nugget of information in a google search that describes how to do it.  Simply create a sym link to the macvim utility with a name of either vi or vim and it will automagically call up the console version…nice!

Here is the .vimrc I ended up with, heavily influenced by this guy

I’m an official Scrum Master :)

As of today I have finally completed all of the requirements to become a scrum master.

From Wikipedia: Scrum is an iterative, incremental methodology for project management often seen in agile software development, a type of software engineering.

Although Scrum was intended for management of software development projects, it can be used to run software maintenance teams, or as a general project/program management approach.

Use to monitor any log file

I just discovered something pretty cool on my mac this morning and wanted to share. I use Symfony ( to develop web apps and it has a log file that you can use during development to help you debug certain aspects. I discovered that you can open the log file with the mac

open log/backend_dev.log

and it will automatically refresh. I normally open up a second terminal and run tail on it:

tail -f log/backend_dev.log

but this is pretty neat as well. Yuo can also use all of the console features such as clear display, insert marker, and filter. I imagine this works with any type of log file. I just happen to stumble upon it with the symfony log I was working on. At any rate, give it a try and see how you like it.

Mac: How to extract an icon

The need: When I first learned how to write Cocoa applications I was reading a book by Aaron Hillegass titled “Cocoa Programming for Mac OS X, Third Edition”. At the end he issues a challenge to choose a medium difficulty application and create it. I wrote an RSS reader. I followed that up by a license manager. I have dozens of shareware applications that I have purchased over the years and they each have their own license to keep track of. So I decided to create a management application to keep track of them all. This application was a little more complex than the RSS reader. I decided it would be a great way to learn CoreData. Somewhere along the way I hit a road block and shelved it. Well I’ve been working with CoreData quite a bit lately and decided to dust off this old app I started since I still have the problem of tracking all of my licenses. I got to a point where I needed an icon. Whenever you create a new Cocoa application it comes with a default icon and I thought it would be perfect to use on the list that contains the apps in my license manager. See the image at the top of the post to see what I was looking for.

The quest: I thought this would be relatively easy to find so I fired up a Spotlight search window: command option space and entered icns (the extension of a Mac icon file) then selected “File Name” instead of “Contents”. A lot of interesting icons came up but not the one I was looking for. So I followed that up with a search on but I just couldn’t seem to put the right words together to find the icon I was looking for. I even tried a regular google search: “mac application filetype:icns” but still nothing. So I decided rather than spend all day searching I should be able to extract the icon I want right out of the file. I am a Mac hacker after all…how hard can it be?

The project: It turns out, it’s not hard at all. I ran across this example Icon For File Type written in Cocoa that I thought was going to do it. It takes a file extension as input, then displays the icon for the application associated with it. So I downloaded it but I was unable to build it because the project file was to old. But it was so simple that I just rewrote the whole thing. So after I built it I ran it thinking I could just type in .app and get the icon I was after. But thinking about it now I realize that was never going to work because there is no application associated with a .app as the .app is the application. However with this little utility in hand it was not hard to extend it to extract the icon from a .app itself so that is what I did.

With this little utility you can either specify an extension like html, pdf, pages, numbers, etc… and display the icon of the application associated with that type, or you can locate the application itself and display its icon directly. Either way once you have the icon, you can save it to a location of your choice.

What I learned: This exercise was not in vain by any means. I was willing to settle for a 48x48 pixel image but what I ended up with was the actual .icns file. An icns file is nice because it has the ability to store 1 or more representations of a file. So for an icon you would most likely store a 16x16, 32x32, 128x128 and a 512x512. That way in various different settings you would always have an icon that looked nice. I guess one could extend this utility a little more to be able to save off 1 or more of the representations themselves instead of the entire file. However for my purposes it was easy enough to just bring up the .icns file in Mac’s built-in preview utility then drag the representation that you want onto the desktop.

Code: If you you want is the utility, you can grab that here:

Icon For File Type Utility

If you would like the Cocoa project for it, you grab that here:

Icon For File Type Utility Cocoa Project

How to recover data from a memory card for free

So a friend of mine took some pictures on her camera which contains an SD card but for some reason was unable to retrieve the pictures off of it.  I have a similar camera and a Mac she has Windows.  Many times I’ve been able to access data on removable drives on my Mac that were inaccessible on Windows but not this time.

So my first hurdle was how to mount this drive under the file system.  I put the card in my camera but it does a great job of masking that there is a removable drive inside of it.  Normally I don’t care.  I just plug it in and up comes iPhoto ready to pull the images off and remove them from my camera.  So when I plugged her card in, iPhoto dutifully came up…but no pictures.  So I found a free piece of software called PhotoRec that would supposedly extract the data from the memory card if I could only see it.  So with iPhoto up and running I ran the app, but there was no drive to be seen.  For some reason I decided to look around on my Mac to see if by any chance there might be a card reader of some sort and lo and behold right under the CD drive is an SD card reader.  Who knew?  So I plugged her card into the reader and finally it was properly mounted.

The website for PhotoRec says that as long as you can see the card and the proper size of the card is detected, then there is a very good chance that the data can be recovered.  Luckily this card was reporting the proper size.  Now PhotoRec is a free application and as such it doesn’t have a fancy user interface that just anybody can click around and figure out.  You have to run this utility from the command line.  

The drive that is 1000GB is my hard drive, the one that is 513MB is the memory card.  So I choose the first one /dev/disk2, not the /dev/rdisk2. And I’m given a screen with more options:

Disk /dev/disk2 - 513 MB / 489 MiB (RO)

Please select the partition table type, press Enter when done.
[Intel  ]  Intel/PC partition
[EFI GPT]  EFI GPT partition map (Mac i386, some x86_64…)
[Mac    ]  Apple partition map
[None   ]  Non partitioned media
[Sun    ]  Sun Solaris partition
[XBox   ]  XBox partition
[Return ]  Return to disk selection

Intel seems like a the most reasonable out of the choices so I select that one.  I’m then prompted with more choices:

Disk /dev/disk2 - 513 MB / 489 MiB (RO)

     Partition                  Start        End    Size in sectors
     No partition                   0    1002495    1002496 [Whole disk]
 1 P FAT16 >32M                   233    1002495    1002263 [NO NAME]

I’m pretty sure that memory sticks for most cameras are formatted as FAT so I choose that. I’m then prompted with more choices:

 1 P FAT16 >32M                   233    1002495    1002263 [NO NAME]

To recover lost files, PhotoRec need to know the filesystem type where the
file were stored:
[ ext2/ext3 ]  ext2/ext3/ext4 filesystem
[ Other     ]  FAT/NTFS/HFS+/ReiserFS/…

Again, I choose anything that says FAT, and again I prompted with more choices:

 1 P FAT16 >32M                   233    1002495    1002263 [NO NAME]

Please choose if all space need to be analysed:
[   Free    ]  Scan for files from FAT16 unallocated space only
[   Whole   ]  Extract files from whole partition

You know me, I’m going with FAT.  Now I’m asked where I would like to save the recovered files.  This is starting to look promising.

Do you want to save recovered files in /Users/socketwiz/bin ? [Y/N]
Do not choose to write the files to the same partition they were stored on.

I choose to store the files on my desktop and then select Y and it begins to attempt to restore the files…FINALLY.  A folder is created on my desktop called recup_dir.1 and PhotoRec appears to be recovering the files:

Disk /dev/disk2 - 513 MB / 489 MiB (RO)
     Partition                  Start        End    Size in sectors
 1 P FAT16 >32M                   233    1002495    1002263 [NO NAME]

Pass 1 - Reading sector     384119/1002263, 151 files found
Elapsed time 0h01m41s - Estimated time for achievement 0h02m42
jpg: 151 recovered

After around 10-15 minutes all 412 files are properly recovered.  Your mileage may vary but I would say if you can mount your card, and the operating system is reporting back the proper size of your card, then you have a pretty good chance of recovering you data from it.  This software also runs on Windows and I would expect you would receive the same choices I described above.  At any rate, if you or a friend end up with a corrupted memory card give these steps a try, I hope this helps.

New blog software already :)

So I decided I wanted to start blogging again and wrote my own blogging site.  Then yesterday I was reading my news feeds and stumbled upon tumblr.  I wasn’t really looking to replace my awesome software that I had written myself, but tumblr just has to many features to ignore for a decent blogging site.  So I’m going to give it a try, after all the price is right.  I don’t understand why people would go through all of this effort to make a wonderful product and then give it away for free.  Oh well.  Of the many features tumblr has is that it seems there a at least a thousand ways to get content to your blog including an iPhone app.  So I think I’m now totally out of excuses for not keeping up with my blog.  I’ve been doing OK so far, lets see how this goes…

Python via Cocoa

I have an idea for a Cocoa front-end around a Python script that I recently came across. As you may or may not be aware Cocoa has the concept of a scripting bridge for Python. However, almost all of the examples I could find were to allow Python to use Cocoa as a GUI interface basically. But I want to do is the other way around, use Python for it’s engine from Cocoa. Google being the amazing search engine that it is helped me to find an example that describes exactly that. Using that example I was able to break out the basic concept and build a very simple app that calls a Python script from Cocoa. The python script just calls ls and is then able to print the output back into my Cocoa app’s text view. So the bridge allows a two way communication from Cocoa to Python and back again. This is very cool stuff. Here is a screen shot of my little test app

Python bridge test app

Here is the Cocoa script that I executed in it’s entirety:

#  Rover
#  Created by Ricky Nelson on 7/16/10.
from Foundation import *
from AppKit import *

import subprocess

class PythonExecutor(NSObject):
	def main_(self, args):
		textView = args[0];
		path = args[1]
		p = subprocess.Popen('ls /', shell=True, stdout=subprocess.PIPE).stdout
		return YES

Now that I have a basic understanding of how it all works I can move on to building my little UI.