Entries Tagged as 'ruby'

Daring Fireball’s TitleCase Ruby Conversion

Update: Welcome fellow Daring Fireball readers. If you wish to get right to the actual code, feel free to skip to it.

I recently took up the challenge from John Gruber and Dan Benjamin to port John’s TitleCase.pl Perl script to an equivalent Ruby version. It seemed to me that converting someone’s script to another language would be a fun experiment to help learn any language. I was right.

I set up a git repository at GitHub.

I decided to write an extension to the String class in Ruby, as that would allow you to use this String#titlecase method anywhere and you could therefore write a standard input processing script trivially with this library included via a gem. Writing the extension also gave me a great excuse to learn more about RSpec, a nice Ruby testing library. I wrote the tests in RSpec, but I admit my tests were a quick hack to get them working at 3 in the morning, not good spec tests. Maybe someday I will convert them into real sentences of intent, as they should be. Either way, it was fun to try out Test Driven Development, and using the autotest function of the ZenTest gem to watch the tests start to pass as the script came along.

So after a few hours of learning about RSpec, ZenTest, all the tests from Gruber pass, even the one he lists as not working with his script. I took a different approach in how to process the titles, so there are not as many gotchas to fix up after processing either.

If you find it useful, let me know. And of course, fork the repo and send back some more test examples and any bugs you find.

P.S. Daniel also converted my Ruby version to PHP. We are going to use it at BitLeap for various things. He had also said about seeing about making a WordPress plugin out of it. So, I will prod Daniel to see if he will setup a public repository for it.

First Post and Hosting Fun

So here is my first post running the spectacular Typo blog Rails app. Typo seems pretty cool so far. I love the admin interface: simple, elegant, yet flexible.

So how am I running a Rails application on 1and1 hosting? I’m not. My free preview account from 1and1 (which was just fine for PHP) expires on the 31st of January, so I had to switch hosts. I also had a domain registered through them (samandjanali.com), so I had to move that as well. Who did I decide to move to?

DreamHost.

They have some very good pricing and seemingly unending amounts of storage and bandwidth for your hosting plan (they increase every week indefinitely). They said they hosted Rails and let you install new Gems too, so I signed up.!

Yeah, not smart. I should have done more questioning and research.

They are using Apache/FastCGI, which isn’t bad really, but there is something that makes me not like DreamHost right now. They have some kind of watchdog process that seemingly randomly kills my dispatch.fcgi processes! Not to mention that their protocol for restarting a Rails app is kill -9‘ing any ruby dispatch.fcgi process :)

Support has been very good with DreamHost so far, so we’ll see if they have any solution for the killing my processes thing (resulting in very bad Internal Server Error 500 errors once and awhile). Hopefully they can resolve the issues and everything will be fine and dandy. I am really not in the mood to change hosting again.