The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
That Stupid Thing I Wrote The Other Day, part 1

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Ryan Davis

Posts: 651
Nickname: zenspider
Registered: Oct, 2004

Ryan Davis is a ruby nerd.
That Stupid Thing I Wrote The Other Day, part 1 Posted: Mar 13, 2007 5:08 PM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by Ryan Davis.
Original Post: That Stupid Thing I Wrote The Other Day, part 1
Feed Title: Polishing Ruby
Feed URL: http://blog.zenspider.com/index.rdf
Feed Description: Musings on Ruby and the Ruby Community...
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by Ryan Davis
Latest Posts From Polishing Ruby

Advertisement

Hopefully this will become a series that will let me clean out my Work/misc dir, but "That Stupid Thing I Wrote The Other Day" needs to be changed because TSTIWTOD is a lame acronym. Suggestions?

I use this to populate my iPod with all my music so I don't get confused in music stores:

music = Hash.new { |h,k| h[k] = [] }

Dir.chdir File.expand_path("~/Music/iTunes/iTunes Music") do
  Dir["*"].sort.each do |artist|
    artist_name = artist.sub(/^The (.*)/, '\1, The')
    Dir.chdir artist do
      Dir["*"].sort.each do |album|
        music[artist_name] << album
      end
    end
  end
end

dir = "/Volumes/NanoSpider/Notes/"
dir = test(?d, dir) ? dir : Dir.pwd
out = $stdout
last = nil

music.sort_by { |k,v| k.downcase }.each do |artist, albums|
  letter = artist[0..0].downcase
  if last != letter and dir then
    out.close
    out = File.open("#{dir}/music-#{letter}.txt", "w")
    last = letter
  end
  out.puts "#{artist}:"
  out.puts "  #{albums.sort.join("\n  ")}"
end

out.close if dir

Read: That Stupid Thing I Wrote The Other Day, part 1

Topic: Poor Communication and IT Projects Previous Topic   Next Topic Topic: Ten Ways to Exercise Your Brain

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use