Skip to content

Instantly share code, notes, and snippets.

@mgold
mgold / sine_animation.elm
Created September 17, 2015 19:59
Sine animation (Elm 0.15.1)
import Graphics.Collage exposing (..)
import Color exposing (rgb)
import Window
import Time
obj_resolution = 360
waves_amount=6
wave_height=0.1
sine_pct=0.5 -- setting in percantage how big is the part
smoothing_amount=0.14
@mgold
mgold / README.md
Last active September 18, 2015 14:30
The 2-adic Numbers

This block is an animation of forming the 2-adic numbers in a fractal-like process. Starting with zero and one, we alternate two steps. First, we visually scale down the existing plot, which doesn't actually change anything. Then, we subdivide each number. The left half stays the same, and to the right half we add an increasing power of two, one more than the previously largest number in the list.

The 2-adic distance metric, which is shift invariant, considers numbers to be closer if they were formed by a more recent subdivision, which is shown visually as similar colors. Analytically, two numbers are close if their difference is divisible by a high power of two. So while 16 is close to 0, 32 is closer, and 64 is closer still.

The integers expand to the right of the number line (or the left of the numeral). But the 2-adics expand into themselves: each subdivision grows in the same space that was once zero to one. These numbers dart back and forth in a contained space; you can hold infinity in the palm of

@mgold
mgold / README.md
Created October 9, 2015 20:25
Dice roll probabilities
@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 / 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