Skip to content

Instantly share code, notes, and snippets.

@mgold
mgold / arithmetic-diff.py
Last active December 17, 2015 07:29
Play with the differences between linear values, quadratic values, exponential values, and whatever else you like.
DEPTH = 6
LENGTH = 12
#Change me!
def f(i):
return i
#also try:
#return i**2
#return 2**i
@mgold
mgold / octBright.c
Last active December 20, 2015 15:59
Translates octal digits into ASCII art, with the brightness correlated to the magnitude of the digit. The input may be either ASCII octal digits or machine octal. Try it on random data, or the compiled executable of the program (and vary your terminal width). A hexidecimal version is also available.
/* octBright.c - visualize octal data with brightness
* Max Goldstein
*
* example usage:
* $ od -o < /dev/random | sed 's/^[0-9]* +//' | tr -d ' ' | ./octBright
*/
#include <stdio.h>
int main(){
@mgold
mgold / hexBright.c
Created August 5, 2013 20:14
Translates hexidecimal digits into ASCII art, with the brightness correlated to the magnitude of the digit. The input may be either ASCII hex (either upper or lowercase) digits or machine values. Try it on random data, or the compiled executable of the program (and vary your terminal width). An octal version is also available.
/* hexBright.c - visualize hex data with brightness
* Max Goldstein
*
* example usage:
* $ head /dev/urandom | hexdump -e '16/1 "%02x " "\n"' | ./hexBright
*/
#include <stdio.h>
int main(){
@mgold
mgold / gyrations.elm
Created August 27, 2013 01:42
A screensaver written in Elm (elm-lang.org). Just about everything is sinusoidal. See it at: http://share-elm.com/gists/6348780
-- Gyrations by Max Goldstein
import Window
main = scene <~ foldp (+) 0 (fps 40) ~ Window.dimensions
scene t (w,h) =
let minr = 14
maxr = 40
time = inSeconds t
@mgold
mgold / sploosh.elm
Created August 27, 2013 01:48
A fun sploosh ball, written in Elm. See it: http://share-elm.com/gists/6348805
-- Sploosh Ball by Max Goldstein
import Window
import Mouse
-- Model
type Spoke = ((Float,Float), Color)
-- Update
curColor : Signal Color
@mgold
mgold / bitmapDraw.elm
Created August 27, 2013 01:54
An infinite grid of black and white pixels in your browser. Try the t, b, w, and c keys after clicking and dragging on this page: http://share-elm.com/gists/6348835/
-- Bitmap Draw by Max Goldstein
-- Change the cursor mode with the keyboard:
-- t Toggle (default)
-- b Black
-- w White
-- c Clear (automatically resets to Toggle afterwards)
import Mouse
import Keyboard
@mgold
mgold / spinner.elm
Created August 27, 2013 02:08
A spinning canvas on which you can paint. Try it: http://share-elm.com/gists/6348912
-- Spinner by Max Goldstein
import Mouse
import Window
import Dict (Dict, empty, toList, insert, findWithDefault)
import Automaton (Automaton, state, run)
import Graphics.Input (button)
-- MODEL
@mgold
mgold / IPAddr_union.rb
Created April 23, 2014 04:13
Find the smallest CIDR block that contains two IPAddrs, in Ruby.
require "ipaddr"
class IPAddr
# Returns the ipaddr representing the smallest CIDR block that includes both
# ipaddrs.
def union(other)
addr = @addr
coerced = coerce_other(other).to_i
prefixlen = self.ipv4? ? 32 : 128
while addr != coerced
@mgold
mgold / Viennese.elm
Created May 9, 2014 17:31
Viennese Maze
-- Viennese Maze Simulator, based on
-- http://zulko.github.io/blog/2014/04/27/viennese-mazes-what-they-are/
import Keyboard
import Window
import Graphics.Input as Input
-------------
-- Helpers --
-------------
@mgold
mgold / README.md
Created September 3, 2014 02:03
Testing d3.bullet

Testing each option to d3.bullet, taken from d3-plugins and slightly revised. This shows that all of the options still work, and some of them work in edge cases where they didn't before. Also shown are cases that do not yet work. This is not an automated test suite; determining success or failure must be done manually (optically).