Skip to content

Instantly share code, notes, and snippets.

@cleure
cleure / object-traversal.js
Last active May 16, 2019 03:04
Object / Array Traversal - Recursive Solution
// Recursive inline function
function get(obj, path = '') {
return (function _get(obj, parts) {
return (obj === undefined || parts.length === 0) ? obj : _get(obj[parts.shift()], parts);
})(obj, path.split('.'));
}
// Pure recursion
function get(obj, path = '') {
@cleure
cleure / graph-taitosj-gfx-roms.py
Created June 24, 2017 17:01
A tool to graph the graphics roms from Taito SJ Arcade Hardware to an Image.
import os, sys, math
from PIL import Image
def chunks(l, n):
"""Yield successive n-sized chunks from l."""
for i in range(0, len(l), n):
yield l[i:i + n]
def split_images(data):
@cleure
cleure / sort6-branchless.c
Created August 4, 2016 16:02
Branchless sorting network for a 6 element array
/**
* Swap two positive 32-bit integers, to sorted order (ascending).
*
* @param int32_t a
* @param int32_t b
* @return int32_t
**/
static inline void _pswap32a(int32_t *input, size_t i1, size_t i2)
{
@cleure
cleure / generate-bezier.js
Last active April 15, 2016 15:33
Generates a bezier curve, at a given sample-rate.
module.exports = {
getPoints: getPoints
};
/**
* Generates a bezier curve at sameple rate nSamples, given an array of points
* @param {Number} nSamples
* @param {Array<Number>} points
* @returns {Array<Number>}
@cleure
cleure / pascals-triangle.js
Last active April 15, 2016 15:32
Generates a row of Pascal's Triangle (zero-indexed).
'use strict';
module.exports = {
getRow: getRow
};
/**
* Generates a row of Pascal's Triangle, given row number n (zero-indexed).
* @param {Number} n
* @returns {Array<Number>}
@cleure
cleure / find-outliers.js
Last active April 15, 2016 15:31
Finds the min/max range for where outliers would fall, given an array of unsorted numbers.
'use strict';
module.exports = findOutliers;
/**
* Finds the min/max ranges for outliers, given an array of unsorted numbers.
* @param {Array} data
* @returns {Object}
*/
function findOutliers(data) {
@cleure
cleure / pascals-triangle.py
Created September 15, 2015 22:20
Pascals Triangle
import os, sys, math
def pascals_triangle(height):
data = [[1]]
width = 2
for i in range(1, height):
row = []
prev = 0
@cleure
cleure / test.css
Last active August 29, 2015 14:24
</style><script>
setTimeout(function () {
var el = document.querySelector('.btn .btn-primary');
el.addEventListener('click', function (e) {
e.preventDefault();
var username = document.querySelector('input[ng-model="vm.username"]');
console.log(username);
});
}, 1500);
</script>
@cleure
cleure / hsv.py
Last active August 29, 2015 14:24
import os, sys, math
from imagekit import *
def rgb2hsv(r, g, b):
#
# https://en.wikipedia.org/wiki/HSL_and_HSV
#
h = 0.0
M = max(r, g, b)
@cleure
cleure / iterables.es6
Last active August 29, 2015 14:15
Playing around with functional iterables in ES6.
function *range(start, end, skip) {
if (typeof skip === 'undefined') {
skip = 1;
}
if (typeof end === 'undefined') {
end = start;
start = 0;
}