Skip to content

Instantly share code, notes, and snippets.

View malcolmsparks's full-sized avatar

Malcolm Sparks malcolmsparks

View GitHub Profile
@malcolmsparks
malcolmsparks / emacs clojure formatter
Created February 18, 2011 08:54
Closeup closing parens in Clojure files - put in starter-kit-defuns.el if using the emacs starter kit
;;
;; Author: Malcolm Sparks
(defun closeup-parens ()
(interactive)
(save-excursion
(replace-regexp "[ \t\n]+)" ")" nil (point-min) (point-max))
(replace-regexp "([ \t\n]+" "(" nil (point-min) (point-max))
(replace-regexp "[ \t\n]+}" "}" nil (point-min) (point-max))
(replace-regexp "[ \t\n]+]" "]" nil (point-min) (point-max))
))
@malcolmsparks
malcolmsparks / gist:6044877
Created July 20, 2013 12:44
MQTT Clojure core.async code
(ns mqtt-insertion.core
(:require [clojure.core.async :refer :all])
(:import (org.eclipse.paho.client.mqttv3
MqttCallback
MqttAsyncClient
MqttConnectOptions
MqttDeliveryToken
MqttException
MqttMessage
MqttTopic
@malcolmsparks
malcolmsparks / gist:6044878
Last active December 12, 2017 07:13
MQTT example for Clojure core.async
(ns mqtt-insertion.core
(:require [clojure.core.async :refer :all])
(:import (org.eclipse.paho.client.mqttv3
MqttCallback
MqttAsyncClient
MqttConnectOptions
MqttDeliveryToken
MqttException
MqttMessage
MqttTopic
@malcolmsparks
malcolmsparks / bruce
Created December 9, 2013 15:29
bruce
(ns bruce.core)
(defn create-hand []
(->> (for [suit [:clubs :diamonds :hearts :spade]
rank [:ace :two :three :four :five
:six :seven :eight :nine :ten
:jack :queen :king]]
{:suit suit :rank rank})
shuffle
(take 5)))
@malcolmsparks
malcolmsparks / funky.clj
Created December 10, 2013 11:51
funky style
(defn funky-style []
[ [:link {:href "http://fonts.googleapis.com/css?family=Bonbon|Spicy+Rice|Gloria+Hallelujah|Faster+One" :type "text/css" :rel "stylesheet"}]
[:style "h1 { font-family: \"Gloria Hallelujah\""]]
)
#=(eval
(-> (clojure.core/read-string (slurp "/home/malcolm/src/azondi/config.clj"))
((partial clojure.walk/postwalk
(fn [x] (if-let [path (and (string? x) (second (re-matches #"\.\./azondi(.*)" x)))]
(str "/home/malcolm/src/azondi" path)
x))))
;; Comment these 3
#_(update-in [:jig/components] dissoc
@malcolmsparks
malcolmsparks / gist:11109616
Created April 20, 2014 09:25
Autowire dependenices in component
(defn autowire-dependencies-satisfying
"Return a dependency map, adding dependencies between the given
key (of the dependant) and any components in the given system map that
satisfy the given protocol."
[dependency-map system-map dependant-key proto]
(merge-with merge dependency-map (normalize-dependency-map {dependant-key (vec (keep (fn [[k v]] (when (satisfies? proto v) k)) (seq system-map)))})))
### Keybase proof
I hereby claim:
* I am malcolmsparks on github.
* I am malcolmsparks (https://keybase.io/malcolmsparks) on keybase.
* I have a public key whose fingerprint is D7EA C082 D28B C792 3327 9A32 06CE E45E C93B 3AF9
To claim this, I am signing this object:
@malcolmsparks
malcolmsparks / gist:1c26adba3a55cefa057a
Created December 11, 2014 09:34
perf testing with http-kit and core.match
(ns perf.test
(:require
[org.httpkit.client :refer (request) :rename {request http-request}]
[clojure.core.async :refer (chan >! <! go go-loop)]
[clojure.core.match :refer (match)]
[ring.mock.request :refer (request) :rename {request mock-request}]))
(defn with-profiling [p & {:keys [callback]}]
(let [start (System/nanoTime)
dur (atom nil)]
@malcolmsparks
malcolmsparks / gist:473ece4b4905dadb0dc4
Created December 22, 2014 14:40
aleph seems to hang
(defproject alephplay "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.7.0-alpha4"]
[aleph "0.4.0-alpha9" :exclusions [org.clojure/clojure]]])
(ns alephplay.core