The Eclectic Quill

Website of Joshua McGee

By

chime: Have your remote server make a bell sound in your local terminal

I needed notification, in my local terminal, when a remote process was finished executing.  I also thought it would be nice if I could wait for multiple notifications and tell them apart by the number of bell sounds I heard.  I came up with this.

On your remote server, copy the following to /usr/local/bin, rename it chime, and make it executable:

If your remote server runs Ubuntu, then this slightly longer script will install the needed dependency (tput) and install the script for you:

To have your local terminal chime once, run chime in your remote shell:

chime

To have your local terminal chime five times, run chime with an argument of 5:

chime 5

... and you should be good to go.

By

Badass programmers

I strongly recommend everyone (especially non-techies) read the discussion "Who are/were some of the most badass computer programmers?" at Quora.  It's too easy for non-programmers – even for programmers – to forget that all software, at its foundation, is written by human beings.  Everything is somebody's baby.  Just turns out that some mommies and daddies are WAY more badass than others.

My list of utter badasses would include the following:

badass-programmers

  1. Ada Lovelace
  2. Alan Turing
  3. Dennis Ritchie
  4. Donald Knuth
  5. Jeff Dean
  6. Linus Torvalds
  7. Richard Stallman
  8. Steve Wozniak
  9. Tim Berners-Lee

Check out the Wikipedia pages I linked to, and realize just how much they shaped the world we live in.

By

PostgreSQL 9.1 fails to start on Ubuntu 12.10

If you upgrade PostgreSQL and receive a message like the following:

CET FATAL:  could not create lock file "/var/run/postgresql/.s.PGSQL.5432.lock": Permission denied

... it is because the default directory for lock files in Ubuntu was changed to /var/run/postgresql, which is not world-writable.  However, simply changing write permissions on the directory does not work; they are reset when the default init script runs.

Instead, to fix this problem, edit your config file:

sudo [some editor] /etc/postgresql/9.1/main/postgresql.conf

... and look for the line that begins unix_socket_directory.  Change this to read:

unix_socket_directory='/tmp'

Then start PostgreSQL:

sudo service postgresql start

... and you should be good to go.

By

Getting the current year in Ruby on Rails

In Ruby on Rails, there are a number of ways to get the current year, but they are not all created equal.

The two methods recommended most frequently are Date.current.year and Time.new.year.  So I profiled these with the following code in Rails 3 that runs each routine a million times:

puts Benchmark.realtime { (10**6).times { Time.new.year } }
puts Benchmark.realtime { (10**6).times { Date.current.year } }

Time.new.year takes 5.479458 seconds to finish the million operations on my computer.  Date.current.year takes 12.323462 seconds -- more than twice as long.

I shared this with a colleague, who found the article Ruby Date Class Slows You Down? Rewrite It In C!, detailing the reasons and the author's suggested workarounds.

By

Create a favicon with ImageMagick

This script, which will run on UNIX, Linux, and Mac OS X systems, will take any input image file that ImageMagick can handle and convert it into a .ico file with resolutions of 256x256, 128x128, 64x64, 32x32, and 16x16 pixels.  The image will be resized, and if the starting image is not square, the image will be centered and padded with transparency.

Copy this and paste it into a file called favicon-maker:

#!/bin/bash
SEC=`date +"%s"`
`cp "$1" favicon"$SEC".png`
`convert favicon"$SEC".png -resize 256x256 -bordercolor transparent -border 128x128 -gravity center -crop 256x256+0+0 +repage favicon-256"$SEC".png`
`convert favicon-256"$SEC".png -resize 128x128 favicon-128"$SEC".png`
`convert favicon-256"$SEC".png -resize 64x64 favicon-64"$SEC".png`
`convert favicon-256"$SEC".png -resize 32x32 favicon-32"$SEC".png`
`convert favicon-256"$SEC".png -resize 16x16 favicon-16"$SEC".png`
`convert favicon-16"$SEC".png favicon-32"$SEC".png favicon-64"$SEC".png favicon-128"$SEC".png favicon-256"$SEC".png favicon.ico`
`rm favicon"$SEC".png favicon-16"$SEC".png favicon-32"$SEC".png favicon-64"$SEC".png favicon-128"$SEC".png favicon-256"$SEC".png`

You will need to make it executable, so type the following in the same directory:

chmod +x ./favicon-maker

To convert an image called my_cat.jpeg to a favicon, type the following and a favicon.ico file will be created in the current directory:

./favicon-maker my_cat.jpeg

If you want it accessible from everywhere, go to the directory where you saved the file and type the following:

sudo cp favicon-maker /usr/local/bin/favicon-maker

Then when you want to run it, you can type the command without the leading './':

favicon-maker my_cat.jpeg

If you don't want a favicon to appear in your visitors' browser, and you are tired of seeing 404s on favicon.ico in your logs, download this transparent .ico file, rename it to 'favicon.ico', and move it into your root directory.