Skip to content

Instantly share code, notes, and snippets.

@numist
numist / layout.kbd.json
Last active Jan 31, 2021
Harmonic Isomorphic MIDI Keyboard
View layout.kbd.json
[
[{"c":"#cccccc", "a":7, "x":6.0}, {"c":"#9999cc"}, "C₈", {"c":"#cccccc"}, {"c":"#333333","t":"#cccccc"},"C₈#",{"c":"#cccccc","t":"#000000"}, "D₈", {"c":"#333333","t":"#cccccc"},"D₈#",{"c":"#cccccc","t":"#000000"}, "E₈", "F₈", {"c":"#333333","t":"#cccccc"},"F₈#",{"c":"#cccccc","t":"#000000"}, "G₈", {"c":"#333333","t":"#cccccc"},"G₈#",{"c":"#cccccc","t":"#000000"}, "A₈", {"c":"#333333","t":"#cccccc"},"A₈#",{"c":"#cccccc","t":"#000000"}, "B₈"],
[{"c":"#cccccc", "a":7, "x":5.5}, {"c":"#333333","t":"#cccccc"},"G₇#",{"c":"#cccccc","t":"#000000"}, "A₇", {"c":"#333333","t":"#cccccc"},"A₇#",{"c":"#cccccc","t":"#000000"}, "B₇", {"c":"#9999cc"}, "C₈", {"c":"#cccccc"}, {"c":"#333333","t":"#cccccc"},"C₈#",{"c":"#cccccc","t":"#000000"}, "D₈", {"c":"#333333","t":"#cccccc"},"D₈#",{"c":"#cccccc","t":"#000000"}, "E₈", "F₈", {"c":"#333333","t":"#cccccc"},"F₈#",{"c":"#cccccc","t":"#000000"}, "G₈", {"c":"#333333","t":"#cccccc"},"G₈#",{"c":"#cccccc","t":"#000000"}],
[{"c":"#cccccc", "a":7, "x":5.0}, "E₇", "F₇", {"c":"#3333
@numist
numist / WorkQueue-FrontierBiNode.swift
Created Apr 10, 2020
Internal type FrontierBiNode from the Club diffing algorithm's work queue
View WorkQueue-FrontierBiNode.swift
/*
FrontierBiNode is a quadtree node with two additional restrictions:
1) all insertions to the southwest are dropped
2) insertions to the northeast are not allowed
Restriction 2) is satisfied by performing all insertions in descending
order of (x+y), resulting in a binary tree structure (all children lie to
the northwest or southeast) containing only points representing edit paths
that have made novel progress.
*/
@numist
numist / Opto.cpp
Created Sep 29, 2019
Digispark firmware providing a digital optical sensor used for controlling timing on model motors
View Opto.cpp
#include "Opto.h"
bool Opto::getState() {
return state;
}
bool Opto::loop(int val) {
bool prev_state = state;
if (val > highest) { highest = val; }
if (val < lowest) { lowest = val; }
@numist
numist / Main.swift
Last active Aug 21, 2019
A rough Swift implementation of the Vose alias method
View Main.swift
// What is an alias method?
// If we have a list of elements with different frequencies,
// like the letters in the English language…
let frequencies = [
("a", 8.167), ("b", 1.492), ("c", 2.782), ("d", 4.253), ("e", 12.702),
("f", 2.228), ("g", 2.015), ("h", 6.094), ("i", 6.966), ("j", 0.153),
("k", 0.772), ("l", 4.025), ("m", 2.406), ("n", 6.749), ("o", 7.507),
("p", 1.929), ("q", 0.095), ("r", 5.987), ("s", 6.327), ("t", 9.056),
("u", 2.758), ("v", 0.978), ("w", 2.360), ("x", 0.150), ("y", 1.974),
@numist
numist / README.md
Last active Aug 2, 2017
Parse input from `ping 8.8.8.8 | ts '%s'` and print outage statistics
View README.md

Prints outage statistics from ping output

Usage

ping 8.8.8.8 | ts '%s' | ./outageReport.rb

Examples:

Packet loss

View Model-Z70.kbd.json
[
{
"name": "Model Z70",
"switchMount": "cherry",
"plate": true
},
[
"~\n`",
{
"a": 0
@numist
numist / plot.swift
Last active Mar 14, 2016
A function that plots (as a string) a function of (Double) -> Double
View plot.swift
import Darwin // Provides: sin/cos/tan
// memoize function from https://gist.github.com/berkus/8a9e104f8aac5d025eb5
func memoize<T: Hashable, U>( body: ( (T)->U, T )->U ) -> (T)->U {
var memo = Dictionary<T, U>()
var result: ((T)->U)!
result = { x in
if let q = memo[x] { return q }
let r = body(result, x)
memo[x] = r
@numist
numist / RSSKit.swift
Created Jul 31, 2015
Feed and Folder protocols with a couple of concrete implementations in the spirit of http://inessential.com/2015/07/19/secret_projects_diary_2_swift_2_0_prot
View RSSKit.swift
func ==<T:Feed>(lhs: T, rhs: T) -> Bool {
return lhs.link == rhs.link
}
protocol Feed : Equatable {
var link : String {get}
}
protocol Folder {
typealias FeedType: Feed
@numist
numist / scheduler.c
Last active Aug 29, 2015
Simple work scheduler and test harness for microcontroller projects in C.
View scheduler.c
#include "scheduler.h"
#include <stddef.h>
#include <stdbool.h>
//
// Compatibility macros
//
// Missing from Arduino toolchain
#ifndef UINT16_MAX
@numist
numist / there_i_fixed_it.rb
Created Nov 13, 2014
Get the system time zone in Olson format using Ruby
View there_i_fixed_it.rb
def get_local_timezone_str
# Yes, this is actually a shell script…
olsontz = `if [ -f /etc/timezone ]; then
cat /etc/timezone
elif [ -h /etc/localtime ]; then
readlink /etc/localtime | sed "s/\\/usr\\/share\\/zoneinfo\\///"
else
checksum=\`md5sum /etc/localtime | cut -d' ' -f1\`
find /usr/share/zoneinfo/ -type f -exec md5sum {} \\; | grep "^$checksum" | sed "s/.*\\/usr\\/share\\/zoneinfo\\///" | head -n 1
fi`.chomp