Skip to content

Instantly share code, notes, and snippets.

Avatar

Mark Godfrey msgodf

View GitHub Profile
@msgodf
msgodf / gist:b108c0c79f5245fa3f30
Created Jul 8, 2015
Understanding how lists get destructured as maps in Clojure
View gist:b108c0c79f5245fa3f30
;; @andrew_jones mentioned this from Miller and Vandgrift's Applied Clojure book
;; unusual how the varargs were being destructured as if they were a map
((fn [& opts] (let [{:keys [a b c]} opts] (str a b c))) :a 1 :b 2 :c 3);;=>"123"
;; opts is a list, not a vector
(let [{:keys [a b c]} '(:a 1 :b 2 :c 3)] (str a b c));;=>"123"
(let [{:keys [a b c]} [:a 1 :b 2 :c 3]] (str a b c));;""
(let [{:keys [a b c]} [[:a 1] [:b 2] [:c 3]]] (str a b c));""
@msgodf
msgodf / profiles.clj
Created Jul 30, 2015
My .lein/profiles.clj
View profiles.clj
{:user
{:plugins [[lein-try "0.4.3"]
[lein-ring "0.9.6"]
[lein-ancient "0.6.7"]
[lein-kibit "0.1.2"]
[refactor-nrepl "1.2.0-SNAPSHOT"]
[cider/cider-nrepl "0.10.0-SNAPSHOT"]
[lein-cljfmt "0.2.1"]
[jonase/eastwood "0.2.1"]
[lein-typed "0.3.5"]]
@msgodf
msgodf / look-and-say.clj
Created Apr 14, 2011
Solution to Conway's Look and Say sequence generation in Clojure
View look-and-say.clj
(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 Apr 14, 2011
A reduce solution to Conway's "Look and Say" sequence
View look-and-say.rb
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
@msgodf
msgodf / fib_generator.coffee
Created May 22, 2011
Fibonacci sequence generator
View fib_generator.coffee
class fib_generator
constructor: ->
last = 0
current = 1
@first = ->
last = 0
current = 1
@next = ->
temp = last
last = current
@msgodf
msgodf / generator_compact.js
Created May 23, 2011
Generator/lazy sequence class for JavaScript
View generator_compact.js
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 / gist:986659
Created May 23, 2011
Attempt to add list comprehension sugar to lazy lists
View gist:986659
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 / localStorage.js
Created May 26, 2011
Rough and ready localStorage object for node.js
View localStorage.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 / ABCD.js
Created Jun 1, 2011
Code to run arbitrary JavaScript code as a string, using only the characters []$=()-+~""!_
View ABCD.js
[][$___=(($=(({}+"")))[$__=-~-~-~-~-~[]]+$[-~[]]+(""[+[]]+"")[-~[]]+(![]+"")[-~-~-~[]]+(($_=(!""+"")))[+[]]+$_[-~[]]+$_[-~-~[]]+$[$__]+$_[+[]]+$[-~[]]+$_[-~[]])][$___](($$=($_____=(!""+"")[-~[]]+(!""+"")[-~-~-~[]]+(!""+"")[+[]]+(!""+"")[-~-~[]]+(!""+"")[-~[]]+(""[+[]]+"")[-~[]]
)+"[][$___][$___]('"+$_____+"\"\\"+(""[+[]]+"")[+[]]
+(+[])+(+[]))+($$$=""+(-~-~-~-~[])+(-~[]))+($$$$="\"')()"))()+[][$___][$___]($$+($$$=-~$$$)+$$$$)()+[][$___][$___]($$+($$$=-~$$$)+$$$$)()+[][$___][$___]($$+($$$=-~$$$)+$$$$)()
@msgodf
msgodf / color_maven.sh
Created Jan 4, 2012
Colour Maven output
View color_maven.sh
# Modified from http://repo.or.cz/w/anomen-overlay.git/tree/HEAD:/dev-java/maven-color
color_maven() {
local BOLD=`tput bold`
local TEXT_RED=`tput setaf 1`
local TEXT_GREEN=`tput setaf 2`
local TEXT_YELLOW=`tput setaf 3`
local RESET_FORMATTING=`tput sgr0`
$MAVEN_HOME/bin/mvn $@ | sed -e "s/\(\[INFO\]\ \-\-\-\ .*\)/${TEXT_BLUE}\1${RESET_FORMATTING}/g" \
-e "s/\(\[INFO\]\ \[.*\)/${RESET_FORMATTING}\1${RESET_FORMATTING}/g" \
-e "s/\(\[INFO\]\ \)\(BUILD SUCCESS\)/\1${TEXT_GREEN}\2${RESET_FORMATTING}/g" \