Skip to content

Instantly share code, notes, and snippets.

View fogus's full-sized avatar
💭
attempting to learn how to better learn

Fogus fogus

💭
attempting to learn how to better learn
View GitHub Profile
@fogus
fogus / gist:1017571
Created June 9, 2011 19:58 — forked from weavejester/gist:1001206
Clojure on Heroku
~/$ 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]
@fogus
fogus / mrisc.rb
Created July 7, 2011 12:31 — forked from joyofclojure/mrisc.rb
A Simple Assembler Language and VM
#!/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
@fogus
fogus / 0 - UNIX Fifth Edition
Created July 20, 2011 00:15
UNIX V5, OpenBSD, Plan 9, FreeBSD, and GNU coreutils implementations of echo.c
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
@fogus
fogus / about.md
Created August 11, 2011 00:28 — forked from jasonrudolph/about.md
Programming Achievements: How to Level Up as a Developer
@fogus
fogus / gist:1139485
Created August 11, 2011 12:06 — forked from swannodette/gist:1083967
typed.clj
(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]
@fogus
fogus / gist:1139486
Created August 11, 2011 12:06 — forked from swannodette/gist:1121891
seqpat2.clj
(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)
@fogus
fogus / seq_tree.clj
Created August 11, 2011 12:07 — forked from Chouser/seq_tree.clj
Very raw version of a function to turn a seq into a lazy tree
(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
@fogus
fogus / proxy-star.clj
Created August 11, 2011 12:08 — forked from Chouser/proxy-star.clj
Like clojure.core/proxy, but accepts a syntax like reify
(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))))))
@fogus
fogus / Functor.scala
Created August 11, 2011 18:51 — forked from gclaramunt/Functor.scala
Functor, Applicative Functor, Monad typeclasses in Haskell and their (simplistic) Scala translation
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]{