Skip to content

Instantly share code, notes, and snippets.

@ohpauleez
ohpauleez / example.html
Created November 8, 2012 19:26
Example of JSON import/export with localStorage
<html>
<head><title>Example of import/export for localstorage</title></head>
<body>
<h3 id="example-text">LS:...</h3>
</body>
<script>
var text = document.getElementById("example-text"),
storage_key = "hidden_ids",
json_str;
localStorage[storage_key] = [1, 2, 3, 4, 5];
@ohpauleez
ohpauleez / blockingderef.cljs
Created October 26, 2012 22:56
Blocking Deref Blog example
(defn blocking-deref
"Given an atom and a Result object, attempt to cycle the process tick on derefing until `pred-fn` isn't true
By default, `pred-fn` is nil?
Once the condition doesn't hold, the Result will be set to @a, and @a is returned"
([a r]
(blocking-deref a r nil?))
([a r pred-fn]
(if (pred-fn @a)
(node/process.nextTick #(blocking-deref a r pred-fn))
(do (.setValue r @a)
@ohpauleez
ohpauleez / thread.clj
Created October 15, 2012 16:16 — forked from fogus/thread.clj
new thread macros draft
(defmacro test->
"Takes an expression and a set of test/form pairs. Threads expr (via ->)
through each form for which the corresponding test is true."
[expr
& clauses]
(assert (even? (count clauses)))
(let [g (gensym)
pstep (fn [[test step]] `(if ~test (-> ~g ~step) ~g))]
`(let [~g ~expr
~@(interleave (repeat g) (map pstep (partition 2 clauses)))]
@ohpauleez
ohpauleez / fork.clj
Created October 5, 2012 15:51 — forked from cemerick/usage.sh
leiningen.fork
(ns leiningen.fork
(:require [leiningen.core.main :as main]
[leiningen.do :as do]))
(defn fork
[project task-name & args]
(apply println "Forking" task-name args)
(future
(main/apply-task (main/lookup-alias task-name project) project args)))
@ohpauleez
ohpauleez / cl-graph.clj
Created September 27, 2012 19:14 — forked from martintrojer/cl-graph.clj
core.logic graph blog
(ns cl-graph
(:refer-clojure :exclude [==])
(:use clojure.core.logic))
;; Directed Acyclic Graphs
(defrel edge a b)
;; a
;; |
@ohpauleez
ohpauleez / common.py
Created September 11, 2012 20:41
Useful Python functions
#!/usr/bin/env python
import collections
# DO NOT USE GENSHI'S FLATTEN - it is not a generator and will chew up CPU and RAM
def flatten(l):
"""
Flatten all iterables (lists, tuples, dicts, etc), into one lazy generator-stream
"""
if isinstance(l, dict):
l = l.items()
(ns barker.client.main
(:require [barker.client.render :as render]
[barker.client.search :as search]
[shoreleave.client.common :as common]
[shoreleave.client.history :as history]
[shoreleave.client.pubsubs.simple :as pbus]
[shoreleave.client.pubsubs.protocols :as pubsub]
[shoreleave.client.worker :as swk]
)
(:use [jayq.core :only [$ attr]])
(ns barker.client.search
(:require [clojure.string :as cstr]
[shoreleave.client.services.geo :as geo]
[shoreleave.client.remote :as remote])
(:use [jayq.core :only [$ inner]]))
(defn query->map [search-query]
(let [[topic location] (map cstr/trim (cstr/split search-query #" near "))
zip (when (re-find #"\d" location) location)] ;if we see an digit, we assume it's some kind of zip
{:raw-query search-query :topic topic :location location :zip zip}))
@ohpauleez
ohpauleez / main.cljs
Created June 12, 2012 02:36
Shoreleave's Web Workers
(ns barker.client.main
(:require [shoreleave.client.worker :as swk]))
; Take any function in your source...
(defn echo-workerfn [data] data)
; Drop it into a worker...
(def nw (swk/worker echo-workerfn))
; The worker implements IWatchable
(comment
Given some rules like:
{(if ?x ?y nil) (when ?x ?y)
(when true . ?x) (do . ?x)}
And the `unify` and `check-form` functions below,
I would like to apply `unify` until I `unify` returns nil.