google-code-prettify - Google Code

JavaScript/CSS that can be used to easily provide syntax highlighting to code snippets within web pages.


ack -- a grep replacement that ignores .svn/CVS/blib directories, understands file types, uses Perl regexes, and much more

The title says it all.


Installing BlueCloth: Use Markdown in Ruby on the Mac

If you find yourself writing text that you’ll eventually post to the web, hopefully you’ve heard of text-to-HTML translators like Textile and Markdown. These tools take plain text formatted with a very light syntax of special characters that can generate formatting like bold text, bulleted lists, and so forth.

I am a big fan of Textile and use it frequently when I set out to write something new that I plan to post to the web (like this post). I’m coming around to see the value in Markdown, however, because it does a better job of taking existing text and translating it to HTML without any manual cleanup. It works especially well when copy-pasting text in e-mail that you want to post online.

Both of these are very useful when writing web applications, since they allow you to convert plain text input from the user into something formatted when displayed in the browser. I’ve used them both from within Ruby scripts, but unfortunately there seems to be an issue with the Ruby gem port of Markdown (BlueCloth). The standard gem install does not seem to do what’s necessary to allow you to use BlueCloth in your own apps or from the command line. (RedCloth doesn’t have this problem.)

So, here’s what I did to get around it…first, install the gem.
sudo gem install bluecloth

If you hit an error on that step, follow this tutorial for installing Ruby on your Mac. Then, run the BlueCloth installer.
sudo ruby /usr/local/lib/ruby/gems/1.8/gems/BlueCloth-1.0.0/install.rb

At this point you should be able to use BlueCloth from within your own Ruby scripts. But let’s take it a step further and enable the bluecloth command line app.
sudo chmod +x /usr/local/lib/ruby/gems/1.8/gems/BlueCloth-1.0.0/bin/bluecloth

At this point it’s runnable, but it still needs to be added to your PATH. Add the following line to your .bash_login file:
export PATH="/usr/local/lib/ruby/gems/1.8/gems/BlueCloth-1.0.0/bin:$PATH"

Woo hoo! You can now use BlueCloth in your Ruby apps and call bluecloth directly on the command line.

Note: According to the documentation, RedCloth is supposed to be capable of rendering Markdown-formatted text via additional options. I could not get this to work, and from what I have read not all of the Markdown syntax is supported anyway.

Displaying a search term in Textpattern

I’ve been doing some work with Textpattern lately, and it’s a really nice CMS for simple web sites. It’s kind of like Ruby on Rails in that 90% of the things you’d commonly do are built in, allowing you to focus on what makes your site unique.

One small thing it doesn’t have (out of the box) is a way to display the search term used on a search results page. We’re all used to the way Google displays the “Results 1 – 10 of about 2,000,000 for your search term here” near the top of the page. Even if the total number of results aren’t listed, it’s nice to know what you’ve searched for.

Fortunately, this is pretty easy to accomplish, since the built in search function puts the search term in the query string. Knowing that, the txp:page_url tag can be used to access the correct parameter:

<p>Search results for <strong><txp:page_url type="q" /></strong></p>

It’s just that simple. Happy searching!

Automated backup to Strongspace with rsync, Automator, and Highrise

Not long ago, I switched to TextDrive after being let down by a cheaper web host. So far, it’s been great…it’s a lot more feature rich and the people over there really know what they’re doing.

The basic $8/month plan includes access to 5GB of file storage for backup/sharing/whatever. I use it to back up regular ol’ documents and files on a daily basis.

They make this easy to do with a UNIX tool called rsync that compresses and transfers only the files that have changed. rsync is the real workhorse here, but I’ve rigged up a backup solution that utilizes all of the following tools:

  • rsync – does the actual file transfer

  • ssh keys – used to avoid entering manual passwords, which enables scripting

  • Automator – ties together the scripts into an application

  • iCal – enables scheduling of the application

  • Growl – provides notification onscreen that the script ran

  • Highrise – keeps a running history of the activity and provides RSS access

To cut to the case, download this file and check out the scripts. For more detail, read on.

This idea uses the UNIX philosophy of employing many small tools each perfectly suited for their job. (I love it.) Let’s take it step by step.

  1. rsync – It’s easy to familiarize yourself with this portion, since you can run it “interactively” on the command line. I do something very similar to what this gentleman did, though I supply slightly different options to rsync as per the recommendations of the Strongspace folks.

  2. ssh keys – If you play with rsync for a while, you’ll see that it asks for a password when you run it. Since we want to script this, we can’t have that, now can we? Fortunately it’s easy to generate ssh keys, which basically make your computer and your Strongspace account “trust each other” so that checking ID isn’t necessary.

  3. Automator – This part is pretty easy…I use Automator in OS X to string together the basic sequence of steps: backup the files, send the log to Highrise, and flash a Growl notification. Download this file to check it out.

  4. iCal – I chose to use iCal to schedule the Automator action (using this basic method) rather than a daemon like cron because it seemed like a more natural, Mac-like fit.

  5. Growl – I’ll be honest, this step is mostly for fun…Growl is just good times. However, I do use it as a quick validation that iCal lauched the script.

  6. Highrise – Growl is cool, but it didn’t provide much in the way of detail as to what happened with the script. I kinda wanted to see a log of what happened, except I didn’t feel like managing log files. I was really looking to get the log info via RSS, and for that I had to post it to the web somewhere. Highrise solves all these issues, and the default Dashboard view is great in the way it highlights the latest info. (After all, I really don’t care about yesterday’s backup after today.) My script e-mails the contents of the log file to my Highrise Dropbox, which was really easy to do with just a few lines of Ruby code.

So far, this has worked without a hitch, and I feel much better having my files backed up everyday.