Skip to content

Instantly share code, notes, and snippets.

(ns api-tunnel.http
(:require [compojure.route :as route]
[compojure.handler :as handler])
(:use org.httpkit.server
[datomic.api :only [db q] :as d]
))
;; - ;; - ;; - ;; - ;; - ;; - ;; - ;; - ;; - ;; - ;; - ;; - ;; - ;; - ;; - ;; - ;; - ;; - ;; - ;; - ;; - ;; - ;; - ;; - ;; - ;; -
@thebusby
thebusby / gist:5472980
Created April 27, 2013 12:41
Example of how you can use reducers to run in parallel and generate a single output stream for IO/etc.
(defmacro thread
"Execute the following S-EXP in another thread, and return thread"
[sexp]
`(let [thread# (java.lang.Thread. (fn [] ~sexp))]
(.start thread#)
thread#))
(defn fold-into-lazy-seq
"Accept a reducible sequence, and produce a lazy-seq of it's results.
Order *NOT* guarranteed!"
#!/usr/bin/ruby
# Must install libusb library via your favorite package manager
# Then install libusb ruby gem, via $ sudo gem install libusb
require 'libusb'
# Call provided blocks when key is pressed or released
def handle_pedal(device, onpress, onrelease)
device.open do |h|
(defn rindex-by-fn
"Uses core.reducers/fold to return a map indexed by the value of key-fn
applied to each element in coll.
Note: key-fn can return a collection of multiple keys."
([key-fn coll ] (rindex-by-fn key-fn identity coll))
([key-fn value-fn coll] (doall (clojure.core.reducers/fold
;; combinef
(defn fold-into-vec [coll]
"Provided a reducer, concatenate into a vector.
Note: same as (into [] coll), but parallel."
(r/fold (r/monoid into vector) conj coll))
(defn capture-image
"Capture an image of specified size from the primary screen at specified point"
[from-x from-y x-size y-size]
(let [rob (java.awt.Robot.)
rect (java.awt.Rectangle. from-x from-y x-size y-size)]
(. rob createScreenCapture rect)))
(defn grab-screen
"Capture the entire primary screen and return BufferedImage"
[]