Skip to content

Instantly share code, notes, and snippets.

View azurite's full-sized avatar
:octocat:
Napping

Marko Nikic azurite

:octocat:
Napping
  • ETH Zürich
  • Switzerland
View GitHub Profile
package assignment13.stm;
import scala.concurrent.stm.Ref;
import scala.concurrent.stm.TArray;
import scala.concurrent.stm.japi.STM;
import java.util.concurrent.Callable;
/**
* This class implements a {@link assignment13.stm.CircularBuffer} using software-transactional memory (more
@azurite
azurite / curry_test.js
Created May 30, 2017 19:24
A small demonstrarion of a general curry function
function curry(fn) {
var slice = Array.prototype.slice;
var arity = fn.length;
var args = slice.call(arguments, 1);
function acc() {
var largs = args;
if (arguments.length > 0) {
largs = largs.concat(slice.call(arguments, 0));
@azurite
azurite / perm.js
Created May 18, 2017 21:34
Computes all n! permutations of an array with n items provided n < 13
/**
* Returns an array of all possible permutations of the given array provided the arrays length is smaller then 13
* @param {Array} arr The given array to compute it's permutations. Empty array if not specified.
* @returns {Array} an array of all the possible permutations of arr
*/
function perm(arr = []) {
if(arr.length > 12) {
// Javascript Array max length is 2^32 - 1 but 13! > 2^32 -1
throw new RangeError("perm() allowed max array length is 12");
}
@azurite
azurite / deepCopy.js
Last active March 11, 2017 18:57
Quick and dirty way to deep copy json objects in javascript (object prototypes are not copied)
function isNull(v) {
return typeof v === "object" && !v;
}
function isPrimitive(v) {
return ["number", "string", "boolean", "undefined"].indexOf(typeof v) !== -1 || isNull(v);
}
function isPlainObject(o) {
return o && typeof o === "object" && o.constructor === Object;