Skip to content

Instantly share code, notes, and snippets.

@ityonemo
ityonemo / Hash.js
Created July 2, 2012 01:59
"Implementing" Hashes in Javascript
//Hash.js -- a cute little wrapper that is really great for turning data-only objects into something that
//javascript explictly calls a "Hash". Useful for cosmetically improving data structure representations
//in your favorite console. also great for making Javascript look like some of the more friendly scripting
//languages like Ruby. Possibly useless for anything else, and may make your code easier to read at the
//expense of speed and/or memory.
Hash = function(object)
{
if (object && (typeof object == 'object')) //do an initial type check to see if this can be hashified.
{ //if not, then you should return an empty hash {}.
@ityonemo
ityonemo / mayhem.js
Created July 28, 2012 00:16
Javascript mayhem
Function.prototype.__defineGetter__("head",function(){return this.toString().split("{")[0].trim();});
Function.prototype.__defineGetter__("body",function(){return this.toString().split("{").slice(1).join("{").slice(0,-1).trim();});
Function.prototype.__defineGetter__("args",function(){return this.toString().split("{")[0].match(/\([\w\s\,]*\)/)[0].slice(1,-1).split(",");});
Function.prototype.__defineGetter__("stmts",function()
{
var str = this.body;
var stmtlist = [];
var pcount = 0;
var lastpos = str.length - 1;
for (var i = str.length - 1; i >= 0; i--)
@ityonemo
ityonemo / torcmtx.cpp
Created January 8, 2013 07:02
converts a sparse matrix to a list of (row, column) vectors indicating which positions are occupado.
#include <octave/oct.h>
// SPECIAL FUNCTION THAT CONVERTS A SPARSE MATRIX
// TO A MATRIX THAT LISTS (ROW COLUMN) OF THE FILLED VALUES
DEFUN_DLD (torcmtx, args, nargout, "extracts edges of a sparse matrix to a list matrix")
{
int nargin = args.length();
if (nargin != 1)
print_usage (); //make sure we actually sent one value in.
@ityonemo
ityonemo / cmtxvars.cpp
Created January 13, 2013 00:35
generates a cell list of variational parameters for a sparse array. Useful for doing gradient descent on said array.
#include <octave/oct.h>
#include <octave/Cell.h>
// SPECIAL FUNCTION THAT CONVERTS A SPARSE MATRIX
// TO A MATRIX THAT LISTS (ROW COLUMN) OF THE FILLED VALUES
DEFUN_DLD (cmtxvars, args, nargout, "creates a cell matrix of variations on a sparse matrix")
{
int nargin = args.length();
if (nargin < 1)
@ityonemo
ityonemo / screw.scad
Created August 20, 2013 18:42
somewhat simple code for doing screws in openSCAD
//we're going to make a screw
//example values:
resolution = 200;
turns = 5;
height = 10;
deltathread = height / turns / 2;
trivial = 0.01;
for(i=[1:resolution]) {
@ityonemo
ityonemo / manifesto
Last active January 1, 2016 07:09
proposed gist of an open company "manifesto"
The Open Company Definition
===========================
(draft)
Introduction
------------
The Open company is a way of organizing collective human behavior, largely inspired by Eric S. Raymond's imperative
to take experiential knowledge from Open source software into 'other domains'. Open companies will implement
@ityonemo
ityonemo / LevyAlphaRand.jl
Last active August 29, 2015 13:57
A Levy Alpha Distribution Random Generator in Julia
module LevyAlphaRand
#a module that provides a levy alpha-stable random number in julia
#uses "McCulloch's algorithm", as provided in:
# Leccardi, M., Comparison of Three Algorithms for Levy Noise Generation
#
# Note two errors in the McCulloch formula as provided in this paper
# One: The phi and w values are swapped
# Two: The sin term should have an exponent of one, a fractional exponent would result in complex values
#include <stdio.h>
#include <string.h>
#include <stdint.h>
typedef uint8_t minifloat;
/*
minifloat variable: sign bit, then three bits of exponent, and four bits of
mantissa. Like the 1:4:3 minifloat, but instead with the exponent as the
least significant bits.
#include <stdio.h>
#include <string.h>
typedef struct {
signed int exp:4;
signed int val:4;
} minifloat;
float to_float(minifloat m){
/* generate a product accumulator */
#!/usr/bin/julia
#julia matrix test program.
v = rand(5)
m = rand(5,5)
r = zeros(5)
println("right product")
tic()