Skip to content

Instantly share code, notes, and snippets.

@daviesian
daviesian / core.clj
Created August 22, 2012 18:40
First experiment with Datomic
;; This is core.clj from a lein2 project with the dependency [com.datomic/datomic-free "0.8.3397"]
;;
;; Based on the tutorial at http://docs.datomic.com/tutorial.html
(ns datomic-test.core
(:use [datomic.api :only [q db] :as d]
[clojure.pprint]))
@daviesian
daviesian / gist:3438768
Created August 23, 2012 17:05
Datomic data test
(ns datomic-test.numbers
(:use [datomic.api :only [q db] :as d]
[clojure.pprint]
[datomic-test.datomic-helpers]))
(def uri "datomic:mem://numbers")
(d/create-database uri)
(def conn (d/connect uri))
@daviesian
daviesian / Client.clj
Created November 8, 2012 16:07
Aleph Server and Client stuff
(ns meta-ex-client.core
(:use compojure.core
compojure.route
aleph.tcp
gloss.core
lamina.core
clojure.data.json
clojure.pprint))
@daviesian
daviesian / gist:4179391
Created November 30, 2012 23:17
nrepl exception
user=> Exception in thread "nREPL-worker-0" java.lang.NullPointerException
at clojure.core$refer.doInvoke(core.clj:3779)
at clojure.lang.RestFn.applyTo(RestFn.java:139)
at clojure.core$apply.invoke(core.clj:603)
at clojure.core$load_lib.doInvoke(core.clj:5279)
at clojure.lang.RestFn.applyTo(RestFn.java:142)
at clojure.core$apply.invoke(core.clj:603)
at clojure.core$load_libs.doInvoke(core.clj:5298)
at clojure.lang.RestFn.applyTo(RestFn.java:137)
at clojure.core$apply.invoke(core.clj:605)
@daviesian
daviesian / gist:4493790
Created January 9, 2013 15:04
Addition to nRepl.el for showing number of live threads in mode line.
;; Eval all this in the scratch buffer, then have a play with evaluating forms in a clojure buffer.
;; This is a very quick and dirty first version.
(setq thread-count 0)
(defun add-remote-thread ()
(setq thread-count (+ 1 thread-count))
(setq mode-name (format "Clojure{%d}" thread-count))
(force-mode-line-update))
@daviesian
daviesian / gist:4517859
Last active November 17, 2022 20:16
Code to redirect output nrepl output to a particular client repl.
;; After connecting an nrepl client repl to an nrepl server, some
;; output will still appear on stdout from the server.
;; Try these snippets - they will both produce output on the nrepl server
;; Java libraries commonly do both these things.
(.println System/out "Hello stdout.")
(.start (Thread. #(println "Hello from a new thread.")))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@daviesian
daviesian / Thing.md
Last active January 21, 2016 19:50
Useful Raspberry Pi setup commands

After changing IP in router config:

sudo dhclient -r && sudo dhclient

List audio devices:

aplay -l

or

aplay -L

To detect all silences longer than a second:

TIMES=`/c/dev/bin/ffmpeg-20160425-git-9ac154d-win64-static/bin/ffmpeg.exe -i ~/Desktop/DW33\ -\ Going\ Postal/Going\ Postal\ 01\ -\ Terry\ Pratchett.mp3 -af silencedetect=noise=0.001:d=1 -f null - 2>&1 | grep -E '^\[silence.*start' | cut --delimiter=\  --fields=5 | tr '\n' ','

To split file at those times:

/c/dev/bin/ffmpeg-20160425-git-9ac154d-win64-static/bin/ffmpeg.exe -i ~/Desktop/DW33\ -\ Going\ Postal/Going\ Postal\ 01\ -\ Terry\ Pratchett.mp3 -acodec copy -f segment -segment_times ${TIMES::-1} thing-%03d.mp3 2>&1

PostgreSQL Replication with Docker

Configuration

  • Make sure nothing exists already: docker-compose down -v
  • Create a blank DB in volume data-1, then start service pg1 using it: docker-compose run --rm pg1-create-primary && docker-compose up pg1
  • From another server, back up the data-1 db into data-2, then run pg2 as a hot-standby: docker-compose run --rm pg2-create-standby && docker-compose up pg2