Skip to content

Instantly share code, notes, and snippets.

@jcromartie
jcromartie / arcc.clj
Created October 31, 2012 14:57
arc challenge in Clojure
(ns arc.core
(:use compojure.core)
(:require [compojure.route :as route]
[compojure.handler :as handler]
[ring.util.response :as response]
[ring.adapter.jetty :as jetty]))
(def route-map (ref {}))
(def ^:dynamic *params* nil)
@knaveofdiamonds
knaveofdiamonds / snakes.rb
Created October 31, 2012 14:56
Snakes and ladders Kata
def board(size, tunnels)
Hash.new {|_,i| i }.
merge(Hash[(1..6).map{|i| [size + i, size - i] }]).
merge(tunnels)
end
def move(board, players, player, roll)
players[player] = board[ players[player] + roll ]
[players, next_player(players.size, player, roll)]
end
@rrguntaka
rrguntaka / update_with_select.sql
Created December 7, 2011 20:59
Update with Select (Oracle). This query is to update a set of columns with the data from a subselect by matching id
UPDATE table_to_be_updated t1
SET (t1.col1, t1.col2) =
(SELECT (t2.col1, t2.col2) subquery_or_table t2
WHERE(t2.id1, t2.id2) in (t1.id1,t1.id2))
WHERE (t1.id1, t1.id2) IN
(select t2.id1, t2.id2 from subquery_or_table t2)
@mschuetz
mschuetz / spam.rb
Created October 25, 2011 21:29
simple bayesian spam classifier using laplace smoothing. quickly thrown together but i'll try to polish this tomorrow.
def sum(arr)
res = 0
arr.each{|e| res+=e}
res
end
def mult(arr)
res = 1
arr.each{|e| res*=e}
res
@lucasfais
lucasfais / gist:1207002
Created September 9, 2011 18:46
Sublime Text 2 - Useful Shortcuts

Sublime Text 2 – Useful Shortcuts (Mac OS X)

General

⌘T go to file
⌘⌃P go to project
⌘R go to methods
⌃G go to line
⌘KB toggle side bar
⌘⇧P command prompt
~/projects/jruby $ jruby -v bench/bench_tak.rb 5
jruby 1.7.0.dev (ruby-1.8.7-p330) (2011-07-25 3e0a9dd) (OpenJDK 64-Bit Server VM 1.7.0-internal) [darwin-x86_64-java]
user system total real
1.164000 0.000000 1.164000 ( 1.132000)
0.917000 0.000000 0.917000 ( 0.917000)
0.921000 0.000000 0.921000 ( 0.921000)
0.918000 0.000000 0.918000 ( 0.918000)
0.920000 0.000000 0.920000 ( 0.920000)
~/projects/jruby $ jruby -Xcompile.invokedynamic=false -v bench/bench_tak.rb 5