Skip to content

Instantly share code, notes, and snippets.

@mikelikesbikes
mikelikesbikes / fib_spec.rb
Created June 13, 2012 12:56
Dynamic Rspec examples
describe "fibonacci" do
[
[0, 0],
[1, 1],
[2, 1],
[3, 2],
[4, 3],
[5, 5],
[6, 8]
].each do |index, value|
;; http://stackoverflow.com/questions/1590716/clojure-prime-numbers-lazy-sequence
(def primes
(let [primes (atom [])]
(for [n (iterate inc 2)
:when (not-any? #(zero? (rem n %))
(filter #(<= % (Math/sqrt n))
@primes))]
(do (swap! primes conj n)
n))))
@mikelikesbikes
mikelikesbikes / frequency_benchmarks.rb
Created April 18, 2012 05:08
comparing frequency built using different enumerable methods
require 'benchmark'
Enumerable.class_eval do
def frequency_group_by
group_by{|x| x}.map { |x, xs| [x, xs.length] }
end
def frequency_each
h = Hash.new(0)
@mikelikesbikes
mikelikesbikes / gist:2297685
Created April 4, 2012 04:21
Base62 encoding
(def alphabet "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
(defn encode [i, alphabet]
(reduce #(str (nth alphabet (last %2)) %) ""
(take-while
#(not= [0 0] %)
(rest
; this is the magic (creates a lazy sequence of tuples, consisting of quot and mod)
(iterate
(fn [[i _]]
@mikelikesbikes
mikelikesbikes / gist:1547415
Created January 1, 2012 14:05
Queso Blanco (El Vaquero, Columbus, OH style)
Prep Time: 5 minutes
Cook Time: 5 minutes
Total Time: 10 minutes
Yield: 30 fluid ounces
1 1/4 lb block White American Cheese (Land O'Lakes brand preferred), cut into 1-inch cubes
1/4 cup diced green chiles
# given this model (Rails 3.1)
class User < ActiveRecord::Base
scope :over_30, where("age > 30")
end
# is this possible?
User.first.over_30? # => true if User.first matches the over_30 criteria
@mikelikesbikes
mikelikesbikes / gist:1205431
Created September 9, 2011 03:33 — forked from ethangunderson/gist:1189125
~/Library/Application\ Support/Propane/unsupported/caveatPatchor.js
var MD5 = function (string) {
function RotateLeft(lValue, iShiftBits) {
return (lValue<<iShiftBits) | (lValue>>>(32-iShiftBits));
}
function AddUnsigned(lX,lY) {
var lX4,lY4,lX8,lY8,lResult;
lX8 = (lX & 0x80000000);
lY8 = (lY & 0x80000000);
@mikelikesbikes
mikelikesbikes / gist:1037094
Created June 21, 2011 02:11
About Code & Coffee
Code & Coffee is an informal get together to write some code Thursday morning. There
are no requirements other than the willingness to sit down, pair up, and learn
something new. We're going with mornings because the evenings are full enough as it
is. Why add to the chaos of user groups, soccer games, and lawn mowing?
If you're interested in joining in, just show up. No invited needed, you don't need
to RSVP, you just need a laptop. Coffee not provided, but it's just a few steps away.
Location will be updated in the posts below, feel free to drop a comment in if you're
going to join us. Hope to see you there.
@mikelikesbikes
mikelikesbikes / gist:1007228
Created June 3, 2011 21:43
Fibonacci with Inject!
def fib(n)
(0..n).inject([1,0]) { |(a,b), _| [b, a+b] }[0]
end
// current window.location = "http://example.com/page"
var action = "http://example.com/beep#/stuff"
var params = "foo=bar&baz=qux"
window.location = action + encodeURIComponent("?" + params);
// browser result
// => http://example.com/beep?foo=bar&baz=qux#/stuff
// desired result