Skip to content

Instantly share code, notes, and snippets.

@daviesian
daviesian / wpa_supplicant.conf
Created November 30, 2020 18:37
Raspberry Pi wifi config
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=GB
network={
ssid="<Name of your wireless LAN>"
psk="<Password for your wireless LAN>"
}
@daviesian
daviesian / Raspberry Pi Boot Script
Created November 14, 2020 11:59
Custom systemd service to run ~/boot.sh when Raspberry Pi boots
sudo nano /lib/systemd/system/custom-boot.service
```
[Unit]
Description=Custom Boot Script Service
After=multi-user.target
[Service]
Type=idle
ExecStart=/bin/bash /home/pi/boot.sh
apt-get update
apt-get install -y apt-transport-https ca-certificates
apt-key adv \
--keyserver hkp://ha.pool.sks-keyservers.net:80 \
--recv-keys 58118E89F3A912897C070ADBF76221572C52609D
echo "deb https://apt.dockerproject.org/repo ubuntu-xenial main" | sudo tee /etc/apt/sources.list.d/docker.list
apt-get update
apt-get install -y linux-image-extra-$(uname -r) linux-image-extra-virtual
apt-get install -y docker-engine

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

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
@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

@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 / 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: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)