Skip to content

Instantly share code, notes, and snippets.

View ossareh's full-sized avatar

P. Michael Ossareh ossareh

View GitHub Profile
@ossareh
ossareh / gist:713338
Created November 24, 2010 08:37
lazytest Exception
ossarehs-macbook:rah parhamossareh$ java -cp "src:test:classes:lib/*:lib/dev/*" lazytest.main src test
Exception in thread "main" java.lang.AssertionError: Assert failed: (not (depends? graph dep x))
at lazytest.dependency$depend.invoke(dependency.clj:41)
at clojure.lang.AFn.applyToHelper(AFn.java:169)
at clojure.lang.RestFn.applyTo(RestFn.java:133)
at clojure.core$apply.invoke(core.clj:544)
at lazytest.tracker$add_to_dep_graph$fn__86.invoke(tracker.clj:24)
at clojure.core$r.invoke(core.clj:799)
at lazytest.tracker$add_to_dep_graph.invoke(tracker.clj:21)
at lazytest.tracker$update_dependency_graph.invoke(tracker.clj:32)
@ossareh
ossareh / underscore_ex.html
Created December 2, 2010 19:46
underscore
<html>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript" src="http://documentcloud.github.com/underscore/underscore-min.js"></script>
<script>
var obj = {"NUM_T1":"581","CABS":{"NYKFP02-CABW1":{"VOLTAGE":54.51,"CURRENT":18.27},"NYKFP02-CABW2":{"VOLTAGE":54.65,"CURRENT":16.85}}}
_.each(obj.CABS, function(v, k) {
console.log("cab '" + k + "' has voltage: " + v.VOLTAGE) ;
}) ;
</script>
(defn pos-int-range [max]
;; rest drops leading 0
;; inc as range is not inclusive
(lazy-seq (rest (range (inc max)))))
(defn not-nil? [x] (not= nil x))
(defn hiphop [n]
(cond (> n 2)
(cond (and (zero? (mod n 15))) "Hop"
(ns company-count
(:use [clojure.contrib.http.agent :only (http-agent stream)])
(:use [clojure.contrib.json])
(:use [clojure.contrib.io :only (read-lines)]))
(defonce companies (read-json (slurp "http://api.crunchbase.com/v/1/companies.js")))
(def emp-ranges (agent {}))
@ossareh
ossareh / company_count.clj
Created December 12, 2010 21:35
without the issues
(ns company-count
(:require [work.core :as work])
(:use [clojure.contrib.json])
(:use [clojure.contrib.io :only (read-lines)]))
(defonce companies (read-json (slurp "http://api.crunchbase.com/v/1/companies.js")))
(def emp-ranges (agent {}))
@ossareh
ossareh / boilerplate.clj
Created January 3, 2011 01:41
boilerplate with a ring middleware
(ns surveyengine.boilerplate
(:use [hiccup.core])
(:use [hiccup.page-helpers]))
(defn boilerplate
([] (boilerplate {} [] [] [] [] {:prod? false}))
([{:keys [title desc author favicon apple-icon cssver] :as head}
header
main
footer
@ossareh
ossareh / riak crash
Created January 5, 2011 20:57
riak crash when parsing Ratio's encoded by c.c.json
==> log/sasl-error.log <==
=CRASH REPORT==== 4-Jan-2011::21:03:53 ===
crasher:
initial call: luke_phase:init/1
pid: <0.5305.13>
registered_name: []
exception exit: {error,[{<<"lineno">>,483},
{<<"message">>,<<"JSON.parse">>},
{<<"source">>,<<"unknown">>}]}
@ossareh
ossareh / why_clojure_rawks.clj
Created January 5, 2011 23:16
transform ratios to map and back again
(defmulti transform-ratio
"Transforms Ratios to and from maps. Passes other values through without changing them unless they are of type clojure.lang.Ratio or clojure.lang.PersistenArrayMap. In the case of a map they must be annotated with :t \"ratio\" otherwise they'll get passed through too"
class)
(defmethod transform-ratio :default [v] v)
(defmethod transform-ratio clojure.lang.Ratio [value]
{:n (numerator value)
:d (denominator value)
@ossareh
ossareh / exception
Created March 23, 2011 20:22
trace from riak logs when parsing string with \r\n in it
=ERROR REPORT==== 23-Mar-2011::13:20:53 ===
** State machine <0.1359.255> terminating
** Last event in was {mapexec_error,
{362449,'riak@127.0.0.1'},
{error,
[{<<"lineno">>,483},
{<<"message">>,<<"JSON.parse">>},
{<<"source">>,<<"unknown">>}]}}
** When State == executing
** Data == {state,0,riak_kv_map_phase,
riak_search> name:gran and name:"tur*"
{<<"games">>,<<"Gran%20Trak%2010">>,[{p,[0]},{score,0.0645806583071036}]}
{<<"games">>,<<"Gran%20Turismo">>,[{p,[0]},{score,0.0645806583071036}]}
{<<"games">>,<<"Gran%20Turismo%202">>,[{p,[0]},{score,0.0645806583071036}]}
{<<"games">>,<<"Gran%20Turismo%203%20A-Spec">>,
[{p,[0]},{score,0.0645806583071036}]}
{<<"games">>,<<"Gran%20Turismo%204">>,[{p,[0]},{score,0.0645806583071036}]}
{<<"games">>,<<"Gran%20Turismo%204%3A%20Prologue">>,
[{p,[0]},{score,0.0645806583071036}]}
{<<"games">>,<<"Gran%20Turismo%205">>,[{p,[0]},{score,0.0645806583071036}]}