Skip to content

Instantly share code, notes, and snippets.

View postspectacular's full-sized avatar
🎉
Celebrating 24 years of building open source tools

Karsten Schmidt postspectacular

🎉
Celebrating 24 years of building open source tools
View GitHub Profile
@postspectacular
postspectacular / ffmpeg-av-seq.sh
Created August 10, 2012 22:49
ffmpeg image seq + audio + watermark
ffmpeg -f image2 -i render-%04d.png -i audio.mp3 -r 25 -vcodec libx264 -b:v 1024k -b:a 192k -t 00:00:04 -vf "movie=watermark.png [watermark]; [in][watermark] overlay=10:10 [out]" out.mp4
@postspectacular
postspectacular / quil-agents
Last active November 29, 2019 15:58
Quick clojure/quil demo to show usage of atoms to manage mutable state, AFAIK quil's architecture doesn't really allow for purely functional approach... even so, with some care one can seriously limit the number points where that mutable state is actually used (here in only 2 places) and the rest remains purely functional! The second version bel…
(ns resonate-2013.agents
(:use quil.core))
(def num-agents 50)
(def num-targets 10)
;;; atom to hold global app state
(def app-state (atom {}))
;;; cheapskate vector ops
@postspectacular
postspectacular / problem59.clj
Created May 11, 2013 19:12
Project Euler #59 solution w/ Clojure
(ns toxi.euler.problem59)
;; http://projecteuler.net/problem=59
;; solution by: toxi <k at postspectacular dot com>
;; 2012-12-23
(defn xor-decrypt
"Applies bit-xor to all items in src using key as cyclic sequence."
[src key] (map bit-xor src (cycle key)))
@postspectacular
postspectacular / 1-project.clj
Last active October 4, 2020 13:24
Quick demo project of how to use leiningen profiles to provide alternative implementations of a namespace... The project.clj defines two profiles :dev & :prod with alternative source paths for each. The main code should remain in the main /src folder and the namespace to be altered must be provided in both /src.dev and /src.prod
(defproject profiletest "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.5.1"]]
:main profiletest.core
:profiles {
:dev {:source-paths ["src" "src.dev"]}
:prod {:source-paths ["src" "src.prod"]}
@postspectacular
postspectacular / tetrahedron-intersect.clj
Last active July 26, 2021 13:25
Tetrahedron intersection (currently runs in ~36% time than original revision of this gist)
;; Tetrahedron intersection based on this paper & algorithm:
;; http://vcg.isti.cnr.it/Publications/2003/GPR03/fast_tetrahedron_tetrahedron_overlap_algorithm.pdf
;;
;; Unlike original algorithm this implementation produces correct
;; results regardless of the orientation/ordering of points defining
;; the two tetrahedra. This is achieved via the orient-tetra function,
;; which ensures the correct ordering of vertices for this algorithm
;; to function properly.
;;
;; Implementation extracted from upcoming geometry library
@postspectacular
postspectacular / deftype-apply.clj
Created February 19, 2014 17:22
deftype & applyTo problem illustrated
(deftype Foo [x y]
clojure.lang.IFn
(invoke [_ a] (case a 0 x, 1 y))
(invoke [_ a nf] (case a 0 x, 1 y nf)))
(def f (Foo. 23 42))
(f 0) ; => 23
(f 2 -1) ; => -1
(apply f [0]) ; AbstractMethodError clojure.core/apply (core.clj:624)
@postspectacular
postspectacular / pointatdemo.clj
Last active August 29, 2015 13:57
3D point-at demo using alignment quaternion. this example requires thi.ng/geom "0.3.0-SNAPSHOT" or later.
(ns pointatdemo
(:require
[thi.ng.geom.core :as g]
[thi.ng.geom.tetrahedron :as t]
[thi.ng.geom.meshio :as mio]
[clojure.java.io :as io]))
(defn point-at
"Takes an entity implementing PTransform, a reference point and two
direction vectors. Transforms the entity in such a way that the 1st
@postspectacular
postspectacular / gist:10312313
Created April 9, 2014 20:38
Setup selfsigned SSL cert for nginx
# https://www.digitalocean.com/community/articles/how-to-create-a-ssl-certificate-on-nginx-for-ubuntu-12-04
sudo openssl genrsa -des3 -out new.key 1024
sudo openssl req -new -key new.key -out new.csr
sudo cp new.key new.key.orig
sudo openssl rsa -in new.key.orig -out new.key
sudo openssl x509 -req -days 1095 -in new.csr -signkey new.key -out new.crt
sudo service nginx restart
@postspectacular
postspectacular / retune-dnb.rb
Last active August 22, 2021 16:08
Sonic-PI livecoding demo @ Retune 2014 - only temporary home here until repo w/ talk slides is up
# Live coding example for Retune conference 2014
# 1) Press Run (Cmd+R) to start
# 2) Make changes (e.g. comment in/out various lines in :beats & :amen)
# 3) Press Run again (changes will only be audible from next queue point)
# compute loop length (4 bars), bar & quarter note durations
dur = sample_duration :loop_compus
bar = dur / 4
quart = dur / 16
;; add lein dep:
;; [org.bouncycastle/bcpg-jdk15on "1.51"]
;; export gpg public & private keys to armored files:
;; gpg -ao pub.asc --export XXXXXXXX
;; gpg -ao pk.asc --export-secret-keys XXXXXXXX
;; usage:
;; (encrypt "foo.txt" "foo.gpg" (pub-key "pub.asc"))
;; (decrypt "foo.gpg" (io/output-stream "foo.txt") (secret-key "ks-pk.asc") "passphrase")