Categories: geek » ruby

RSS - Atom - Subscribe via email

More Rails twiddling

| rails

My “What’s in My Fridge” app is now a little bit smarter. It can keep track of what’s still in my fridge, what I’ve used, and what I’ve thrown away. I wonder if this will let me come up with statistics on how quickly I go through certain ingredients…

View or add comments


| rails, ruby

I play around with Ruby on Rails, and what do I do?

Build one webapp to keep track of what’s in my fridge, and another
webapp to keep track of what’s in my closet.

I’m going to do it in _pink_, too… ;)

View or add comments

The Year in Bookmarks

Posted: - Modified: | emacs, ruby
Top 10 tags for 2005 productivity(104) web2.0(88) digitalpinay(88) social(84) useful(83) business(80) blogs(70) research(69) lifehacks(68) blogging(60)

Check out my year in bookmarks for more detail. =) If you want me to analyze yours, just save to all.xml and run this Ruby script. You can also e-mail me ( your all.xml if you don’t want to go through the hassle yourself.

Much fun!


require 'rexml/document'
require 'date'

include REXML

YEAR = 2005
USER = "sachac"
doc = Document::new(File::new('all.xml'))

month_hash = {}
month_total = {}
tag_total = {}
doc.elements[1].elements.each {
  date = DateTime::parse(x.attributes['time'])
  if (date.year == YEAR)
    x.attributes['tag'].split(' ').each {
      month_hash[date.month] ||= {}
      month_hash[date.month][tag] ||= 0
      month_hash[date.month][tag] += 1
      tag_total[tag] ||= 0
      tag_total[tag] += 1
    month_total[date.month] ||= 0
    month_total[date.month] += 1

s = "Top 10 tags for " + YEAR.to_s + " |"
tag_total.sort_by { |tag,total| -total }.slice(0, 10).each { |tag,total|
  s += ' " + tag + "(" + total.to_s + ")"
puts s

month_hash.sort.each { |month,tags|
  s = Date::MONTHNAMES[month] + "
(" + month_total[month].to_s + " bookmarks) |" tags.sort_by { |tag,total| -total }.each { |tag,total| s += ' " + tag + "(" + total.to_s + ")" } puts s }
View or add comments

Ruby: Turn quotes into a fortune file

Posted: - Modified: | ruby

The following code turns XML quotes from (a popular IRC quotes server) into a fortune-cookie file.
Handy for using with ../emacs/flashcard.el and my ../emacs/flashcard-config.el, which pops up a fortune
every time I get a correct answer.


require 'rss/1.0'
require 'cgi'
require 'net/http'
host ='', 80)
if ARGV[0] then
   resp, data = host.get('' + ARGV[0], nil)
   resp, data = host.get('', nil)
parsed = RSS::Parser.parse(data, false)
parsed.items.each { |x| puts CGI::unescapeHTML(x.description.gsub('
', "\n")); puts "%\n" }

Call like this:

ruby bash-org-to-fortune.rb > bash; strfile bash; fortune bash

# or to get the top quotes with score < 1000
ruby bash-org-to-fortune.rb 1000 > bash; strfile bash; fortune bash
View or add comments

Adventures with Ruby

Posted: - Modified: | emacs, 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!

View or add comments

Nifty Japanese stuff: Kakasi

| emacs, japanese, linux, ruby

Kakasi is an external utility for
converting Japanese text between coding systems. It can also add
furigana after kanji or convert a text file to romaji.

Debian users can apt-get install kakasi kakasi-dic.
There’s an Emacs interface,
a Perl module (Text::Kakasi),
and a Ruby library.

View or add comments

More Ruby stuff

| ruby

Poignant guide, . Possibly the weirdest introduction to a programming language that I will ever see in my life . – Dave

Also, read Why the Lucky Stiff.

View or add comments