This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'ruby-debug' | |
abort("Supply a twitter screen name like: ruby twitter_info_via_curl.rb tomcreighton") unless ARGV.size > 0 | |
# the -s argument makes curl silent (it will no longer show a progress meter) | |
# don't forget to append m to your regular expressions if you want the . to match newline characters | |
user_info = `curl -s http://api.twitter.com/1/users/show.xml?screen_name=#{ARGV[0]}`.match( | |
/<followers_count>(\d*)<\/followers_count>.*<statuses_count>(\d*)<\/statuses_count>/m) | |
puts "Followers: #{user_info[1]}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# When we create our Rackup file, we'll already be requiring RubyGems and Sinatra, | |
# so we don't require them again if they've already been loaded. | |
require 'rubygems' unless defined? ::RubyGems | |
require 'sinatra' unless defined? ::Sinatra | |
require 'rack' # more on the decision to include this below | |
require 'dm-core' | |
require 'haml' | |
require 'ruby-debug' | |
# If you want changes to your application to appear in development mode without having to |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inject({}) { |hash,(k,v)| hash[k.downcase] = v ; hash } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def past(interval) | |
interval.inject({}) { |interval,(k,v)| interval[k] = v.abs * -1; interval } | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# given hash like { :weeks => 1 } or { :months => -2 }, always return hash with a negative value | |
def past(interval) | |
k,v = interval.to_a[0] | |
interval[k] = v.abs * -1 | |
interval | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'ruby-debug' | |
def media_type_params(content_type) | |
debugger | |
return {} if content_type.nil? | |
content_type = content_type.split(/\s*[;,]\s*/)[1..-1] | |
content_type = content_type.collect { |s| s.split('=', 2) } | |
content_type = content_type.inject({}) { |hash,(k,v)| hash[k.downcase] = v ; hash } | |
content_type |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The media type parameters provided in CONTENT_TYPE as a Hash, or | |
# an empty Hash if no CONTENT_TYPE or media-type parameters were | |
# provided. e.g., when the CONTENT_TYPE is "text/plain;charset=utf-8", | |
# this method responds with the following Hash: | |
# { 'charset' => 'utf-8' } | |
def media_type_params | |
return {} if content_type.nil? | |
content_type.split(/\s*[;,]\s*/)[1..-1]. | |
collect { |s| s.split('=', 2) }. | |
inject({}) { |hash,(k,v)| hash[k.downcase] = v ; hash } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
require 'rubygems' | |
require 'open-uri' | |
require 'hpricot' | |
require 'ruby-debug' | |
require 'cgi' | |
f = open("http://forum.cakewalk.com/tm.aspx?m=1859288#1859354") | |
doc = Hpricot(f) |
NewerOlder