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: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: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: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: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 / 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"