This gist is part of a blog post. Check it out at:
http://jasonrudolph.com/blog/2011/08/09/programming-achievements-how-to-level-up-as-a-developer
~/$ lein new ring-on-heroku | |
Created new project in: /home/jim/Development/ring-on-heroku | |
~/$ cd ring-on-heroku | |
~/ring-on-heroku$ echo 'web: lein run -m ring-on-heroku.core' > Procfile | |
~/ring-on-heroku$ cat > src/ring_on_heroku/core.clj | |
(ns ring-on-heroku.core | |
(:use ring.util.response | |
ring.adapter.jetty)) | |
(defn app [req] |
#!/usr/bin/env ruby | |
class MRISC | |
def run(code) | |
tokens = code.gsub(/(\*.*?\*)|[^a-z0-9,-;@\._]/,'').split(';') | |
@vars,stack,i = {:_pc=>-1,:_oc=>0},[],0 | |
tokens.map!{|t| t.chars.first=='@' ? (@vars[t.to_sym]=i-1;nil) : (i+=1;t.split(',').map{|e|numeric?(e) ? e.to_i : e.to_sym})}.compact! | |
while @vars[:_pc] < tokens.size-1 | |
@vars[:_pc] += 1 | |
@vars[:_oc] += 1 |
main(argc, argv) | |
int argc; | |
char *argv[]; | |
{ | |
int i; | |
argc--; | |
for(i=1; i<=argc; i++) | |
printf("%s%c", argv[i], i==argc? '\n': ' '); | |
} |
(ns fraud.detectors.bktree) | |
(defn root [distance-fn] {:distance-fn distance-fn :children {} :matches []}) | |
(defn new-node [term] {:term term :children {} :matches []}) | |
(defn empty-node? [node] | |
(= nil (:term node))) | |
(defn insert |
This gist is part of a blog post. Check it out at:
http://jasonrudolph.com/blog/2011/08/09/programming-achievements-how-to-level-up-as-a-developer
(defne geto [k m v] | |
([_ [[k :- v] . _] _]) | |
([_ [_ . ?r] _] (geto k ?r v))) | |
(defn typedo [c x t] | |
(conde | |
((geto x c t)) | |
((matche [c x t] | |
([_ [:apply ?a ?b] _] | |
(exist [s nc] |
(let [x 1 y 2 z 4] | |
(match [x y z] | |
[1 2 b] b | |
[a 2 4] a)) | |
;; => | |
(cond | |
(= x 1) (cond | |
(= y 2) (let [b z] b) |
(defn seq-tree | |
"Takes a sequential collection of events that logically represents | |
a tree by each event being one of: enter-sub-tree event, | |
exit-sub-tree event, or node event. Returns a lazy sequence whose | |
first element is a sequence of sub-trees and whose remaining | |
elements are events that are not siblings or descendants of the | |
initial event. The given exit? function must return true for any | |
exit-sub-tree event. parent must be a function of two arguments: | |
the first is an event, the second a sequence of nodes or subtrees | |
that are children of the event. parent must return nil or false if |
(let [arrays '{objects "Ljava.lang.Object;", | |
ints I, longs J, floats F, doubles D, chars C, | |
shorts S, bytes B, booleans Z}] | |
(defn qualify-tag [tag] | |
(when tag | |
(let [cls (if-let [array (arrays tag)] | |
(clojure.lang.RT/classForName (str "[" array)) | |
(resolve tag))] | |
(assert (class? cls)) | |
(symbol (pr-str cls)))))) |
trait Functor[T[_]]{ | |
def fmap[A,B](f:A=>B)(ta:T[A]):T[B] | |
} | |
trait Applicative[T[_]] extends Functor[T]{ | |
def pure[A](a:A):T[A] | |
def <*>[A,B](tf:T[A=>B])(ta:T[A]):T[B] | |
} | |
trait Monad[M[_]] extends Applicative[M]{ |