Skip to content

Instantly share code, notes, and snippets.

View kriskowal's full-sized avatar

Kris Kowal kriskowal

View GitHub Profile
@kriskowal
kriskowal / controltheoryplayground.go
Last active September 19, 2018 04:34
A control theory playground. Eliminate dropped messages, minimize latency, maximize throughput.
package main
import (
"fmt"
"image"
"image/color"
"image/draw"
"image/png"
"os"
"sync"
var origin = entities[0].position;
for (var i = 0; i < entities.length; i++) {
var entity = entities[i];
entity.relativePosition.copyFrom(entity.position).subThis(origin);
entity.distance = entity.relativePosition.distance();
entity.direction = Math.atan2(entity.relativePosition.y, entity.relativePosition.x);
entity.distortion = res*Math.atan2(entity.distance, elevation)/Math.PI;
entity.projection.x = Math.cos(entity.direction) * entity.distortion;
entity.projection.y = Math.sin(entity.direction) * entity.distortion;
drawVessel(entity.projection.x, entity.projection.y, entity.orientation);
@kriskowal
kriskowal / termbox.go
Last active November 9, 2017 00:43
Go command line tool that renders a box in the terminal’s dimensions until you press any key.
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
"unsafe"
"github.com/pkg/term/termios"
#!/bin/bash
ex - README.md << "EOF"
/```\nUsage:/
+1,/```\n/-1d
-1 r! bin/tool --help
:w
EOF
@kriskowal
kriskowal / finally.js
Created October 16, 2017 18:36
Finally
// resource cleanup after work, using finally
return server.start()
.then(work)
.finally(server.stop);
// or with native promises
return server.start()
.then(work)
.then(
(val) => server.stop()
func Tick(next, prev *World) {
var i IntVec2
total := SumOfLife(prev.Field)
for i.X = 0; i.X < Width; i.X++ {
for i.Y = 0; i.Y < Height; i.Y++ {
s := SumOfLifeAbout(prev.Field, i)
life := prev.Field.At(i).Life
if life > 0 {
func Tick(next, prev *World) {
var i IntVec2
total := SumOfLife(prev.Field)
for i.X = 0; i.X < Width; i.X++ {
for i.Y = 0; i.Y < Height; i.Y++ {
s := SumOfLifeAbout(prev.Field, i)
life := prev.Field.At(i).Life
if life > 0 {

The following data overlays pitches in equal temperament (a piano tuned to be equally out of tune regardless of which key you use as the root of your chords, the fundamental), against frequencies that are harmonics of the fundamental.

Harmonics that are closer to the left will tend to be more pleasing to the ear (consonant, as opposed to dissonant). Every time you overlay two frequencies, it produces a third frequency: an overtone or undertone depending on whether it is above or below the primary tones. Dissonance occurs when an overtone soars toward the upper end of the spectrum of perceptible frequencies (around 20KHz), or rumbles low, close to the bottom end of the perceptible spectrum (around 16Hz).

       A - 440   Hz Do
   64/63   447.0 Hz                                                                | 64/63
   33/32   453.8 Hz                                  | 33/32
   32/31   454.2 Hz                                | 32/31
   64/61   461.6 Hz                                                    
@kriskowal
kriskowal / tweedux.js
Last active July 11, 2017 20:47
Redux in a Tweet
// Tweedux.js
const tweedux = (reduce, state, observe) => (action) => {
state = reduce(state, action)
observe(state)
}
@kriskowal
kriskowal / potter.md
Last active August 14, 2021 19:20
On the incompetence of Albus