Inspect all the assign variables

| |

Here's a way to look at all the instance variables your controller assigned:

In application.rb:

  def map_assigns
    @@protected_variables_cache ||= Set.new(protected_instance_variables)
    instance_variables.map do |var|
      next if @@protected_variables_cache.include?(var)
      var = instance_variable_get(var)
      ActiveSupport::Deprecation.silence do # var may now be deprecated
        yield(var)
      end
    end
  end

That may seem pointless, but now you can do something like this:

In your controller:

  @thing = Thing.find(params[:thing_id])

ssh tunnel around a firewall

| | |

Sometimes you need access to a service on the other side of a firewall. Try something like this:

ssh -C -L <local port>:<target host>:<target port> <user>@<ssh host>

So, for example to tunnel VNC from localhost to vnc.example.com, where ssh.example.com is a host that's inside the firewall with vnc.example.com and you have an ssh account on:

ssh -C -L 5900:vnc.example.com:5900 username@ssh.example.com
vncviewer localhost

URLEncode n-dimensional hash in Rails

| | |

Rails has support for passing n-dimensional hashes in POST and GET requests. However, it doesn't provide a function to encode said hashes into said supported string format, so I wrote one:

  # Takes a hash of arbitrary depth and turns it into a uri-encoded string that
  # Rails will be able to reconsitute correctly.
  def urlencode_hash(hash, parent=nil)
    hash.map do |k,v|
      unless v.kind_of?(Hash)
        unless parent
          URI.encode(k.to_s)
        else
          parent + URI.encode("[#{k.to_s}]")
        end +
        "=" + URI.encode(v.to_s)
      else
        unless parent

Find and replace in many files

| | |

Find and replace in many files:

mkdir old
for f in *
do
mv $f old/$f
sed 's/find/replace/g' old/$f > $f
done

or, to do it simpler and recursively

find ./ -type f -exec sed -i 's/find/replace/' {} \;

My Public Key

Here's my public key:

-----BEGIN CERTIFICATE-----
MIIC3DCCAkWgAwIBAgIQGJLqcVROzpvzE8wdroqPrTANBgkqhkiG9w0BAQUFADBi
MQswCQYDVQQGEwJaQTElMCMGA1UEChMcVGhhd3RlIENvbnN1bHRpbmcgKFB0eSkg
THRkLjEsMCoGA1UEAxMjVGhhd3RlIFBlcnNvbmFsIEZyZWVtYWlsIElzc3Vpbmcg
Q0EwHhcNMDYwOTI1MTU0NjMwWhcNMDcwOTI1MTU0NjMwWjBDMR8wHQYDVQQDExZU
aGF3dGUgRnJlZW1haWwgTWVtYmVyMSAwHgYJKoZIhvcNAQkBFhFoZWlzdGVyc0Aw
eDA5LmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAM1RCVSbWLLZ
40I/tCb9VSHNne/km4qhkufQ/yrl1NlZQ8yDrOYj1WwgSTM2QBxdWUYRb5AnnbmD
In0+z2b+H9LdsRjiqw+W8N/JiNXcntr7ZKTcIDFcY7GE+Pj0ISQ8AaOFZfJGKVCn
fLzi34zRSrQ3tpNjXI9lBbFAvwQBkRb5F5HC1HiuYYPdGRNiOJetKaaHJW1sqSo/

GMail encryption

|

The good way

The most straightforward way is just to install the GMail S/MIME Firefox extension, then install a cert from Thawte into Firefox.

To export a public key from the Thawte p12 file:

openssl pkcs12 -in file.p12 -out file.pem -clcerts -nokeys

see page 2 for the first way I tried to do it, plus other useful notes.

Use Sun's JRE with Eclipse on Ubuntu

| | |

By default Ubuntu uses GCJ, which will run Eclipse way too slowly. So you need to install the Sun JRE from multiverse, but still Eclipse won't find the new JRE. You need to use update-alternatives and edit the eclipse configuration to point in the right direction.

apt-get install sun-java5-jre
update-alternatives --config java
vi /etc/eclipse/java_home

add /usr/lib/jvm/java-1.5.0-sun to the top of the list.

Create a passwordless self-signed cert for apache2

| | | |

I don't always want to have to type in a password to restart apache, so here's how to create a passwordless self-signed cert:

su
cd /etc/apache2/ssl
openssl genrsa -out 0x09.com.key 1024
openssl req -new -key 0x09.com.key -out 0x09.com.crt
openssl x509 -req -in 0x09.com.csr -signkey 0x09.com.key -out 0x09.com.crt
chmod 600 *

The recommendation is to run genrsa with the -des3 flag, but this requires a password. However, now the key is not encrypted so you should chmod it 600.

Bonita Helmer Paintings

| |

Sometime around 2002 I designed a Website for Bonita Helmer, a Los Angeles based painter. All the design and implementation was done by me. It was my first full Web project and, looking back, it's a nightmare of invalid HTML, and noodley cut-n-paste code. However, it still has some nice ideas, and I almost wish I could go back and redo it.

The Bonita Helmer site

Resume

|

My current resume in Open Document format and PDF.