Friday, October 31, 2008

Html Grep

Ever wanted to grep through the page contents and extract only interesting tags like all meta tags? Or maybe you wanted to print out contents of a tag with given id?

Now it's simple: html grep.

Usage is: htmlgrep.rb selector (file or url). It also accepts STDIN

Examples:


htmlgrep.rb input "http://www.google.com/"
cat index.html | htmlgrep.rb "div#users"
htmlgrep.rb "div#users" index.html

Tuesday, October 28, 2008

Pat Maddox on testing

The best post on test driven development

Sunday, October 26, 2008

Morphing basic types

An OS file path or URL are basically strings. They impose some validity constrains and change some of behaviour (like conncatenation or comparison) but in fact are only strings.

I was always bothered by the way languages treat such special strings. You can not in a simple way express them as strings. You have to pull out a whole library to deal with them:

File.open(File.join('..', 'spec_helper'))

What I would like to see instead is something more simple, easier to remember and more object oriented. I wonder if we can put in a language a way to simply and quickly morph literals from basic type to more specific type. Something among the lines of:

(#path{.}+'..'+'spec_helper').open

There should be a way of saying: hey, I want this particular string literal to be treated as instance of a special type. Behind the scenes platform may use a call to Path.new but I'm not too interested in that. I want a way of expressing my intent of work with paths rather than strings.

Implementation of this pattern is quite simple. On parser side we need to declare a special way of marking literals as 'morphable' and providing target type. When parser encounters such literal it emits a call to BasicType.new_with_target(target) instead of simple BasicType.new. In addition BasicType must provide BasicType.register_target(target, TargetType) so library creators can register own morph targets.

This allows to easily incorporate regular expressions (#r{} or #regex{}), URLs (#u{} or #{url}). Sigils may be used to designate literal type. TargetType of course has full control over the valid format accepted within the literal.

Thursday, October 23, 2008

Recruiter Woes

Oh, how I miss those days when it was hard to come by a person that knew Rails. Two years ago when you finally found one you could be sure he is an enthusiast and a professional.

Now, once RoR has been on the market for several years, more and more people are getting familiar with it. I personally like Java people coming to Rails as they are acustomed with design patterns and crave for high code quality.

Sadly, that's not usually the case with people with PHP background. Those often see Rails only as money making opportunity. Even when they switch to Ruby they are still writing PHP code (you can write FORTRAN in any language).

I have a good test that allows me to pick only valuable people: I ask them to show me their tests. If a new person has no tested code, I still give them a chance. They have to pick an open source, Rails-based project and fix a ticket there in TDD (or even better BDD) fashion. This way I was able to gather quite large group of skilled people.

I still am however annoyed by some. I try to be polite to anyone, no matter how low skills his may seem in the beginning, carefuly explaining my needs. But when, after exchanging three rounds of e-mail stating clearly, that we put high pressure on well tested code, a person asks me if 'there is another way to get to my organization except testing' I really want to scream:

LEARN TO FUCKING TEST

Wednesday, September 17, 2008

Omnipresent

Perl

Installation: Already installed

Use: perl program.pl or perl -e 'program text'

From infinite loop @ everything2