Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
#!/usr/bin/env ruby require 'open-uri' require 'osx/cocoa' include OSX def read_char system "stty raw -echo" STDIN.getc ensure system "stty -raw echo" end puts "Fetching MP3s..." mp3s = [] # if working with local files: Dir["/tmp/mp3/*.mp3"].each_with_index do |mp3,i| open('http://www.freesound.org/packsViewSingle.php?id=532').read.scan(/http:\/\/[^"]+?\.mp3/).each_with_index do |mp3, i| break if i > 9 puts "Loading #{mp3}" mp3s << NSSound.alloc.initWithContentsOfURL_byReference(NSURL.alloc.initWithString(mp3), 1) # if working with local files: # mp3s << NSSound.alloc.initWithContentsOfFile_byReference(mp3, 0) end puts "Done. Now hit number 0-9 to play sounds. (ctrl-c or ESC to end)" while(1) c = read_char break if c == 27 || c == 3 c = c.chr.to_i if c && mp3s[c] # this is broken, doesn't release the memory, just gets bigger and bigger mp3s[c].copy.play end end
This paste will be private.
From the Design Piracy series on my blog: