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
# 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 |
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
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 |
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 '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"] |
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
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 |
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
a | |
a's | |
able | |
about | |
above | |
according | |
accordingly | |
across | |
actually | |
after |
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/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 |
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
== 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 |
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 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 |
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
class Market | |
def net_worth | |
investors.map(&:net_worth).sum | |
end | |
def capitalization | |
net_worth - investors.map(&:cash).sum | |
end | |
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
ActionMailer::Base.register_template_path 'haml' |