Skip to content

Instantly share code, notes, and snippets.

View kbaribeau's full-sized avatar

Kevin Baribeau kbaribeau

  • Test Double
  • Saskatoon, SK, Canada
View GitHub Profile
@kbaribeau
kbaribeau / gist:3452778
Created August 24, 2012 16:48
Ruby style poll
#Do you prefer this?
merchant["thing"] = important_stuff.map { |important_thing| important_thing["units"] }.inject(&:+)
#Or this?
important_stuff.each { |important_thing| merchant["thing"] += important_thing["units"] }
#Why? Is it completely objective? Or are ruby's idioms/social mores/conventions the deciding factor?
window.CountCalculator=window.PriceCalculator=window.TaxCalculator=window.ShippingCaclulator = {
calculate: (num) -> (num == undefined ? 0 : num + 1) }
ChainsCalls =
chain: (dependencies, method) ->
_(dependencies).inject((memo, dependency) ->
dependency[method](memo)
, undefined)
Invoice =
@kbaribeau
kbaribeau / gist:3123533
Created July 16, 2012 16:07
using custom ssl certs on osx
#see http://jjinux.blogspot.com/2012/02/ruby-working-around-ssl-errors-on-os-x.html
require 'open-uri'
require 'net/https'
module Net
class HTTP
alias_method :original_use_ssl=, :use_ssl=
def use_ssl=(flag)
@kbaribeau
kbaribeau / gist:2936794
Created June 15, 2012 14:41
ugly line of js
var o = this.options, scroll = this.cssPosition == 'absolute' && !(this.scrollParent[0] != document && $.ui.contains(this.scrollParent[0], this.offsetParent[0])) ? this.offsetParent : this.scrollParent, scrollIsRootNode = (/(html|body)/i).test(scroll[0].tagName);
ree-1.8.7-2011.03 :003 > hash = Hash.new([])
=> {}
ree-1.8.7-2011.03 :004 > hash[:asdf] << 1
=> [1]
ree-1.8.7-2011.03 :005 > hash[:fdsa]
=> [1]
ree-1.8.7-2011.03 :006 >
@kbaribeau
kbaribeau / gist:2294333
Created April 3, 2012 18:13
Annoyances / Fixes when switching from vim to sublime

CTRL+O/CTRL+I (forward / back)

  • partial fix: add this to your user keybindings (this only works between files, not within a file)
    [
         { "keys": ["ctrl+o"], "command": "next_view_in_stack" },
         { "keys": ["ctrl+i"], "command": "prev_view_in_stack" }
    ]
@kbaribeau
kbaribeau / gist:1677180
Created January 25, 2012 16:43
Git branch cleanup
git branch -r | grep kbaribeau | grep -v ${stuff_to_keep} | cut -d '/' -f 2-9 | sed -e 's/^/:/' | xargs git push origin
@kbaribeau
kbaribeau / gist:1297273
Created October 19, 2011 01:34
explicit requires, fast specs, and crazy dependencies
#foo.rb
class Foo < Bar
end
#bar.rb
class Bar < ActiveRecord::Base
#all sorts of crazy code that depends on a bunch of wacky stuff my tests don't care about
end
class Foo
Object = nil
def getBinding()
binding()
end
end
Foo::Object #returns nil
Object #returns Object
@kbaribeau
kbaribeau / gist:1158770
Created August 20, 2011 06:44
Download all DAS screencasts
#!/bin/bash
set -e
for file in `curl -s https://www.destroyallsoftware.com/screencasts/catalog |
grep screencasts |
tail -n +6 |
grep '(' |
cut -d '"' -f 2`; do
filename=$(echo $file | cut -d '/' -f 4)