Skip to content

Instantly share code, notes, and snippets.

Can you put LaTeX-style math in a Github Gist? Yes you can.

Use https://www.codecogs.com/eqnedit.php to edit your math. Use the little menu at the bottom to select "HTML (Edit)", and copy the stuff into your Gist. Here is a fairly meaningless example.

Clicking on this will allow your reader to review and edit the source.

@wware
wware / 0_Instrument_2018.md
Last active October 23, 2018 02:55
Another stupid electronic musical instrument

Instrument for 2018

Before spending time and money building a lot of electronics, let's prototype the thing in Javascript.

Hmm. Maybe a better idea would be to make up a board that accepts a Teensy 3.6, and provides audio hardware, and a bunch of pushbuttons and a few other controllers. Then you can develop code on a real Teensy with representative hardware support. When you go to the real instrument you're only changing the form factor, and maybe the number of buttons or switching to touch-sensitive or whatever.

Prior art - the Tooba, 2015

Non-blocking

The System.lang.Runtime.exec() method is non-blocking, so you call it and it spawns a background process.

Unfortunately the java.lang.Process thingy in Java 8 has no way to get a PID, so you need a cheesy hack to find it.

@wware
wware / connect_two_points.scad
Last active August 3, 2018 19:50
OpenSCAD code to create a cylinder connecting two given points in 3-space
v1 = [0, 2, -1];
v2 = [1, 3, 3];
y = [v2[0] - v1[0], v2[1] - v1[1], v2[2] - v1[2]];
translate(v1)
rotate(-acos(y[2] / norm(y)), cross(y, [0, 0, 1]))
cylinder(h=norm(y), d=0.1);
#!/usr/bin/env python
# https://en.wikipedia.org/wiki/Isomorphic_keyboard
# any hexagonal layout is defined by two offsets (the value of the third is forced by the first two)
import sys
many = [20 * [None] for _ in range(20)]
def display():
width = 4

Messing with Ansible and Docker

Nobody can remember how to use Docker, it is far too confusing. So here are some hints.

sudo docker build -t simple_flask:dockerfile .
sudo docker run -p 5000:5000 simple_flask:dockerfile python hello.py

My actual intention is to learn Ansible. But in order to run Ansible you need Docker, unless you happen to have a rackful of machines at your disposal which I do not.

@wware
wware / bash_waiter.sh
Created February 22, 2018 23:36
I want to run a couple Bash processes in parallel in the background. If I use "wait", I might end up waiting for a long-running process to finish after another process has already failed, and in this case I want to stop as soon as I see the failure.
#!/bin/bash
wait_all() {
# As soon as one of the background processes creates the EPIC_FAIL file,
# kill all background processes, rm EPIC_FAIL, and stop looping.
while [ $(jobs | grep -v Done | wc -l) -ne 0 ]; do
sleep 1
if [ -f EPIC_FAIL ]; then
rm -f EPIC_FAIL
echo OUCH
#!/usr/bin/env python
import argparse
import logging
import os
import sys
import pprint
from textwrap import dedent
HERE = os.path.dirname(__file__)
#!/usr/bin/env python
import logging
from flask import Flask
from twisted.internet import ssl, reactor
from twisted.web.wsgi import WSGIResource
from twisted.web.server import Site
from twisted.python.threadpool import ThreadPool
from twisted.application import service