6098 comments
2357 subscribers
6263 on Twitter
Subscribe! Feed reader E-mail

Adventures with Ruby

This is my second day of Ruby, a programming language that is rather
popular in Japan. I’m in love. It’s now my second-favorite programming
language. (Emacs Lisp is, of course, the first.)

Yesterday’s script parsed schedule data and checked that monthly cost
and day constraints were observed. Today I wanted to visualize the verified schedule.

At first I tried working with planner (formerly known as
MrProject and not to be confused with PlannerMode). I wrote a Ruby program that converted my schedule.csv into XML, and planner loaded it successfully. However, I didn’t think planner would let me do funky color coding. I thought about using etask, but ended up deciding to write something using libgd-ruby.

It was surprisingly easy to write a Gantt-like visualizer for the schedule
and even easier to manipulate it once I had written it. For example, I could do silly things like

s.to_image((s.schedule.sort { |a,b| a.start <=> b.start }, 0, 2500, 1800, image)

Sorted by start date

to see the tasks sorted by start date. Being a Lisp girl, I had no problems writing silly things like

s.to_image((s.schedule.collect { |x| x if x.person_id == ’08-1′ } – [ nil ]).sort { |a,b| a.start <=> b.start }, 0, 2500, 1800, image)

but then I realized that this was much cleaner:

s.to_image((s.schedule.sort { |a,b| x = a.person_id <=> b.person_id; if x == 0 then a.start <=> b.start else x end }, 0, 2500, 1800, image)

Sorted by person and then start date

Ruby is so cute!

On Technorati:

Short URL: http://sachachua.com/blog/p/2616

On This Day...

  • 2013: Disabling touch on Windows 8 on a Lenovo X220 tablet — I often draw with my stylus in tablet mode. Palm detection doesn’t work particularly well, so I prefer to disable [...]
  • 2012: What to do when you have a hard time listening to lectures: adapting as a visual learner — J- is taking Red Cross lifeguard lessons. She told us that she sometimes has a hard time understanding and remembering [...]
  • 2011: A story of pi — A trivia question related to pi and my teammate’s subsequent recitation of pi to ten digits reminded me of this [...]
  • 2011: Lotusphere 2011 wrap-up — This was my first Lotusphere, and it was a blast. Lotus has such an active, passionate, experienced community around [...]
  • 2010: Monthly highlights: January 2010 — What a great start to the year! A vacation to Siargao gave me a chance to get to know my [...]
  • 2009: Conversations about networking; scale, structure, and skills — I had tea/hot chocolate with Ida Shessel at Linuxcaffe last Monday. She had come across me through a Google alert [...]
  • 2006: Banking arghs — I went all the way up to Yonge and Eglinton only to discover that I’d left the form I needed. SIGH. [...]
  • 2005: ri-mode bug when there is no current word — I replaced the stock implementation of ruby-default-ri-entry with the following code so that I could use it even if I didn’t [...]
  • 2005: Upgrade yourself! =) — Creating Passionate Users is a great blog just full of insights. The latest gem is about upgrading users. Right, that’s you. (If [...]
  • 2005: NEW YEAR’S CAT — 687 words Linlin couldn’t wait for the fireworks to start. While her parents watched the New Year’s special on TV, Linlin sat [...]
  • 2004: Debconf4 — Debconf4 will be held in Brazil from 2004.05.26 to 2004.06.02. I wish I could go. Hey, maybe I can! E-Mail from Pablo [...]
  • 2004: SIGGRAPH — Introductions - Father Rene Javellana, director of Fine Arts program in Ateneo - Richi Lerma - Glen from the office of international programs - [...]
  • 2004: New story: A Fairy Tale — I forced myself to write today (last night?), and here is the result: A Fairy Tale. Like many things, this story [...]

Get the highlights as a PDF!

Stories from my Twenties: Highlights from a Decade of Blogging

Free sample!