Skip to content

Instantly share code, notes, and snippets.

View Quantisan's full-sized avatar

Paul Lam Quantisan

View GitHub Profile
@Quantisan
Quantisan / typed_project.clj
Created March 29, 2014 19:44
Mock lein usage of core.typed
(defproject something "0.0.1"
:dependencies [[org.clojure/core.typed.core "0.x"]] ;; with minimal trace
:profiles {:dev {:dependencies [[org.clojure/core.typed "0.x"]]}}) ;; with full
@Quantisan
Quantisan / scott.clj
Created May 8, 2014 21:53
clojure restful server library idea with Graph
;; https://scott.mn/2014/01/26/first_thoughts_on_liberator_clojure/
(defn blog-post-resource [request id]
{:authorized?
(fnk [logged-in-user request]
(or logged-in-user
(= (:method request) :get)))
:allowed?
(fnk [logged-in-user author request]
@Quantisan
Quantisan / method_value_or_pointer.go
Created June 11, 2014 15:43
Defining methods on values or pointers
package main
import (
"fmt"
)
type rectPointer struct {
width int
height int
}
@Quantisan
Quantisan / Dockerfile
Created October 20, 2014 21:16
Fig continuous dev setup
FROM clojure
ADD . /usr/src/app
WORKDIR /usr/src/app
RUN lein deps
@Quantisan
Quantisan / articles_struct.clj
Created January 28, 2015 16:19
sample data structure
(def articles
[{:title "3 Langs" :author "boris" :tags #{:java :clojure :haskell}}
{:title "mylangs" :author "rocky" :tags #{:ruby :clojure :haskell}}
{:title "2 Langs" :author "boris" :tags #{:java :haskell}}])
@Quantisan
Quantisan / readyforzero.clj
Created June 16, 2011 16:08
my solutions to ReadyForZero challenge
(ns readyforzero)
(def txt1 "en3pG3+nz+A2acXKrsyDouhViP9EDQS4JQK6uJqM3rBjKEBKC3yc=AA1=LUQqRPHvQ4dopgkbb/axClP3smzVcaTkRsCqHSG5aKFQ2TbOae0t5r4nWrCVesGK1Z3yEq+dClrDwXXOiAMyW09WdCS+CaKcfu=6kv9dUFBcS4KsUIgwMiXimoBpJZSWlBzILVf4zVA=7GjRP8RXn6uKjbjAPkpFEs/mYJpeOpEnhQfPhjoscgjfL5/SQsU6+jaAf5pg9MQzZdQAEJt7Jm1541fEmnumpjmJMd/MTJ5vzBttBBA7b5rbjDX0nHdTWn8C5suYKfNyYzc6x8S6FIepoEBsMS2mKhx5BRH5jSBrYRem4iQgYARzGnCFot3jPhp3cHj7qjXBWfZZASz8YJqi2d+r393AmdGm1L9NfU2f=FJprbLwJpuE7uT7xAlQA3Ry8aHRNgNkffP29Iqb2DSoQ0PK+9LX0t37HIAhI5zvoP6b4J7yQZEQDgeNlnPQMvSjw9pLWAxQ1VUY+NMU5BLZ2Bxuma1cIsHxcx4PwHcg0u1HYPJAWM2WK=xhJP5aQSc6oNMQK4s2=6guQRVFll6rvWkXTebrdsws7m/Kpa29spUFl8XzFx0ondEMCF3byAyWj875wAI3Hn8ZY92ddTAKj0s+a4X7qSti2lA0GzePHjBjMCD5g9kZYLtB94kkbVZ6eCle/xtto4LHH8GElc5YoUi=mk3nmQ5iOL1zMWfDyRUMLq+HCXbQL9NTejNa/yTdL3sayJOlMW1T7/Jmaz1FMbfBRFzruHeMT41=Zu3nYZJ3nIP22qKrFzNkt/24RuQ+7IMVCI2ngh2Yr8qLiL7QjSThRJPxA1wIJXwR2wqGiMhOqpun4DyQ5b/fTw1eTavpbFg6+tvqS4GKOt6p=bPoTV0GHIBBlXgHF/GUss90N0mXMKKiGwHhn/kyz=FxN0j=mfQUuUQa7lrZLjr10sqflWTwskIUkp1Cd8GYU
@Quantisan
Quantisan / tree-comp-each.clj
Created August 6, 2011 18:08
Calculating euclidean distance using tree composition
(def x [1 2])
(def y [4 5])
(defn- tree-comp-each [root branch & leaves]
(apply
root (map branch leaves)))
(defn euclidean-distance
[a b]
{:pre [(= (count a) (count b))]}
(defn eval-decompose
[coll]
(let [super-d (distinct coll)
freqs (loop [ps []
d super-d]
(if (seq d)
(let [c (count (filter (partial = (first d)) coll))]
(recur (conj ps c) (rest d)))
ps))]
(map #(vector %1 %2) super-d freqs)))
(defn match-count
" Given key, k, returns number of occurrences of k in collection, coll.
"
[k coll]
(let [match? (fn [i x]
(if (= k x) ;; closure on k
(inc i)
i))]
(reduce match? 0 coll)))
@Quantisan
Quantisan / ccl-checkpoint-sample1.clj
Created February 26, 2012 09:27
cascalog-checkpoint sample
(workflow [tmp-path]
step-A ([:tmp-dirs stage-a]
(query-A input stage-a))
step-B ([:deps step-A]
(query-B input stage-a output-b)))