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 / global-replace
Created February 8, 2011 22:50
the grep garbage is because sed likes to add newlines to the ends of files that don't already end in a newline
find . -type f -name \*.rb -exec grep -qi "foo" {} \; -print |xargs sed -i "" -e "s|foo|bar|g" -e "s|Foo|Bar|g"
@kbaribeau
kbaribeau / gist:851314
Created March 2, 2011 17:22
run a set of ruby specs based on a git grep search
git grep 'thing_to_search_for' | grep spec | grep -v vendor | grep rb: | awk '{print $1}' | sed -e 's/.$//' | uniq | xargs spec
@kbaribeau
kbaribeau / gist:853446
Created March 3, 2011 20:16
Run all failing cucumber scenarios from a hudson log
curl http://url-to-hudson-log | grep -A 5 'Failing Scenarios' | grep ^cucumber | awk '{print $2}' | sed -e 's/^.*\(\/features.*\)$/\1/' | sed -e 's/^.//' | xargs script/cucumber
@kbaribeau
kbaribeau / gist:938215
Created April 23, 2011 03:10
Tail recursive and non-tail recursive implementations of reverse and factorial in clojure
(defn recursive-reverse [coll]
(if (= 0 (count coll))
[]
(concat (recursive-reverse (drop 1 coll)) (take 1 coll))))
(defn recursive-reverse [coll]
(loop [coll coll
acc []]
(if (empty? coll)
acc
@kbaribeau
kbaribeau / gist:1103102
Created July 24, 2011 21:06
Ruby single quote escaping madness
Ok, so I'm trying to replace a ' character with \' in a ruby string. I have working code, but it was
*way* too painful getting there for my taste.
Take a look:
ree-1.8.7-2010.02 :001 > single_quote = "\'"
=> "'"
ree-1.8.7-2010.02 :003 > single_quote.gsub(/'/, "\\\'")
=> ""
ree-1.8.7-2010.02 :004 > single_quote.gsub(/'/) {|c| "\\'"}
@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)
class Foo
Object = nil
def getBinding()
binding()
end
end
Foo::Object #returns nil
Object #returns Object
@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
@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: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" }
    ]