Tab completion and syntax coloring in irb using Wirble

I generally code in python and am used to the default features of the ipython interactive python shell. One of the features that I use a lot is tab completion. It helps me locate method names and also just do exploration inside modules that are new to me.

Wirble is a gem for ruby that enhances the irb interactive ruby shell to have tab completion, syntax coloring, and a few other irb tweaks that I haven’t looked in to yet.

Its pretty easy to install wirble on most unix systems with ruby gem support installed:

gem install wirble

Then, add the following lines to your ~/.irbrc

require 'rubygems'
require 'wirble'
require 'irb/completion'
Wirble.init
Wirble.colorize

Next time you start up irb save typing using tab completion and relax your eyes using the syntax coloring.

SSH Tricks #2: SSH as a proxy

We talked about port forwarding recently. This helps you get access to single resources but it requires a lot of planning and configuration. It would be pretty awesome if SSH had a proxy feature.

Lucky for us all there is the -D option for the ssh command. This option turns the ssh connection in to a SOCKS proxy on the remote server. The potential uses for this are huge. I often use this feature to gain quick access to my whole network.

Setting it up

superbox$ ssh -D 31337 someserver

Using it

Firefox SOCKS Proxy is set to localhost port 31337

To use this you will need to configure your applications to connect through the SOCKS proxy. Firefox is pretty easy to configure. The settings for the proxy live in the Preferences under the Advanced section in the Network tab. Click the Settings… button to bring up a dialog similar to the one on the right. Set the SOCKS host to localhost and the port to the one you chose when connecting.

Now that the proxy is setup you can test out that you’re proxy is working by visiting http://whatismyipaddress.com/ to check to see if it looks like you are accessing the site from a new IP address.

In the next installment of SSH Tricks we’ll talk about using ssh config files to save time and energy.

Dealing with long tracks in iTunes

This is apparently really old news however it was news to me a few days ago.

iTunes 7+ has an option for tracks to “remember playback position”. This feature is pretty handy for those 30 minute long progressive rock tracks and also for things like MIT’s OpenCourseWare.

It can be set in the Info for any item in iTunes. Right click on any item in iTunes and click Get Info or ⌘+i on a Mac. Under the Options tab in the Info box that shows you’ll find the Remember playback position option.

Mimic Positive Lookbehind in Javascript

JavaScript’s regular expression engine, while useful, lacks a few less frequently-used constructs.

I recently needed to remove all single whitespace characters (\s) immediately following semicolons (;) in a given block of text.  A simple way to accomplish this uses the positive lookbehind construct – that is, to match certain characters (;), but not to consume them, only to assert whether a match occurred or not.

This would normally be written as:

text.replace(/(?<=;)\s/g, '');

Though JavaScript doesn’t support lookbehinds, we can use a lambda expression to mimic its zero-width assertion behaviour:

text.replace(/(\;|:)?\s/g, function(str, p1) {
	return p1 ? p1 : str;
});

I haven’t tested this workaround exhaustively, but it solved the problem that needed to be overcome.

Update

It seems I’m not the first to have tackled this.  Steve Levithan’s regex skills far exceed my own, and his blog entry on the subject offers a more comprehensive solution to the problem.

SSH Tricks #1: SSH Port Forwards

SSH is the ultimate tool for shifting bits around networks in a secure manner. This is the first of a series of articles on SSH tips. This article is all about the basics; as the tips progress, we will get trickier.

Overview

Port forwards are a way of mapping a TCP from one side of the ssh connection to the other. They are established using the -L and -R parameters to the ssh command. These stand for local and remote port forwards. A local forward takes a port on the local machine and connects it to an IP address and port from the remote machine. As you suspect, a remote forward takes a port on the remote machine and connects is to an IP address and port from machine you are connecting from.

Examples

You could forward port 80 from an  internal web server to port 8188 on the machine you are connecting from. This is a sort of poorman’s VPN. You can gain access to resources inside your network via SSH local port forwards. After connecting to your gateway machine you would be able to access the web server at http://localhost:8188.  To actually do this the command would look like this:

superbox$ ssh -L 8188:internalweb:80 homerouter

Another common use for this is securing VNC access. Many VNC servers offer the option to only accept connections from localhost. By combining this option with a ssh local forward  you can create an encrypted VNC session. This would be done by doing:

superbox$ ssh -L 5900:localhost:5900 vncserver

Remote port forwards are much less common. Lets say you have a local web server running on your workstation and you’d like your friend to take a look at an error on a hot new web app. you’re developing. The catch is you don’t want to let them login to your machine to do a local forward to gain access to your server. In this case you could use a remote port forward like this:

superbox$ ssh -R 8188:localhost:80 untrusted-friend

Your somewhat trustworthy friend could then access your web server at http://localhost:8188.

In the next installment of this series we will reveal a way to make your SSH connection behave even more like a VPN.

Manipulating Passcode Lock on jailbroken iPhone

If you have a jailbroken iPhone and find yourself unable to set the passcode lock, you can still activate this feature manually:

  • set your passcode on the iPhone under Settings / General / Passcode Lock
    (this stores the passcode, despite the feature not being activated)
  • open /private/var/mobile/Library/Preferences/com.apple.springboard.plist on your phone;
    the easiest way is to copy the file locally via SFTP, then edit it in the Property List Editor bundled with Xcode
  • add the following key under Root:
    • key = PasswordProtected
    • type = Number
    • value = 1
  • restart SpringBoard (relaunch the process, or just restart your phone)

You can also reverse this process if you find yourself unable to access said iPhone.

Fixing Visual Voicemail on the iPhone

A recent upgrade to my iPhone left the phone unable to access visual voicemail.  When I pushed the Voicemail button from the Phone screen, the phone simply did nothing.

Caveat: In addition to resetting your password, this will also delete your personal greeting.  It shouldn’t affect existing messages, though this assumption is untested.

The solution:

  • disable WiFi from the Settings menu
    (visual voicemail needs to reset over EDGE or UMTS/3G)
  • call AT&T at 611
  • press 1 to confirm your number
  • press 3 for voicemail help
  • press 3 to reset your password
  • hang up and wait for a confirmation text message

The Voicemail screen should work again.  Don’t forget to re-enable WiFi once you complete your voicemail setup.

Fixing dhclient in Debian Stable

Recently I installed Debian on a DEC Multia, I documented this install on my own blog. During my long upgrade process to a current Debian release from Woody. I encountered the following error:

midget# dhclient
Unrecognized Kernel Version

The way to fix this is to edit /sbin/dhclient and locate the line that contains “2.[12345].*)” and change it to “2.[123456].*)”