Skip to content

Instantly share code, notes, and snippets.

@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>
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()
@ityonemo
ityonemo / tablethis-xp.js
Created April 9, 2015 23:26
readable and marginally commented version of http://scripts.shpg.org/TableThis.js
var $$;
if(!Array.prototype.forEach){
Array.prototype.forEach = function(fun){
var len=this.length;
if(typeof fun!=="function"){
throw new TypeError();
}
var thisp = arguments[1];
@ityonemo
ityonemo / testing-stuff-from-the-book.jl
Created August 14, 2015 01:41
testing things from end of error
#test-things-from-the-book.jl
include("unum.jl")
using Unums
using Base.Test
#test various things from the book.
#are our representations of unums correct?
one16 = one(Uint16)
@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 / unum-constructor-proposal.jl
Created November 3, 2015 22:57
squaring the circle to make variadic unums have both sane construction and high performance
abstract Unum{ESS, FSS}
#define an outer constructor on this type.
type Unum_Small{ESS, FSS} <: Unum{ESS, FSS}
fsize::UInt16
esize::UInt16
flags::UInt16
fraction::UInt64
exponent::UInt64
@ityonemo
ityonemo / cleaninject.jl
Last active November 6, 2015 03:36
macros that cleanly Injecting code into a function's AST in julia
#cleaninject.jl
#cleanly injects some code into the AST of a function.
function code_to_inject()
println("this code is injected")
end
function code_to_inject(a,b)
println("injected code handles $a and $b")
using Base.Test
module X
macro id(v)
quote
$v
end
end
export @id
end