Skip to content

Instantly share code, notes, and snippets.

View mindoftea's full-sized avatar

Emory Hufbauer mindoftea

View GitHub Profile
@mindoftea
mindoftea / fastArray.js
Last active August 29, 2015 14:01
A fast homogenous JavaScript array generator. Given some string, it generates an array of arbitrary length containing that string repeated. It uses binary concatenation and string addition to achieve its speed.
var generateArray=function(x,n)
{
var s,y,z;
s="";
if(x.length>1)
{
s="|";
}
x+=s;
y="";
@mindoftea
mindoftea / pointChecker.js
Created May 10, 2014 05:50
A javascript function which uses a map to efficiently search for nearby points distributed across a one-dimensional field. There is quite a high up-front cost to initializing the map, but, once that is done, each point-finding operation is extremely cheap.
var CheckPoints=function(list, spaceSize, scanSize)
{
var n,m,map;
list.sort(
function(a,b)
{
return -(a.x<b.x)+(a.x>b.x);
}
);
map={};
@mindoftea
mindoftea / seededRand.js
Created May 10, 2014 05:53
A simple seeded pseudo-random number generator implemented in JavaScript using the Blum Blum Shub method.
var SeededRand = function(seed, mod1, mod2)
{
return function()
{
seed = (seed*seed) % (mod1*mod2);
return seed/(mod1*mod2);
};
};
var rand = SeededRand(seed, mod1, mod2);
@mindoftea
mindoftea / elGamal.js
Created May 10, 2014 06:04
An implementation of the ElGamal encryption system in JavaScript.
var Alphabet = "!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~ 𮃩∆";
Alphabet = Alphabet.split("");
var Crypto = function (alpha, gen, C) {
var p, B, encrypt, decrypt, f, g, modInv, modPow, toAlpha, to10;
toAlpha = function (x) {
var y, p, l, n;
if (x === 0) {
return "!!!!";
@mindoftea
mindoftea / fastFibonacci.js
Created May 10, 2014 06:08
A recursive, caching JavaScript implementation of the famous Fibonacci function. Each time you call it, it gets faster.
var fibonacci=function()
{
var x=[0,1];
return function(n)
{
if(x[n]!==undefined)
{
return x[n];
}
else
@mindoftea
mindoftea / curryProduct.js
Last active August 29, 2015 14:01
A demonstration of some of the power of closures when used for currying in JavaScript.
var f=function(x)
{
var g=function(y)
{
x*=y;
print(x);
return g;
};
return g;
};
@mindoftea
mindoftea / chooser.js
Created June 21, 2014 15:03
A node.js program that helps users sort a list based on subjective criteria.
"use strict";
var Prompt=require('prompt');
Prompt.start();
var LOW={};
var HIGH={};
var sortedList=[LOW,HIGH];
var unSortedList=[
@mindoftea
mindoftea / bluetoothLagTest
Created June 21, 2014 22:09
Node-bluetooth-serial-port writing lag test case. Writing consistently takes 250ms to complete on OSX.
"use strict";
var bluetooth=require('bluetooth-serial-port');
bluetooth=new bluetooth.BluetoothSerialPort();
var write=function()
{
var timeStamp;
console.log("sending...");
timeStamp=Date.now();
const arraySize = 1e3;
const trialSize = 1e6;
const a = [];
let i = arraySize;
while (i--) {
a[i] = i;
}
const t = [];
const x = a.slice();
import Data.Bits
import Data.List
import Data.List.Split
import qualified Data.Map as Map
import Data.Maybe
-- Abstract operation type
data Operation = Operation {
compute :: [Integer] -> Integer,
symbol :: String