Skip to content

Instantly share code, notes, and snippets.

View msgodf's full-sized avatar

Mark Godfrey msgodf

View GitHub Profile
@msgodf
msgodf / localStorage.js
Created May 26, 2011 16:59
Rough and ready localStorage object for node.js
localStorage=(function(){function t(){this.store={};};t.prototype={constructor:t,setItem:function(k,v){this.store[k]=v;},getItem:function(k){return this.store[k];}};return new t;})()
@msgodf
msgodf / gist:986659
Created May 23, 2011 13:10
Attempt to add list comprehension sugar to lazy lists
range = (function(s,e){var i=s,r={};f=fuction(){r[i+1]=f;i++;return i;};r[i]=f;r.length=e-s;return r;};
some_range = range( 0 , 10 );
for ( i = 0 ; i <= some_range.length ; ++i ) {
console.log( some_range[ i ]() );
}
@msgodf
msgodf / generator_compact.js
Created May 23, 2011 11:47
Generator/lazy sequence class for JavaScript
function Generator(f,s,i){i=0;return{first:function(){return s[i=0];},next:function(){return s.length<=++i?s[i]=f(s):s[i];},nth:function(n){while(s.length<=n)this.next();return s[n];},take:function(n){this.nth(n);return s.slice(0,n);}};}
@msgodf
msgodf / fib_generator.coffee
Created May 22, 2011 17:01
Fibonacci sequence generator
class fib_generator
constructor: ->
last = 0
current = 1
@first = ->
last = 0
current = 1
@next = ->
temp = last
last = current
@msgodf
msgodf / look-and-say.clj
Created April 14, 2011 14:27
Solution to Conway's Look and Say sequence generation in Clojure
(defn seq-groups [seq]
(partition-by (fn [x] seq)))
(defn look-and-say [seq]
(interleave
(map count (seq-groups seq))
(map first (seq-groups seq))))
@msgodf
msgodf / look-and-say.rb
Created April 14, 2011 08:36
A reduce solution to Conway's "Look and Say" sequence
def lookandsay(seq)
seq.reduce{|s, v| s = [[1, s]] if s != s.to_a;if s.last.last == v then s[ s.length - 1 ] = [ s.last.first + 1 , v] else s.push [1, v] end; s}.flatten
end