This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def admins #{{:name "owen" :id 1} {:name "paul" :id 2} {:name "bazzz" :id 3}}) | |
(def orgs #{{:name "xively" :id 1} {:name "cosm" :id 2} {:name "patchbay" :id 3}}) | |
(def groups #{{:name "admins" :id 1} {:name "owners" :id 2} {:name "playas" :id 3}}) | |
(def joins #{{:admin-id 1 :org-id 1 :group-id :1} | |
{:admin-id 2 :org-id 1 :group-id :1} | |
{:admin-id 2 :org-id 2 :group-id :2} | |
{:admin-id 3 :org-id 3 :group-id :3}}) | |
(defn join-tables [src-key dst-key dst-table val] | |
(let [;; "select distinct dst-key from joins where src-key = val" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns app | |
(:gen-class)) | |
(defn -main [& args] | |
(require 'myapp.core) | |
(eval `(apply myapp.core/old-main ~args))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns dbtest.datomic | |
(:require [datomic.api :as d])) | |
(def uri "datomic:mem://test") | |
(d/delete-database uri) | |
(d/create-database uri) | |
(def conn (d/connect uri)) | |
(def urif "datomic:free://localhost:4334/test") | |
(d/delete-database urif) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
all: iedl.exe | |
iedl.exe: iedl.cpp | |
g++ -g iedl.cpp -o iedl.exe -l wininet | |
clean: | |
rm -rf iedl.exe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; http://dev.clojure.org/jira/browse/CMEMOIZE-8 | |
(defn memoize-ttl [f time-to-live] | |
(let [mem (atom {})] | |
(fn [& args] | |
(let [[_ [r t]] (find @mem args)] | |
(if (and t (<= (- (System/currentTimeMillis) t) time-to-live)) | |
r | |
(let [ret (apply f args)] | |
(swap! mem assoc args [ret (System/currentTimeMillis)]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(clj-http.client/get "http://www.google.com" {:proxy-host "inetproxy3" :proxy-port 8080 :digest-auth ["<u>" "<p>"]}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn walk [tree ch] | |
(letfn [(walker [t] | |
(go | |
(when t | |
(walker (:left t)) | |
(>! ch (:value t)) | |
(walker (:right t)))))] | |
(walker tree) | |
(close! ch))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(time | |
(def data-thread | |
(let [c (chan) | |
res (atom [])] | |
;; fetch em all | |
(doseq [i (range 10 100)] | |
(thread (>!! c (blocking-get (format "http://fssnip.net/%d" i))))) | |
;; gather results | |
(doseq [_ (range 10 100)] | |
(swap! res conj (<!! c))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// If you took the matter in a teaspoon of water, and converted that to energy, | |
// how many gallons of gasoline would you have to burn to get an equal amount of energy? | |
scala> 'teaspoon * 'water * ('c ** 2) to 'gallons * 'gasoline | |
res0: frins.NumberT = 3164209.862836101 [dimensionless] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package frins | |
class Ratio(n: BigInt, d: BigInt) { | |
require(denom != 0) | |
private val g = gcd(n.abs, d.abs) | |
val numer: BigInt = n / g | |
val denom: BigInt = d / g | |
private def gcd(a: BigInt, b: BigInt): BigInt = |