Skip to content

Instantly share code, notes, and snippets.

View binarymax's full-sized avatar
👻
for(;1;){work();eat();rest();}

Max Irwin binarymax

👻
for(;1;){work();eat();rest();}
View GitHub Profile
@binarymax
binarymax / GUID.js
Created April 5, 2015 20:05
8 char GUID
//Easy 8 char Base-36 GUID
var GUID = function() {
var char = function(){return Math.floor(Math.random()*36).toString('36')};
return char() + char() + char() + ((new Date())-0).toString('36').substr(3);
};
@binarymax
binarymax / keybase.md
Created March 19, 2015 22:37
keybase.md

Keybase proof

I hereby claim:

  • I am binarymax on github.
  • I am binarymax (https://keybase.io/binarymax) on keybase.
  • I have a public key whose fingerprint is F29D 3138 8A07 0E93 3EB1 0FF6 3231 DE37 8B23 41B5

To claim this, I am signing this object:

@binarymax
binarymax / Bitmap.js
Last active October 24, 2023 11:08
Javascript bitmap data structure
//------------------------------------------
//Compact bitmap datastructure
//Memory efficient array of bool flags
var Bitmap = function(size){
this._cols = 8;
this._shift = 3;
this._rows = (size>>this._shift)+1;
this._buf = new ArrayBuffer(this._rows);
this._bin = new Uint8Array(this._buf);
};
@binarymax
binarymax / CraftyChess.txt
Last active November 29, 2015 22:00
Compile Crafty Chess on Mac OSX
Compiling crafty chess on MacOS, you get the following error:
-------------------------------------------------------------
~/apps/crafty/crafty-23.4:$ make darwin
/Applications/Xcode.app/Contents/Developer/usr/bin/make target=FreeBSD \
CC=gcc CXX=g++ \
CFLAGS='-Wall -pipe -O3' \
CXFLAGS='-Wall -pipe -O3' \
LDFLAGS= \
LIBS='-lstdc++' \
opt='' \
/*
2D ARRAY
0 1 2 3 4 (x)
0 [ ][ ][ ][ ][ ]
1 [ ][ ][#][ ][ ]
2 [ ][ ][ ][ ][ ]
3 [ ][ ][ ][ ][ ]
4 [ ][ ][ ][ ][ ]
@binarymax
binarymax / elosim.js
Last active December 24, 2015 19:59
Elo rating simulation
/*********************************
*
* Elo Rating Simulation
* Copyright (c) 2013, Max Irwin
* MIT License
*
*********************************/
(function(){
var players = [];
@binarymax
binarymax / parseCIDRRange.js
Last active July 30, 2021 11:03
JavaScript function to parse a CIDR Range string into beginning and ending IPv4 Addresses
//MIT License
//Copyright (c) 2013, Max Irwin
//Parses a CIDR Range into beginning and ending IPv4 Addresses
//For example: '10.0.0.0/24'
//Returns ['10.0.0.0', '10.0.0.255']
var parseCIDR = function(CIDR) {
//Beginning IP address
var beg = CIDR.substr(CIDR,CIDR.indexOf('/'));
@binarymax
binarymax / gist:5039967
Created February 26, 2013 16:41
Workaround for toDataURL >2MB
//From https://code.google.com/p/chromium/issues/detail?id=69227#c37
//take apart data URL
var parts = canvas.toDataURL().match(/data:([^;]*)(;base64)?,([0-9A-Za-z+/]+)/);
//assume base64 encoding
var binStr = atob(parts[3]);
//convert to binary in ArrayBuffer
var buf = new ArrayBuffer(binStr.length);
@binarymax
binarymax / canvasfloodfill.js
Created November 14, 2012 12:36
Javascript Canvas FloodFill functions
//MIT License
//Author: Max Irwin, 2011
//Floodfill functions
function floodfill(x,y,fillcolor,ctx,width,height,tolerance) {
var img = ctx.getImageData(0,0,width,height);
var data = img.data;
var length = data.length;
var Q = [];
var i = (x+y*width)*4;
@binarymax
binarymax / fib_scale.js
Created December 30, 2011 14:53
Scales the fibonacci sequence
#!/usr/bin/env node
(function() {
var rnd = function(x) { return Math.round(x*10)/10; };
var tbl = function(a) {
var b=[];
for(var i=0,l=a.length;i<l;i++) {
var n=a[i].toString();
for(var j=0, s=" "; j<(5-n.length);j++) {