A Ruby script for MPD
1 2 #!/usr/bin/ruby 3 #file: mp_control.rb 4 5 require 'open-uri' 6 cmd = ARGV[0] 7 open("http://192.168.1.107/phpMp/playlist.php?hide=1&command=#{cmd}", 'User-Agent' => 'Ruby-MPClient').read 8
Example: mp_control.rb play
12733 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
1 2 #!/usr/bin/ruby 3 #file: mp_control.rb 4 5 require 'open-uri' 6 cmd = ARGV[0] 7 open("http://192.168.1.107/phpMp/playlist.php?hide=1&command=#{cmd}", 'User-Agent' => 'Ruby-MPClient').read 8
1 2 require 'open-uri' 3 puts open('http://digg.com/rss/index.xml', 4 'User-Agent' => 'Ruby-Wget').read
1 2 require 'open-uri' 3 require 'rexml/document' 4 5 open('http://www.flickr.com/services/rest/?method=flickr.photos.getRecent&api_key=YOUR_KEY_HERE') { |f| 6 doc = REXML::Document.new f.read 7 i = 0 8 doc.elements.each("rsp/photos/photo") { |element| 9 if i < 3 10 open("images/file" << i.to_s << ".jpg", "wb"). 11 write(open("http://static.flickr.com/" << \ 12 element.attributes["server"] << "/" << \ 13 element.attributes["id"] << "_" << \ 14 element.attributes["secret"] << "_o.jpg").read) 15 else 16 break 17 end 18 i = i + 1 19 } 20 } 21 22 puts "Done!"
1 2 require 'open-uri' 3 require 'pp' 4 5 open('http://www.juretta.com/') do |f| 6 # hash with meta information 7 pp f.meta 8 9 # 10 pp "Content-Type: " + f.content_type 11 pp "last modified" + f.last_modified.to_s 12 13 no = 1 14 # print the first three lines 15 f.each do |line| 16 print "#{no}: #{line}" 17 no += 1 18 break if no > 4 19 end 20 end 21
1 2 require 'open-uri' 3 require 'csv' 4 5 def get_adjusted_close stock_symbol 6 puts "-- #{stock_symbol} Adjusted Close - Historical --" 7 url = "http://ichart.finance.yahoo.com/table.csv?s=#{stock_symbol}&d=7&e=1&f=2006&g=d&a=2&b=26&c=1990&ignore=.csv" 8 puts "Connecting to #{url}\n" 9 10 csv = CSV.parse(open(url).read) 11 12 csv.each{|row| 13 puts "#{row[0]} - #{row.last}" 14 } 15 puts "---------------------------------" 16 end 17 18 example_stocks = "CSCO GOOG" 19 print "Enter a series of stock symbols separated by spaces (example: #{example_stocks}) to retrieve the historical adjusted close.\n" 20 stock_symbols = gets 21 stock_symbols ||= example_stocks 22 23 stock_symbols.split.each{|symbol| 24 get_adjusted_close(symbol) 25 }