Skip to content

Instantly share code, notes, and snippets.

View nat-n's full-sized avatar
🏠
Working from home

Nat Noordanus nat-n

🏠
Working from home
View GitHub Profile
@nat-n
nat-n / find_in_pi.rb
Created October 20, 2012 12:50
Command line executable which searches for the first occurence of a given string in PI, in the form of an ascii base10 string.
#!/usr/bin/env ruby
# encoding: utf-8
#
# Created by Nat Noordanus on 2012-10-20.
#
# requires a text file of digits of pi http://stuff.mit.edu/afs/sipb/contrib/pi/pi-billion.txt
def find_in_pi string, pi_file_path
# convert string to base 10 ascii
@nat-n
nat-n / Monadik_Async_Chain.coffee
Created September 3, 2012 14:48
In the smallest possible Coffeescript code, chain an array of async callbacks to "thread" their evaluation order. Inspired from Haskell
# Construct a chained array of callbacks that "thread" a sequence of async functions in the smallest possible code.
# tldr; call the next async function in fn, "wait" for its callback to store the result and call the next async callback in cb
# each async function
# accepts 1 callback argument
# passes 1 arg of result data to the callback
# construct the callback
# when callback in cb evaluates, replaces itself in cb array with the result
# calls the next callback in cb
# after last callback in cb, return joined results stored in cb
@nat-n
nat-n / action_helper.js.coffee
Created June 11, 2012 12:41
largest circle fitting onto jax picking regions with debugging visualisation, also uses Raphael and https://github.com/gorhill/Javascript-Voronoi
Jax.getGlobal().ApplicationHelper = Jax.Helper.create
patch_world: ->
Jax.World.prototype.find_region_centers = () ->
context = this.context
w = context.canvas.width
h = context.canvas.height
f = 4
wf = w*f
data = new Uint8Array(w*h*4)
pickBuffer = new Jax.Framebuffer
@nat-n
nat-n / application_helper.js.coffee
Created May 25, 2012 10:53
attempt to patch Jax.World
Jax.getGlobal().ApplicationHelper = Jax.Helper.create
patch_world: ->
Jax.World.prototype.pick_all_visible = () ->
context = this.context
w = context.canvas.width
h = context.canvas.height
data = new Uint8Array(w*h*4)
data.w = w
data.h = h
data.f = f = 4
@nat-n
nat-n / mybsp_controller.js.coffee
Created February 12, 2012 21:26
Jax controller trying to use the coldet plugin
Jax.Controller.create "Mybsp", ApplicationController,
index: ->
sphere = new Jax.Mesh.Sphere
this.ball1 = new Jax.Model({ mesh:sphere })
this.ball2 = new Jax.Model({ mesh:sphere, position:[0,5,0] })
this.ball1.bsp = new BSP
this.ball2.bsp = new BSP
@nat-n
nat-n / async_helper.js.coffee
Created December 8, 2011 21:54
A JaxGL Helper used by gist:1448410 to load and display a model from ajax and/or indexedDB
Jax.getGlobal().AsyncHelper = Jax.Helper.create
load_from_idb: (idb_name, os_name, key, onsuccess, onfailure) ->
indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB
IDBTransaction = IDBTransaction || window.webkitIDBTransaction
IDBKeyRange = IDBKeyRange || window.webkitIDBKeyRange
idb_request = indexedDB.open @indexedDB
idb_request.onsuccess = (e) =>
idb = e.target.result
if idb.objectStoreNames.contains @objectStore
@nat-n
nat-n / loadedmesh.js.coffee
Created December 8, 2011 20:26
A JaxGL Model file which uses AsyncHelper.js.coffee (gist: 1448794) to load and display a model from ajax and/or indexedDB
Jax.getGlobal()['LoadedMesh'] = Jax.Model.create
after_initialize: ->
model_data = null
@mesh = new Jax.Mesh
init: (vertices, colors, texCoords, normals, indices) ->
if model_data
vertices.push datum for datum in model_data["vertices"][0]["values"]
normals.push datum for datum in model_data["vertices"][1]["values"]
indices.push datum for datum in model_data["connectivity"][0]["indices"]
update: ((updated_mesh) => model_data = updated_mesh; @mesh.rebuild())