Skip to content

Instantly share code, notes, and snippets.

Adrian Duyzer adriand

Block or report user

Report or block adriand

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View broken_hpricot.rb
#!/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)
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?
content_type.split(/\s*[;,]\s*/)[1..-1].
collect { |s| s.split('=', 2) }.
inject({}) { |hash,(k,v)| hash[k.downcase] = v ; hash }
View split_up.rb
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
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
interval
end
View shorter_past.rb
def past(interval)
interval.inject({}) { |interval,(k,v)| interval[k] = v.abs * -1; interval }
end
View line_9.rb
inject({}) { |hash,(k,v)| hash[k.downcase] = v ; hash }
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 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 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]}"
View layout.haml
!!!
%html{ :lang => "en" }
%head
%meta{ :content => "text/html; charset=utf-8", "http-equiv" => "Content-Type" }/
%title
= "#{@page_title} &plusmn;" if @page_title
99 Bottles
%link{ :href => "/style.css", :title => "no title", :rel => "stylesheet", :media => "screen", :type => "text/css", :charset => "utf-8" }
%script{ :type => "text/javascript", :src => "/jquery.js" }
/ Drop in an erb file that just contains Javascript - that way, any Javascript we need is contained cleanly in a
View twitter.rb
# http://httparty.rubyforge.org/
# E.g.: Twitter.get('/1/users/show.json', :query => { :screen_name => "USERNAME" })
class Twitter
include HTTParty
base_uri 'api.twitter.com'
end
You can’t perform that action at this time.