> /dev/null

Interesting hacks, snippets, and shortcuts.

Mar 1

Firefox Downloads not Working

I ran into some trouble recently where Firefox would simply not download files. If I told it to open them with a specific application, I would get absolutely no feedback until all of a sudden, the file would be downloaded and the application would launch. If I told it to save the file, nothing at all would happen and the file would never download.

After some snooping I found that downloads are stored in a sqlite database called downloads.sqlite in the root of your profile (Instructions for fi...

Dec 26

Rubygems failing with ruby 1.9.2

I spent a long time trying to figure this one out. If I tried to use rubygems at all with ruby 1.9.2 I got the following errors:

Turns out the solution is very simple. Check your RUBYLIB environment variable. Mine was for some reason set to /Library/Ruby/Site/1.8/ which cause gem to load the wrong rubygems library. The easiest way to get up and running is simply:

Jun 11

Remove Leading Whitespace from Bash Variable

If you have a variable with an unknown amount of leading whitespace, for example:

You can use this bash command to give you the value without any leading whitespaces

What is that?!

It's not nearly as complicated as it looks. The bash construct ${parameter##word} removes the longest matching prefix of the pattern word from the variable parameter. The pattern we use is *( ) which is bash speak for zero or more occurrences of space.

EDIT: If this doesn't seem to do anything at all, you might need to enable...

Apr 13

Scriptable tray notifications

I have written a little python script that allows you to put notifications in the taskbar using a simple command line program. Here is the project page.

You can create a command that gives you different feedback based on whether a program failed. For example a good use would be for ./configure scripts.

Now you can let ./configure run in the background and you will get an icon when it is done.

Enjoy.

Apr 12

Search for commands with wildcards

I often run into issues where I can't remember the exact name for a program. After spending half an hour looking for nm-applet, I decided it was time to be able to search by more than just prefix. Here is a snippet of code you can put in your .bashrc to allow you to search for programs more easily.

function find_command
{
    i=1;
    while [ $(echo $PATH | cut -d : -f "$i") ]; do
        PATHITEM=$(echo $PATH | cut -d : -f "$i")
        find $PATHITEM -name "$1"
        let i="$i+1"
    done
}
...
Mar 21

RSS feed troubles

Because of the way I include code snippets, my RSS feed doesn't publish them with the article. I am working on a method that allows me to continue to use gists for the code snippets without screwing up the RSS feed. Until then, the feed is really only good for getting headlines. Thanks for your patience :).

Mar 21

Working with multiple items on the $PATH

If you're like me then you have a $HOME/bin directory or something similar where you put custom versions of programs you use. But what if you need the original version for something? Memorizing the path works but is a real pain. Here is how to create a bash function that will run the old version of your command.

The which command

You probably know to use which to get the location of a program on the $PATH, but which can also take in the flag -a to list locations of all occurrenc...

Mar 18

Save as root in vim

Do you ever finish up editing a config file only to realize you forgot to open it with sudo and therefore can't save? This simple one liner from Peteris Krumins’ blog is a godsend.

:w ! tells vim to pass the entire file in the buffer to stdin of the next command. The command tee writes stdin to a file. The character % tells vim to pass the current file name so you end up using tee running as root to write the vim buffer back to the original file.

Page 2 of 2