Skip to content

Instantly share code, notes, and snippets.

View danprince's full-sized avatar

Dan Prince danprince

View GitHub Profile
@danprince
danprince / r.clj
Last active December 22, 2015 02:59
Clojure RPN
(require '[clojure.string :as s])
(defn r[e]
(load-string
(reduce
(fn[x c]
(s/replace x #"([\+\-\*\/] (\(.*\) \d+|\d+ \d+))" "($0)"))
e
(subvec (s/split e #"\d") 1))))
@danprince
danprince / pn.js
Last active December 22, 2015 04:09
PN evaluator.
p=function($){for(s="substr",i=e=t=0,_=" ",$+=_;i<$.length;c=$[i],isNaN(c)&&c!=_?(e=0,t=i):0,i++,c==_?++e==3?(x=$[s](t,i).trim().split(_),x.unshift(x.pop()),x=eval(x.join(""))+_,$=$[s](0,t)+x+$[s](i),i=0):0:0){}
return $}
@danprince
danprince / morse.js
Created September 2, 2013 18:11
Morse Code
m=".-|-...|-.-.|-..|.|..-.|--.|....|..|.---|-.-|.-..|--|-.|---|.--.|--.-|.-.|...|-|..-|...-|.--|-..-|-.--|--..".split("|")
m[-33]=" "
t=function(s){
for(o="",i=0;i<s.length;o+=m[s.charCodeAt(++i)-65]){}
return o
}
@danprince
danprince / morse.rb
Created September 3, 2013 13:40
(170) Morse code golf (Ruby)
def t(s)
o=''
s.each_byte{|c|o+='.-|-...|-.-.|-..|.|..-.|--.|....|..|.---|-.-|.-..|--|-.|---|.--.|--.-|.-.|...|-|..-|...-|.--|-..-|-.--|--..'.split('|')[c-65]||' '}
o
end
@danprince
danprince / sum.coffee
Created October 8, 2013 18:19
Takes an array of integers, strings and arrays. Finds all integers at any depth and returns the sum.
sum = (i) ->
i.map((e) ->
(if typeof e is "object" then sum(e) else e)
).filter((e) ->
typeof e is "number"
).reduce (p, c) ->
p + c
@danprince
danprince / mash.coffee
Created October 10, 2013 11:29
61 - Coffeescript Mash
m=(a,b)->
o=[]
a.map (y,j) ->
alert [y,b[j]].join("")
@danprince
danprince / cake.js
Created October 29, 2013 14:32
Run it in your console.
/* * * * * * *
|| || || || || || ||
|| || || || || || ||
|| || || || || || ||
|| || || || || || ||
|| || || || || || ||*/
c= function(i) {a.push(i*1)};
a=[];c(14/2+"2"),c(97),c(10+1
+"2");c(112),c("1"+2+"1"), c(
32);c(36/6+""+48/8),c("1"+ (+
@danprince
danprince / split.hs
Last active December 28, 2015 13:38
71 - Split string by delimiter
-- uncompressed
split str del = foldr (\col ltr ->
if ltr /= del then
(ltr:head col):tail col
else
[]:col) [""] str
-- compressed
x s d = foldl (\c l -> if l/=d then (l:head c):tail c else []:c) [""] s
@danprince
danprince / split.io
Created November 19, 2013 04:28
75 - Io string split
x :=method(s,d,
doString("list(\""..
s asMutable replaceSeq(d,",") ..
"\")")
)
// compressed
x :=method(s,d,doString("list(\"".. s asMutable replaceSeq(d,",") .."\")"))
@danprince
danprince / list.ls
Created December 13, 2013 20:25
41 - Tiny list in livescript.
l=do->
x=[]
(a,s)->
|s=>x[a]=s
x[a]