One advantage of using rack is having access to rack middleware. rack-flash is a middleware which you can use for flash hash on your rack apps.

If you’re using sinatra, the syntax is similar to rails. Check out the rack-flash page here.

I added rack-flash to my sinatra app. Check out the git commit. Since rack-flash uses the session, don’t forget to add Rack::Session::Cookie.

Watch the video of Jon Crosby’s talk In a World of Middleware, Who Needs Monolithic Applications? at Mountain West Ruby Conference 2009 for more on rack middleware.

G-Edit and Shell to make editing multiple views easier

I recently was given a task to change alt tags in ALL of our companies images for better SEO purposes(I do think it won’t impact that much, but I guess they’re thinking any additional impact is better than nothing). I was given an excel file with about 300 images with their current alt tags and their proposed replacements. Yes, another copy and paste task.

What really blows is I don’t have a way of knowing where ALL the instances of the images are, so I had to use my now current favorite shell command to search where a said image is placed in a view:

grep -r -i imagename *

What that does is look which file and line in that file that the imagename string is mentioned. I usually just look for the name itself, and not the extension and the sub-folder, so to look for logo.jpg, I just put

grep -r -i logo *

That returns all the files where logo is mentioned(so I guess you’ll also get non-image results). What’s good about this is that it looks for both the instances when the image was rendered using <img src> or <%= image_tag %>

Seeing my first search resulted in 11 hits(I think the options -r -i of grep searches incrementally so it will also look in all sub-folders of the directory you are in), it occurred to me that this might take a while, as I also had to look for all the files, etc. I asked my friend to help in some shell-fu and here’s what we came up with:

gedit `grep -r -i -l imagename *`

What does this do? Simple, the -l option just lists the filename of the file where imagename was seen(as opposed to including the actual line where it was seen), and the grep enclosed in “ means that the output will be a string…which in turn is sent to gedit. The result? It opens up all the files that contains imagename and that my friends, made my life a wee bit easier in changing the alt tags in all the instances of a said image.

By the way, I know there is an easier way, like maybe replace all instances of said string in all files or something, but I haven’t found out about it yet. If I do, I’ll be sure to make a new post about it :P