Skip to content

Instantly share code, notes, and snippets.

var cartesian = (function(range) {
return {
'inX': inX,
'outX': outX,
'inY': inY,
'outY': outY
};
function inX(value) {
import os, sys, math
def _min(a, b):
signA = a < 0
signB = b < 0
branch1 = signA & (~signB & 1) # branch1 = (signA && !signB)
branch2 = signB & (~signA & 1) # branch2 = (signB && !signA)
notBranched = (~branch1) & (~branch2) & 1 # notBranched = (!branch1 && !branch2)
branch3 = notBranched & ((a - b) >> 31 & 1) # branch3 = (notBranched && a < b)
/**
* @param key
* @param additionalParameters
* @return promise
**/
function MyCacheSetter(key, params) {
return $http.post('some_url', {
someField: params.someValue
});
/**
* Compile with:
* clang -Wall -Werror -std=c99 -g IntegerToEnglish.c -o IntegerToEnglish
*
* OR
* gcc -Wall -Werror -std=c99 -g IntegerToEnglish.c -o IntegerToEnglish
*
**/
@cleure
cleure / factory.js
Last active August 29, 2015 14:04
Factory, to expose a class as AMD, CommonJS, and browser window
(function(factory) {
var module = factory();
// AMD
if (typeof define === 'function' && define.amd) {
define(function() { return module; });
}
// CommonJS
if (typeof exports === 'object') {
(function() {
var API = 'crypto2',
METHOD = 'getRandomValues';
var maxValueLookup = {
'[object Uint8Array]': 0xff,
'[object Uint8ClampedArray]': 0xff,
'[object Uint16Array]': 0xffff,
'[object Uint32Array]': 0xffffffff
/**
* A Queue, implemented as two stacks.
*
* Push has a worst case of O(1)
* Pop has a worst case of O(N), and a best case of O(1)
*
**/
function Queue() {
this.clear();
@cleure
cleure / min_max.c
Last active January 4, 2024 22:21
Branchless Min/Max
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <assert.h>
#include <math.h>
int32_t min_int32(int32_t a, int32_t b)
{
uint32_t branch1,
branch2,
from math import *
def _expand_args_float(func):
def wrapper(*args):
return func(*([float(i) for i in args]))
return wrapper
@_expand_args_float
def easeInQuad(t, b, c, d):
t /= d
function getUrlParams(url) {
return (url.replace(/.*\/[^/?]+(?=\?|$)/, '').replace(/^\?/, ''))
.split('&')
.map(function(kvPair) {
return kvPair.split('=').map(decodeURIComponent);
}).reduce(function(objToReturn, item) {
objToReturn[item[0]] = item[1];
return objToReturn;
}, {});
}