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
# currying | |
add = ->(a, b) { | |
a + b | |
} | |
add_two = add.curry.(2) | |
# => #<Proc:0x00007f911d0962c0 (lambda)> | |
add_two.(1) | |
# => 3 |
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 'benchmark/ips' | |
# hash.size # 1000 | |
# hash.values.flatten.size # 500500 | |
def a_big_hash | |
{}.tap do |h| | |
1.upto(1000) { |i| h[i.to_s.to_sym] = 1.upto(i).to_a } | |
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
function ajax(url, callback) { | |
var xhr = new XMLHttpRequest(); | |
xhr.onreadystatechange = function() { | |
if (xhr.readyState === 4) { | |
callback(xhr.responseText); | |
} | |
} | |
xhr.open('GET', url, true); | |
xhr.send(); | |
} |
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
alert(window.location.pathname); |
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
# http://andora.us/blog/2011/03/03/choosing-foreground-using-luminosity-contrast-ratio/ | |
# color contrast ratio ranges from 1 (least) to 21 (most, white/black) | |
class Color | |
attr_reader :r, :g, :b | |
def initialize(hex) | |
raise 'Invalid hex code' unless hex =~ /[0-9a-f]{6}/i | |
hexes = hex.scan /.{2}/ | |
@r,@g,@b = hexes.map { |h| h.hex.to_i } | |
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
#!/bin/bash | |
# accepts as many version strings as you like | |
# returns them in order, one per line, highest first | |
function vseq() | |
{ | |
# collect arbitrary number of args | |
while [ -n "$1" ]; do | |
args="$args$1," | |
shift |
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
# subl . + all files that have been edited in this branch | |
# your $EDITOR may vary | |
alias diffedit="(echo '.' && git diff --name-only `git merge-base origin/master HEAD`) | xargs subl" |
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
# as a one-liner to use in an rspec example | |
@user.stub(:trebuchet).and_return(double(@user.trebuchet, :launch? => true)) | |
# more verbose example | |
it "should stub user.trebuchet" do | |
@user = Factory(:user) | |
@user.trebuchet.launch?("something ridiculous").should be_false | |
enthusiastic_trebuchet = double(@user.trebuchet, :launch? => true) | |
@user.stub(:trebuchet).and_return(enthusiastic_trebuchet) |
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
# code at http://gist.github.com/3350 | |
# tests at http://gist.github.com/3354 | |
require 'rubygems' | |
require 'active_resource' | |
require 'time' | |
class Hoptoad < ActiveResource::Base | |
self.site = "https://YOUR_ACCOUNT.hoptoadapp.com" | |
class << self |
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
FIXME: | |
WARNING: Nokogiri was built against LibXML version 2.7.3, but has dynamically loaded 2.7.8 | |
or | |
libxml_ruby.bundle: dlsym(0x10fde1900, Init_libxml_ruby): symbol not found | |
gem uninstall nokogiri libxml-ruby | |
brew update | |
brew uninstall libxml2 |
NewerOlder