Skip to content

Instantly share code, notes, and snippets.

View Quantisan's full-sized avatar

Paul Lam Quantisan

View GitHub Profile
@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 / corr_demo.clj
Created June 26, 2011 00:49
first try using Incanter to analyse stocks data
(ns inc-sandbox.corr-demo
(:require [clojure.set :as set])
(:use (incanter core stats charts io))
(:require [clj-time.core :as time])
(:use (clj-time [format :only (formatter formatters parse)]
[coerce :only (to-long)])))
(defn sym-to-dataset
"returns a dataset read from a local CSV in './data/' given a Yahoo Finance symbol name"
[yf-symbol]
@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 / wunderground.R
Created February 12, 2012 11:43
a weather station data scrapper
# Scrapes wunderground weather record
#
# Based on http://casoilresource.lawr.ucdavis.edu/drupal/node/991
#
# Usage:
# fetch.temperature('ILONDONL8', '2012-01-01', '2012-01-30')
#
fetch.temperature <- function(station, start.date, end.date) {
date.range <- seq.Date(from=as.Date(start.date), to=as.Date(end.date), by='1 day')
@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)))
@Quantisan
Quantisan / map_counter.clj
Created March 7, 2012 15:37
equal-weight mapped counter
(comment
;; "Usage Example"
(facts
(attrib-model [["a" "a"]
["b"]
["b" "c" "a"]
["b"]]
equal-weights) => {"a" 4/3, "b" 7/3, "c" 1/3})
)
@Quantisan
Quantisan / RiskManager.java
Created June 18, 2012 21:31
JForex risk manager 1.0
/*
RiskManager.java
version 1.0
Copyright 2010 Quantisan.com
*/
package jforex;
import java.math.*;
@Quantisan
Quantisan / output
Created August 23, 2012 20:21
Impatient part 1
$ more output/rain/part-00000
doc_id text
doc01 A rain shadow is a dry area on the lee back side of a mountainous area.
doc02 This sinking, dry air produces a rain shadow, or area in the lee of a mountain with less rain and cloudcover.
doc03 A rain shadow is an area of dry land that lies on the leeward (or downwind) side of a mountain.
doc04 This is known as the rain shadow effect and is the primary cause of leeward deserts of mountain ranges, such as California's Death Valley.
doc05 Two Women. Secrets. A Broken Land. [DVD Australia]