Skip to content

Instantly share code, notes, and snippets.

writing computer programs

Mr Rogers bunnymatic

writing computer programs
View GitHub Profile
jonah-williams / circle.yml
Last active May 29, 2019
Automating deployments to Heroku from CircleCI
View circle.yml
- bundle exec rspec spec
branch: master
timeout: 300
bunnymatic / gist:1648765
Last active Feb 22, 2020
compute histogram in ruby
View gist:1648765
def tally inp; hash =; inp.each {|k,v| hash[k] +=v}; hash; end
def histogram inp; hash =; inp.each {|v| hash[v]+=1}; hash; end
def histogram2 inp; Hash[*inp.group_by{ |v| v }.flat_map{ |k, v| [k, v.size] }] end
def test_tally
tally([['a',1],['b',1],['a',1],['c',1],['a',3], ['c',1]]) == {'a'=>5, 'b'=>1, 'c'=>2}
def test_histogram
histogram(['a','b','a','c','a', 'c']) == {'a'=>3, 'b'=>1, 'c'=>2}
lucasmazza / xhr.rb
Created Nov 24, 2010
Using xhr with rspec + rack/test
View xhr.rb
module XhrHelpers
def xhr(path, params = {})
verb = params.delete(:as) || :get
send(verb,path, params, "HTTP_X_REQUESTED_WITH" => "XMLHttpRequest")
alias_method :ajax, :xhr
RSpec.configuration.include XhrHelpers, :type => :controller
pillowfactory / partials.rb
Created Jun 9, 2010 — forked from lenary/partials.rb
Sinatra Partials
View partials.rb
# stolen from
# and made a lot more robust by me
# this implementation uses erb by default. if you want to use any other template mechanism
# then replace `erb` on line 13 and line 17 with `haml` or whatever
module Sinatra::Partials
def partial(template, *args)
template_array = template.to_s.split('/')
template = template_array[0..-2].join('/') + "/_#{template_array[-1]}"
options = args.last.is_a?(Hash) ? args.pop : {}
options.merge!(:layout => false)