Skip to content

Instantly share code, notes, and snippets.

View bunnymatic's full-sized avatar
💭
writing computer programs

Mr Rogers bunnymatic

💭
writing computer programs
View GitHub Profile
@jcieslar
jcieslar / selectize_spec.rb
Created March 19, 2015 16:33
Capybara and selectize
page.execute_script("$('.selectize-input input').val('ber')")
sleep 0.5
page.execute_script("$('.selectize-input input').keyup()")
sleep 0.5
page.execute_script("$('.full-name').mousedown()")
# https://github.com/brianreavis/selectize.js/blob/master/src/selectize.js
@bunnymatic
bunnymatic / gist:1648765
Last active February 22, 2020 21:03
compute histogram in ruby
def tally inp; hash = Hash.new(0); inp.each {|k,v| hash[k] +=v}; hash; end
def histogram inp; hash = Hash.new(0); 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}
end
def test_histogram
histogram(['a','b','a','c','a', 'c']) == {'a'=>3, 'b'=>1, 'c'=>2}
@jonah-williams
jonah-williams / circle.yml
Last active May 29, 2019 14:53
Automating deployments to Heroku from CircleCI
test:
override:
- bundle exec rspec spec
deployment:
acceptance:
branch: master
commands:
- ./script/heroku_deploy.sh <ACCEPTANCE_HEROKU_APP>:
timeout: 300
@lucasmazza
lucasmazza / xhr.rb
Created November 24, 2010 16:43
Using xhr with rspec + rack/test
module XhrHelpers
def xhr(path, params = {})
verb = params.delete(:as) || :get
send(verb,path, params, "HTTP_X_REQUESTED_WITH" => "XMLHttpRequest")
end
alias_method :ajax, :xhr
end
RSpec.configuration.include XhrHelpers, :type => :controller
@pillowfactory
pillowfactory / partials.rb
Created June 9, 2010 03:49 — forked from lenary/partials.rb
Sinatra Partials
# stolen from http://github.com/cschneid/irclogger/blob/master/lib/partials.rb
# 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)