Skip to content

Instantly share code, notes, and snippets.

View nat-n's full-sized avatar

Nat Noordanus nat-n

View GitHub Profile
@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())
@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 / 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 / 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 / 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 / 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 / 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 / mlv_merge.py
Last active December 14, 2015 19:49
These python modules provide functions for dealing with multi label volumetric images (such as anatomical atlases) in .nii format or any similar format compatible with nibabel. Both can also be used as command line tools. mlv_merge.py takes a directory of single-label or multilabel volumetric image files and creates a new nifiti multi-label imag…
#!/usr/bin/env python
import os
import sys
import argparse
import collections
import numpy
import nibabel as nib
@nat-n
nat-n / convert3d.rb
Last active December 16, 2015 10:29
A very light wrapper for the InsightToolkit Convert3D tool which must be downloaded seperately. See http://www.itksnap.org/pmwiki/pmwiki.php?n=Convert3D.Convert3D . It is assumed that the Convert3D tool resides in the shall path as c3d. Otherwise Convert3D.path= must be used to set the location of the executable.
# A very light wrapper for the InsightToolkit Convert3D tool which must be downloaded seperately.
# See http://www.itksnap.org/pmwiki/pmwiki.php?n=Convert3D.Convert3D
# It is assumed that the Convert3D tool resides in the shall path as c3d.
# Otherwise Convert3D.path= must be used to set the location of the executable.
module Convert3D
@@c3d_path = "c3d" # assume c3d is in the environment path by default
@@Formats = [".nrrd", ".hdr", ".img", ".img.gz", ".dcm", ".cub", ".mha", ".df3", ".nii.gz"]
def self.path= path
# Provides an efficiently searchable tree index of a given array of stringafiable objects.
# Is specifically designed to be much faster than using Array's _index_ or _include?_ methods for locating a numerical value within an Array.
# However it should work just as well with Arrays of strings or other objects that respond appropriately to _to_s_.
class QuickIndex
# @param ary [Array] of items to be indexed.
# @param stop_char (String) which should not occur as a substring in any of the stringified objects in ary.
#