-
Word of the Day
valituskuoro
Finnish word for people who complain simultaneously. Ok, from what I can gather, it is actually a combination of two words: valitus and kuoro.
Literal translation: complaints choir.
Posted on December 9, 2009
-
Customizing Autotest
If you’re like me at all, you love doing TDD, and you do it using the marvelous autotest, part of the ZenTest suite of tools. I recently encountered an issue where autotest was not detecting changes I made to files in my RAILS_ROOT/lib directory. I had set up tests for the lib files in test/lib. I found out that you can create a file in RAILS_ROOT/.autotest and enter custom regex mappings for your project to trigger automatic testing of files.
I wasn’t sure about the format of this file, though, and since I’ve figured out how to do it I thought I would share:
Autotest.add_hook :initialize do |at| at.add_mapping(/test\/lib\/.*\.rb/) do |_, m| at.files_matching %r%^test/(lib)/.*\.rb$% end endThe part that I didn’t know about was the “Autotest.add_hook :initialize” block. Running autotest with this .autotest file in my rails project now includes test/lib files.
Posted on December 1, 2009
-
If you say so…
Posted on November 17, 2009
-
http://www.flickr.com/photos/theremina/3365578708/
I love vintage surrealism. 19th Century owns.
Posted on November 17, 2009
-
Posted on November 15, 2009
-
Pale blind diver, luckless slinger,
lost discoverer, in you everything sank!
It is the hour of departure, the hard cold hour
which the night fastens to all the timetables.
The rustling belt of the sea girdles the shore.
Cold stars heave up, black birds migrate.
Deserted like the wharves at dawn.
Only the tremulous shadow twists in my hands.
- Pablo Neruda, from The Song of DespairPosted on November 15, 2009
-
So come, my friends, be not afraid.
We are so lightly here.
It is in love that we are made;
In love we disappear.
Though all the maps of blood and flesh
Are posted on the door,
There’s no one who has told us yet
What Boogie Street is for.“Boogie Street” by Leonard CohenPosted on November 12, 2009
-
.bashrc vs .bash_profile vs .profile
Despite years of various Unix flavor development, I can never remember the difference between the above mentioned files. So, I thought I’d finally document the outcome of my experiment here for posterity:
bash_profile: interactive login shells
bashrc: non-interactive login shells
profile: I’m guessing this is used when you do not have a bash_profile file. I found it hard to find a definitive answer, though.
$ cat .bashrc
export BASHRC=’loaded’
$ cat .bash_profile
export BASH_PROFILE=’loaded’
$ cat .profile
export PROFILE=’loaded’
$ echo $BASHRC$ echo $BASH_PROFILE
loaded
$ echo $PROFILERemoving my .bash_profile file gives the following results:
$ echo $BASHRC
$ echo $BASH_PROFILE
$ echo $PROFILE
loadedSo, it looks like the .profile is loaded when no .bash_profile exists, but that the .bash_profile supercedes .profile when it is found, preventing it from being loaded.
At least in Snow Leopard :)
Posted on November 6, 2009
-
Rails - Delegate Attributes with Override Ability
Ever find yourself in a situation where you wanted to delegate attributes from one model to an associated model unless they were specified in the original model?
I did, and I came up with a revamped version of Rails’ delegate method that not only checks if the original model has a value specified before delegating it to the associated model, but also checks that the associated model exists.
Grab the gist here: http://gist.github.com/70186
Example usage is included in it.
(originally posted on brighter.net)
Posted on October 12, 2009
-
FakeWeb with Regular Expression support for registering URIs
I have recently started using a gem called FakeWeb to fake http requests in my specs. It’s awesome - FakeWeb allowed me to ensure that I had stubbed out all external API requests (on a rather API-dependent application) with one line of code:
# prevent specs from trying to hit external api'srequire 'fakeweb'FakeWeb.allow_net_connect = false
However, I ran into an issue with it on another project that needed to block all requests except those going to a specific service. The issue was that each request had a different query string, and soon our spec helper was full of lines like this:
FakeWeb.register_uri("http://www.external.service.com/api/some/script?crazy=true¶m=foo&list=0&whatever=3", :string => "foo") FakeWeb.register_uri("http://www.external.service.com/api/some/script?crazy=true¶m=foo&list=0&whatever=4&additional=etc", :string => "foo") FakeWeb.register_uri("http://www.external.service.com/api/some/script?crazy=true¶m=foo&list=0&whatever=5&additional=bar", :string => "foo") FakeWeb.register_uri("http://www.external.service.com/api/some/script?crazy=true¶m=foo&list=0&whatever=6", :string => "foo")The query params differed depending on the request issued. Where we really got into trouble was with escaped URIs - these are harder for mere humans to read, and we missed differences in the longer ones quite a few times.
FakeWeb.register_uri("http://example.com/?a=%09%0D&b=%09%0D&ca=%09dog%4D&d=%26%0D&g=%09%0D&b=%09%0D&ca=%09dog%4D&d=%26%0D") FakeWeb.register_uri("http://example.com/?a=%09%0D&b=%09%0D&ca=%09dog%4D&d=%26%0D&g=%09%0D&b=%09%0E&ca=%09dog%4D&d=%26%0D") FakeWeb.register_uri("http://example.com/?bc=%09%0D&b=%09%0D&ca=%09dog%4D&d=%26%0D&g=%09%0D&b=%09%0D&ca=%09dog%4D&d=%26%0D")This prompted me to ask, “why not pass a regexp to FakeWeb’s register_uri method?” That way, we could pass something like /example.com\/?a=(.*)$/ for example and not have to worry about the query parameters changing… and thus have less clutter in our spec helper.
FakeWeb didn’t support this (it allowed you to pass URI and String objects) but it wasn’t too hard to add it. You can check out my fork here:
FakeWeb with Regular Expression support for registering URIs
I hope that other people find this useful. Oh yeah - please let me know on github if you find a bug in the code, and of course, feel free to fork it too!
(originally posted on brighter.net)
Posted on October 12, 2009

