Skip to content

Instantly share code, notes, and snippets.


Adrian Duyzer adriand

  • Hamilton, Ontario
View GitHub Profile
View twitter_info_via_curl.rb
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{ARGV[0]}`.match(
puts "Followers: #{user_info[1]}"
View bottles_base.rb
# 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
View line_9.rb
inject({}) { |hash,(k,v)| hash[k.downcase] = v ; hash }
View shorter_past.rb
def past(interval)
interval.inject({}) { |interval,(k,v)| interval[k] = v.abs * -1; interval }
View past_interval.rb
# 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
View split_up.rb
require 'rubygems'
require 'ruby-debug'
def media_type_params(content_type)
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 }
View a_bit_of_rack.rb
# 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?
collect { |s| s.split('=', 2) }.
inject({}) { |hash,(k,v)| hash[k.downcase] = v ; hash }
View broken_hpricot.rb
require 'rubygems'
require 'open-uri'
require 'hpricot'
require 'ruby-debug'
require 'cgi'
f = open("")
doc = Hpricot(f)