Skip to content

Instantly share code, notes, and snippets.

(ns lucenalog.core
"Lucenalog = Datalog interface to Lucene in 10 lines.
Simple but powerful.
Use
(db/add (index) {:a \"foo\" :b \"bar\"})
to index a map with Lucene. Then you can use the relation
@ohpauleez
ohpauleez / fs.clj
Created December 17, 2012 05:59
This is a preview of my experiments using the Alloy Language and Verifier in Clojure. The goal is to use one common, open spec backend to generate: test.generative tests, core.contract constraints, Alloy specs, extra documentation, etc
(ns sterling.example.filesystem.fs
(:require [clojure.walk :as cwalk]))
;; Overview
;; ==========
;;
;; A common example is to illustrate Alloy's abilities is a simpel filesystem.
;;
;; Below is a pure Clojure implementation of the same system, with the same
;; checks.
@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.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}))
(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]])