Skip to content

Instantly share code, notes, and snippets.

View phillipoertel's full-sized avatar

Phillip Oertel phillipoertel

View GitHub Profile
@phillipoertel
phillipoertel / parse_css_colors.rb
Created March 6, 2011 19:06
Get the colors from a CSS file, sorted by how often they occurr.
require 'open-uri'
#uri = "http://www.zeldman.com/wp-content/themes/zeldman-v2/style.css?0111110710"
#uri = "http://asset2.betterplace.org/stylesheets/screen.css?1299172234"
uri = 'http://www.xing.com/css/v/144/general.min.css'
def parse_css_colors(uri)
file = open(uri).read
hex_colors = file.scan(/#[a-f0-9]{3,6}/i)
hash1 = %w(cat dog wombat).each_with_object({}) do |item, memo|
memo[item] = item.upcase
end
p hash1
# => {"cat"=>"CAT", "dog"=>"DOG", "wombat"=>"WOMBAT"}
hash2 = %w(cat dog wombat).inject({}) do |memo, item|
memo[item] = item.upcase
memo
@phillipoertel
phillipoertel / simplify_me.rb
Created September 3, 2011 21:07
Change the implementation of a classes instance method by including a module.
# original ApplicationController
class ApplicationController
def home_page?
"original"
end
end
puts ApplicationController.new.home_page?
# => original
@phillipoertel
phillipoertel / raphael.js
Created September 26, 2011 13:12
RaphaelJS animation
$(window).load(function() {
// config
var cyan = "#009fee";
var white = "#ffffff";
var paperCenterX = $(window).width() / 2;
// timings
var lineFadeInTime = 2000;
var whiteGFadeInTime = 2000;
### Gemfile
group :test do
gem "rspec"
gem "capybara"
# ...
end
### spec_helper.rb
@phillipoertel
phillipoertel / gist:2170042
Created March 23, 2012 12:02
passenger 3 "zero-downtime" restarts
# loop do
# start = Time.now
# `curl -s http://staging.torial.com`
# puts "Requested in #{Time.now - start}s"
# end
[...]
Requested in 0.148879s
Requested in 0.137547s
Requested in 0.165125s
describe "#visible_for_user?" do
let(:owner) { FactoryGirl.create(:user) }
let(:other_user) { FactoryGirl.create(:user) }
let(:private_content) { FactoryGirl.build(:private_content, :project => owner.default_project) }
let(:public_content) { FactoryGirl.build(:public_content, :project => owner.default_project) }
specify { private_content.should be_visible_for_user(owner) }
specify { private_content.should_not be_visible_for_user(other_user) }
specify { public_content.should be_visible_for_user(owner) }
specify { public_content.should be_visible_for_user(other_user) }
end
@phillipoertel
phillipoertel / gist:3312805
Created August 10, 2012 09:14
Here's what I needed to teach Sublime Text some TextMate keyboard shortcuts I use frequently -- Shift-Ctrl-T to show all methods in a file, and Cmd-L to go to a line in a file.
[
// goto line
{ "keys": ["super+l"], "command": "show_overlay", "args": {"overlay": "goto", "text": ":"} },
// goto method
{ "keys": ["super+shift+t"], "command": "show_overlay", "args": {"overlay": "goto", "text": "@"} }
]
@phillipoertel
phillipoertel / .irbrc
Created October 12, 2012 06:48
Config for a silent, non-distracting IRB.
IRB.conf[:PROMPT_MODE] = :SIMPLE
IRB.conf[:ECHO] = false