Skip to content

Instantly share code, notes, and snippets.

View huned's full-sized avatar
💭
I may be slow to respond.

Huned Botee huned

💭
I may be slow to respond.
View GitHub Profile
# monkey patch HTTParty to use a configurable timeout
module HTTParty
class Request
private
def http
http = Net::HTTP.new(uri.host, uri.port, options[:http_proxyaddr], options[:http_proxyport])
http.use_ssl = (uri.port == 443)
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
http.open_timeout = http.read_timeout = options[:timeout].to_i if options[:timeout].to_i > 0
http
class Role < ActiveRecord::Base
ROOT = 'root'
ADMIN = 'admin'
USER = 'user'
def <=> other
roles = [Role::USER, Role::ADMIN, Role::ROOT]
roles.index(name) <=> roles.index(other.name)
end
end
@huned
huned / homework
Created June 19, 2009 19:01
homework in 8 minutes
require 'rubygems'
require 'hpricot'
require 'open-uri'
# First find the rss
url = ARGV[1] || "http://twitter.com/burnto"
doc = Hpricot(open(url))
rss_url = doc.search("link[@type=\"application/rss+xml\"]").first.attributes["href"]
@huned
huned / String#emphasize
Created June 25, 2009 00:03
String#emphasize puts <em>'s in strings
class String
def emphasize substrings
cleaned = [substrings].flatten.compact.uniq.map(&:strip).reject(&:empty?)
return self.clone if cleaned.empty?
returning to_s do |em|
cleaned.inject em do |s, sub|
s.gsub!(%r/(#{sub})/i, '<em>\1</em>') || s
end
end
end
@huned
huned / stopwords
Created June 29, 2009 16:19
571 english stopwords
a
a's
able
about
above
according
accordingly
across
actually
after
#!/usr/bin/env ruby
# calculate average uptime of my machine
require 'rubygems'
require 'activesupport'
times = `last | grep ^shutdown`
times = times.map { |l| Time.parse l[/shutdown\s+~\s+(.*)/, 1] }
times = times.map { |t| t > Time.now ? t - 1.year : t }
diffs = times.zip(times[1 .. -1]).map { |(a, b)| a - b if b }.compact
== VP MARKETING ==
Crowdcast is the leading provider of enterprise forecasting solutions
that aggregate team intelligence to deliver dynamic and accurate forecasts.
This is an exciting opportunity to join a venture funded Enterprise 2.0
startup revolutionizing corporate forecasting. Crowdcast has received
favorable press (NYT, Economist, VentureBeat, etc) and has signed many
Fortune 500 customers.
As VP Marketing for Crowdcast, you will be responsible for crafting and
def significant x, n = 3
# TODO test the fuck out of this
return '0' unless x.is_a? Numeric
('%f' % [("%.#{n}g" % x).to_f]).sub %r/\.?0*\z/, ''
end
class Market
def net_worth
investors.map(&:net_worth).sum
end
def capitalization
net_worth - investors.map(&:cash).sum
end
end
ActionMailer::Base.register_template_path 'haml'