This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| describe "fibonacci" do | |
| [ | |
| [0, 0], | |
| [1, 1], | |
| [2, 1], | |
| [3, 2], | |
| [4, 3], | |
| [5, 5], | |
| [6, 8] | |
| ].each do |index, value| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; 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)))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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 _]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def fib(n) | |
| (0..n).inject([1,0]) { |(a,b), _| [b, a+b] }[0] | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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 |