Category Archives: Dev

New article on how to set CGI:IRC as Firefox’s IRC protocol handler

I really like to overdo things.  In the overdoing spirit of the Thanksgiving season, I overdid something recently.

When I clicked on an irc link to a chatroom, it didn’t open in my preferred IRC client, which is on my webserver.   I like to run my applications off of my webserver because I don’t have to worry about carrying thumbdrives or dealing with install policies on strange computers.  If I’ve got a browser, my own private cloud just works.

A little digging, a little coding, and I wrote up a handler.  Yes, that was a bit more work than I expected, but this way I can give thanks to you by giving you this gift of a very small effort.

If you’ve followed my advice before about getting your own webserver, this could be a 15 minute task for you.  Install CGI:IRC, install my little handler, baboomp.  Then we can chat on IRC

Say hi!

Why the Business Hates the Software Developers

Inspired by “Why I Hate Frameworks” “Why I Hate Frameworks”

So I wanted a custom spice rack, one that would really help my restaurant, but I didn’t want to build it myself.  I’m no carpenter.  I hired one though.
“Can you build me a spice rack? Here’s what I need – “
“Just a sec,” he interrupted. “I’m going to start building some hammers while you talk.”
“Don’t you already have some hammers?”
“Sure, but those were for past projects.  There’s better ways to build hammers these days.”
“Here – I have a hammer already.  It got left behind by the guy who hung the pictures in the restaurant.  Use this.”
“SIR! I don’t think that using a framing hammer is going to help us develop this spicerack.  Please!”

Professor Robb Willer and the Golden Apple

Robb WillerThe group of misfits I grew up with has turned out pretty well.
One of them, Robb Willer was my debate partner for a while. He’s gone on to be a professor at Berkeley. Robb won the Golden Apple award for being an awesome teacher. How awesome? Robb’s got intellectual groupies!

Berkeley put up Robb’s lectures under a Creative Commons license, so you can download them if you want and distribute them. Of course, Berkeley hasn’t given people any links to download the lectures. A bit lame if you ask me. Also, the way they’ve presented the lectures is terrible. Clicking anywhere on the page during playback makes the video close! That won’t do. I whipped up a quick fix.

  1. Install the excellent greasemonkey firefox addon.
  2. Install my Better Berkely script to fix  the webcast page.

Done.  Now the video is fixed.  When I get a free moment I’ll update the script to provide download links to all of the lectures, because what use is a creative commons license when you can’t get the media‽ Now the videos are available for download as well.

Congrats Robb!

How to get around a proxy system

This sounds complicated but it is really simple.  That it is so simple is why the internet is amazing and awesome.

from flickr user Bright Tal with a CC licenseProxies are used by people in positions of authority who want to control what you view on the internet.  Such groups include the governments of Turkey and China.  Also, the internet security team of most major corporations.  Some of these motives are good:

  • Blocking you from visiting websites that will infect your computer with spyware.
  • Blocking you from looking at naked people at work and totally creeping your coworkers out.
  • Blocking you from using webmail or instant messaging to communicate with customers in insecure ways or in ways that can’t be audited for a lawsuit.

Some of these motives are bad:

  • Blocking you from learning about problems at the group.
  • Blocking you from “wasting” company time or resources.

Generally you will eventually find a situation where you want to look at a website that has been blocked improperly.  I’ve often seen sites that discuss internet security vulnerabilities classified as “hacking” – but I need to know if those sites affect my work.

kindly sourced from flickr user Dazzie DWhether your intentions are pure or not, here is a simple way to give yourself internet freedom.

Download CGIproxy and install it on something that faces the unfiltered internet.  This might be your web host if you have one.  If not, you can install a web server on your home computer.  It is easier than you might think, and with DynDns, you can have your own domain name for your home computer.

You are done.  Now you can navigate in your browser to where you installed CGIproxy.  It will surf the sites you are blocked from.   Doing that is a hassle, though.  You have to go to CGIproxy when you want to go to a different site.  Lame.

Let’s make it easier through the magical power of bookmarklets.  We will put two little buttons in your browser that let you proxy blocked sites and unproxy them when you are somewhere safe again.

I wrote up a little page for you that generates proxy and unproxy bookmarklets for CGIProxy.  Go there, put in the URL of your CGIproxy, and choose your options.  I’ll automagically generate the bookmarklets for you.  You just drag them up to your browser quick links and now you have the keys to the kingdom.

Let me know if anything isn’t clear – I did the extra work so that it could be useful for you.

Using Ruby for command line web lookups

Common Problem

You frequently have to look up customer information on the company website.  Firing up a web browser takes time and invites you to start dawdling away on facebook and such.  If only anyone in the company had bothered to write a decent webservice or command line utility to look up customer information.

Find the right url

The first step is to dig into the company website and find out what happens when you click search.  You are looking for an element in there of type “form”.  A form is what gets submitted when you click search.  It will submit information to a page, and that page is the “action” attribute of the form element.  Then you need to find the inputs to that form.  Look for elements of type “input”.  These guys are the information you are sending to the action page.  Once you have the “action” and the “input” names, you can come up with a URL that represents this lookup.  It’s dead easy and it always follows the same pattern.

If you have a form like this:


<form action="/admin/clientsearch.asp" method="post">
<table border="0" align="center">
<tbody>
<tr>
<th class="QueryHeader">Search Options</th>
</tr>
<tr>
<td align="center">
<table border="0">
<tbody>
<tr>
<td><strong>Search For:</strong>

<input name="SEARCHPARAM" size="15" type="text" /></td>
</tr>
</tbody></table>
</td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td align="center"><input type="submit" value="Search" /><input type="reset" value="Reset" /></td>
</tr>
</tbody></table>
</form>

You can see the “action” is”/admin/clientsearch.asp” and that the input is named “SEARCHPARAM”.  From this we know that the URL is going to be “http://www.example.com/admin/clientsearch.asp?SEARCHPARAM=”.  That’s how simple it is.

Automate the lookup using Ruby

If this is a task you have to do often, try using Ruby to automate it.  Ruby has a utility for doing repetitive tasks called Rake or Sake and a utility for parsing web pages called Hpricot.  Install them like so:


gem install rake hpricot sake

Now we write up a file called “Rakefile.rb” and put in a rake task

desc "sets up the following tasks"
task :setup do
require 'open-uri'
require 'hpricot'
end

desc "lookup a client"
task :clients, :client_name do |t, args|
doc = Hpricot(open("http://www.example.com/admin/clientsearch.asp?SEARCHPARAM=#{args.client_name}", :http_basic_authentication => ['username', 'password']))
puts doc.search("//center[2]/table")[0].to_plain_text
end
task :clients => :setup #put in here bc named args seem to conflict with dependencies.

Most of what’s going on there is happening on line 9. We are opening a url, then passing it to our parser. If you don’t have a username and password for this website, you can remove the whole “http_basic_authentication” argument to open.

Where is my data

In line 10 you’ll see a little handy XPath going on to narrow down the document to what we care about. If you aren’t so hot with XPath, there is an easy way to find it out. In Firefox, install an extension called Firebug. Do a search on your webpage, then activate firebug by clicking the bug icon in your statusbar. Click inspect in Firebug and then click where your data is. Firebug will display a bunch of elements on the top. Move your mouse along them and you’ll find one element that highlights your data in blue. Right click on this and “Copy XPath”. That’s what you will put in “doc.search()”.

Using it

From the commandline type rake clients[myclient] and ruby will do the lookup and return the information you care about.  That will only work if you are in the same directory as your rakefile.rb.  We can install these tasks into sake by typing sake -i rakefile.rb. This makes these tasks system wide, so you can call sake clients[myclient].

A couple of caveats

  1. You may have to do a little tweaking to get open-uri to play nice with expired https certificates. Shouldn’t be a problem for most folks.
  2. The world of screen-scraping as it is called, doesn’t end there. If you need more advanced techniques for screen scraping a page, behold the power of the internet.

Making Context Free Art

If you are reading this post in your feed reader, you’ll want to click through to my actual website. Trust me on this one.

I was really impressed with Aza Raskin’s ContextFree.js experiment. I like how the simple rules of a context free art piece generate complex forms. See below, that text will turn into something I can’t exactly predict.
I’ve added a few comments to help you understand what’s going on there.

//all context free art starts with a single rule.  Ours will start with a rule named face.
startshape FACE
//and here is the rule FACE
rule FACE{
//a FACE rule means that we should draw the rules EYE MOUTH and HEAD.
 EYE{}
 // flip an eye over to the other side of the face.
 EYE{flip 90}
 MOUTH{}
 HEAD{}
}

//OH NO! We have two rules named HEAD.  Context free will randomly pick one
rule HEAD{ CIRCLE{}}
rule HEAD{  SQUARE{}}

rule EYE{CIRCLE { s .1 b .5 y .12 x .3}}
rule EYE {SQUARE { s .1 b .5 y .12 x .3}}
rule EYE {SQUARE { s .1 b .5 y .12 x .3 r 45}}
rule EYE {TRIANGLE { s .1 b .5 y .12 x .3}}
rule EYE {TRIANGLE { s .1 b .5 y .12 x .3 r 60}}

rule MOUTH {SQUARE{ s .8 .1 y -.12  b .5}}

And here is a randomly generated face, all made up of squares, circles, and triangles:

Want more faces? Go mess about with my face generator on Aza’s demo site.

update: in the comments Chris came up with a bunch of great mouths for an even better face generator!
The art is context free because any rule can be executed without knowing the context of the other rules – they are side-effect free. (these are the kind of problems that work well on lots of processors)
It gets much better. If you are using a modern browser, you’ll see that the heading of my website now is using this to generate random art up there in that previously wasted space.
Reload the website, you’ll see different art generated according to a handful of tiny algorithms. If you can see this, you might want to switch from Internet Explorer to Firefox or Safari. They both support the cool stuff that I’m doing, but you can’t see right now.

It’s all details

They say the devil is in the details. Sometimes subtle details are a place to shine.

I was reading notes on a lecture by the great Joshua Schachter, developer of Del.icio.us, when I was thunderstruck by a detail.

You have to speak the user’s language. “Bookmarks” are what you call them if
you use Netscape of Firefox – most users these days know the term “favourite”
instead. Half of his population (? users) didn’t know what a bookmark was.

It is true:
The small details matter

The beauty of Ruby’s array subtraction operator

Today I had to a set of email addresses, one per line, from which I had to remove the addresses of folks that said “Don’t email me.” Those emails were in a separate file, one address per line.

I figured I’d have to do this again, so I wrote a ruby script to automate it. Below, stripper.rb

#put each address in an array, remove whitespace and make it all lowercase
 potential_emails = IO.readlines("potentials.txt").map! {|email| email.strip.downcase}
 delete_emails = IO.readlines("donotemail.txt").map! {|email| email.strip.downcase}

#use the beauty of ruby's array subtraction operator
 puts potential_emails - delete_emails

Simple, terse and readable.  Lovely!