Skip navigation

Tag Archives: Ruby

I’ve been working on a little experiment lately… a Ruby domain-specific language for generating Cascading Style Sheets called CascadingRubies.

It’s an internal DSL, meaning it uses plain Ruby syntax, like this:

CascadingRubies Syntax


CascadingRubies CSS Output

Being just Ruby, of course, you can mix in variables, arithmetic, require external code, hit the database, or whatever.

The guys on the Tulsa.rb mailing list have provided some great feedback, and from that I’ve released the the second gem version (0.2.0). If this looks interesting to you, head over to the GitHub project and check it out. Please let me know what you think.

sudo aptitude install libavahi-compat-libdnssd-dev
sudo gem install technomancy-dnssd -s
> require 'rubygems'
> require 'dnssd'

We’re gearing up for the upcoming, very first Tulsa Ruby Workshop.


Of course, all you need to know is on the website, but in short, it’s a beginner’s conference all about Ruby and Rails. If you’re new to Ruby and/or Rails, this is for you (if you’re in or near enough to Tulsa, Oklahoma that is). Tell everyone you know!

Just to save you a half-hour of your life, I thought I’d share that you should never create a named route called “directory” — it will break Rails migrations and other rake tasks in mysterious and hard-to-track-down ways.

I’ve been reading the book Advanced Rails by Brad Ediger. I first met Brad way back in 2006 when we were first trying to get our local Ruby user group going. He is a very smart fellow, and his newest book is definitely evidence of that. There’s a lot in there that’s over my head, but that’s nothing a few rereads can’t solve. :-)

The book has everything from optimization to deployment, from security to metaprogramming (my brain is still spinning from that one). Brad does an awesome job of including plenty of code and real-world examples.

If you use Ruby on Rails for fun or profit, this book is definitely a must-buy.

And, believe it or not, this something-other-than-perl-and-php book can be found in local bookstores (Brad V. found this one at the Tulsa 71st B&N):


From my post on Snippets:

First, create a plain Word document with text to replace like this:

Here is some text of my document. This will be replaced with [name]. Today’s date is: [date].

Then, run the following code. The text in square brackets will be replaced with the values in the code, and the file will be saved as a new name.

require 'win32ole'

word ='Word.Application')
#word.Visible = true # uncomment if you want to see it happen
doc = word.Documents.Open('c:\file_to_open.doc')
  'name' => 'Tim Morgan',
  'date' =>'%B %d, %Y')
}.each do |key, value|
  word.Selection.HomeKey(unit=6) # start at beginning
  find = word.Selection.Find
  find.Text = "[#{key}]" # text must be in square brackets
  while word.Selection.Find.Execute


Update: I’ve been using this for awhile now, and I still have to manually check my watchlist every day because my reader only gets updates every few days. I’m not sure, but it seems to be a caching issue on the WP API and not so much the script’s fault.

Update 2: The load on my server was too much, so I removed the hosted script from my server. You can still download the source and host it yourself.

Update 3: Turns out it’s better to just subscribe to each page’s feed rather than to use a script like this.

Back before Wikipedia had an API, I created a script that scraped the HTML and generated a plain RSS feed of my watchlist. Now, it’s even easier as the new API does most of the work for you, provided you correctly authenticate with it. So, version 2 of the script is much simpler, and simply acts to authenticate a user and grab the feed as-is and hand it to the browser/aggregator/etc.

The script source is here.

Basically, the URL would look like this:

Before you go trying it on my server, be aware that: (I have removed the script from my server. Sorry.)

  1. Your password and username are in the URL in plain-text (and thus in my server logs if you use this script directly from my server). This might scare you. I’m not an evil person, but then again, I wouldn’t believe someone else telling me that for a second. If you don’t trust me, then grab the script and stick it on your own server.
  2. I will leave my script running for you to use directly, but if the load becomes too much on my lowly server, I will disable it.

So, there’s two reasons to grab the script and run it on your own server.

Thanks to Jyotirmoy Bhattacharya for his Python script that does basically the same thing.

It occured to me that my gems of wisdom on my Snippets page likely go unnoticed by you faithful blog readers, so you might want to subscribe to my snippets feed as well so you don’t miss beauties like this (yes, I know this will seem lame to some, but I think it’s clever):

class Object
 def in?(object)
   object.include? self

>> 2..3
=> false
>> 1..3
=> true

My favorite programming language had a bit of a facelift. Now the homepage is as beautiful and elegant as the language itself.

Update: Version 2 is available here.

Today, I finally got fed up with Wikipedia‘s lack of watchlist feeds, so I wrote a script that generates them.

A few of the photos I had uploaded to the Wikimedia Commons have been marked for deletion for some time now due to inadequate license information (my fault entirely), but I didn’t know it because I didn’t think about the Commons having its own separate watchlist. Oops. That got me thinking… these watchlists should have feeds so I don’t have to keep pulling up my bookmarks every day.

Now, until they actually add feeds to those pages, I have my own solution in a few lines of Ruby code: This code can be run as a CGI on a web server and generates feeds like this.

So, I’m sharing this because the other two or three scripts out there written to do this suck IMO. (Or at least I couldn’t get them to work — which in that case means I suck :-)