Skip to content

Instantly share code, notes, and snippets.

(set-bounds! [-14 -10 -10] [14 10 10])
(set-quality! 8)
(set-resolution! 10)
(define super-egg (lambda-shape (x y z)
(- (sqrt (sqrt (+ (* x x x x)
(* y y y y)
(* z z z z)))) 1)))
(define semi-egg (lambda-shape (x y z)
#version 100
#ifdef GL_ES
precision mediump float;
#endif
varying vec2 v_texcoord;
uniform sampler2D tex;
uniform float time;
uniform float width;
uniform float height;
@mds2
mds2 / launch_virtual_webcam.sh
Last active November 11, 2021 00:08
shader video effect for zoom (on linux)
# run this one *after* running setup_virtual_webcam.sh
# it will require a variety of gstreamer plugins
# it will also take over your main webcam.
# Kill the process(es) this launches to regain control of your main webcam
gst-launch-1.0 --gst-debug -v v4l2src device=/dev/video0 ! video/x-raw,width=640,height=360 ! videoconvert ! video/x-raw,format=RGBA ! glupload ! glshader fragment="\"`cat myshader.frag`\"" ! gldownload ! video/x-raw,width=640,height=360 ! queue ! videoconvert ! video/x-raw,format=I420,framerate=30/1 ! v4l2sink device=/dev/video10
Python 3.6.9 (default, Apr 18 2020, 01:56:04)
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import wave
>>> writer = wave.open("foo.wav", "wb")
>>> writer.setnchannels(2)
>>> from math import sin, cos
>>> writer.setsampwidth(1)
>>> writer.setframerate(44100)
>>> vals_left = [sin(3.0 * sin(3.14159265 * 440 * i / 44100)) for i in range(44100)]
@mds2
mds2 / dronezone.service
Created May 14, 2018 16:20
simple web interface to systemd music player
[Unit]
Description=Dronezone (somafm) music player
Conflicts=sonic-universe.service groove-salad.service silence.service
[Service]
Type=simple
WorkingDirectory=/home/pi
ExecStart=/usr/bin/mplayer http://ice3.somafm.com/dronezone-128-mp3
KillMode=process
Restart=on-failure
@mds2
mds2 / udp-event-triggered-sound.clj
Created February 28, 2015 07:43
Slightly more flexible networked event-triggered sound
(ns sound-sample-server (:import
(java.net InetAddress
DatagramPacket
DatagramSocket)))
(use 'overtone.core)
(boot-server)
(defn make-udp-trigger [sound-file port extra-args]
(let [sample-buf (load-sample sound-file)
@mds2
mds2 / udp_noise.clj
Created February 27, 2015 02:08
Single page networked sound server
(ns sound-sample-server (:import
(java.net InetAddress
DatagramPacket
DatagramSocket)))
(use 'overtone.core)
(boot-server)
(defn make-udp-trigger [sound-file port]
(.start
@mds2
mds2 / sound_testing.clj
Created February 26, 2015 03:22
Overtone/Clojure samples can be played on top of themselves with no clicking.
(use 'overtone.core)
(boot-server)
(def samp1 (sample "power_melody.wav")) ; see http://alumni.soe.ucsc.edu/~mds/amp_testing/power_melody.wav
;;; Play the same sample a bunch of times with overlap
(loop [n-remaining 10 delay-to-use 0]
(after-delay delay-to-use samp1)
(if (> n-remaining 0) (recur (- n-remaining 1) (+ delay-to-use 1800)) '()))
;;; to play the sample once, just enter
@mds2
mds2 / horse-race.clj
Created November 29, 2014 01:36
adventures in information theory and optimal gambling
;;; Every time I read about information theory, gambling, and the optimal
;;; way to bet on horse races, I am sufficiently surprised by what the math is
;;; telling me that I develop a desire to run experiments to double-check it
;;; for myself.
;;;
;;; See : http://en.wikipedia.org/wiki/Gambling_and_information_theory
;;; See : http://en.wikipedia.org/wiki/Kelly_criterion
;;;
;;; Note that my notion of "odds" might not exactly match up with the
;;; conventional notion. Mine are easier to compute with.