Skip to content

Instantly share code, notes, and snippets.

View jochemstoel's full-sized avatar
💭
Dematerializing

Jochem Stoel jochemstoel

💭
Dematerializing
View GitHub Profile
@jochemstoel
jochemstoel / JSON.replacer.js
Created January 30, 2019 22:35 — forked from dmitrythaler/JSON.replacer.js
replacer function for the JSON.stringify() with depth and duplicates control
const replacer = function( depth = Number.MAX_SAFE_INTEGER ) {
let objects, stack, keys;
return function(key, value) {
// very first iteration
if (key === '') {
keys = ['root'];
objects = [{keys: 'root', value: value}];
stack = [];
return value;
}
@jochemstoel
jochemstoel / native jQuery methods.js
Last active November 9, 2023 15:53
Vanilla implementations of commonly used jQuery methods.
/**
* Convenient shortcut
*/
Object.defineProperty(window, 'define', {
value: (property, ...meta) => meta.length == 2 ? Object.defineProperty(meta[0], property, meta[1]) : Object.defineProperty(window, property, meta[0]),
writable: false,
enumerable: true
})
@jochemstoel
jochemstoel / string-utils.js
Created December 3, 2018 14:43 — forked from jonlabelle/string-utils.js
Useful collection of JavaScript string utilities.
// String utils
//
// resources:
// -- mout, https://github.com/mout/mout/tree/master/src/string
/**
* "Safer" String.toLowerCase()
*/
function lowerCase(str){
return str.toLowerCase();
@jochemstoel
jochemstoel / unCamelCase.js
Created December 3, 2018 14:41 — forked from mattwiebe/unCamelCase.js
unCamelCase.js
/**
* Turns someCrazyName into Some Crazy Name
* Decent job of acroynyms:
* ABCAcryonym => ABC Acryoynm
* xmlHTTPRequest => Xml HTTP Request
*/
String.prototype.unCamelCase = function(){
return this
// insert a space between lower & upper
.replace(/([a-z])([A-Z])/g, '$1 $2')
@jochemstoel
jochemstoel / ffmpeg-compress-mp4
Created November 19, 2018 13:01 — forked from lukehedger/ffmpeg-compress-mp4
Compress mp4 using FFMPEG
$ ffmpeg -i input.mp4 -vcodec h264 -acodec mp2 output.mp4
@jochemstoel
jochemstoel / ISO-639-1-language.json
Created November 2, 2018 20:13 — forked from jrnk/ISO-639-1-language.json
ISO 639-1 Alpha-2 codes of languages JSON
[
{
"code": "ab",
"name": "Abkhaz"
},
{
"code": "aa",
"name": "Afar"
},
{
// Loads js files
function loadScripts(urlArray,cb) {
var scriptLoadCount = scriptLoadedCount = 0;
loadScript();
function loadScript() {
var head= document.getElementsByTagName('head')[0];
var script= document.createElement('script');
script.type= 'text/javascript';
var url = (urlArray[scriptLoadCount].indexOf('?') == -1) ? urlArray[scriptLoadCount] + '?d=' + Math.random() : urlArray[scriptLoadCount] + '&d=' + Math.random()
@jochemstoel
jochemstoel / Note to Frequency
Created October 25, 2018 16:18 — forked from stuartmemo/Note to Frequency
Convert note to frequency
// Takes string of Note + Octave
// Example:
// var frequency = getFrequency('C3');
var getFrequency = function (note) {
var notes = ['A', 'A#', 'B', 'C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', 'G#'],
octave,
keyNumber;
if (note.length === 3) {
@jochemstoel
jochemstoel / node-walk.js
Created October 1, 2018 11:18 — forked from lovasoa/node-walk.es6
Walk through a directory recursively in node.js.
var fs = require("fs"),
path = require("path");
function walk(dir, callback) {
fs.readdir(dir, function(err, files) {
if (err) throw err;
files.forEach(function(file) {
var filepath = path.join(dir, file);
fs.stat(filepath, function(err,stats) {
if (stats.isDirectory()) {
@jochemstoel
jochemstoel / unless.js
Created September 27, 2018 00:20 — forked from samihda/unless.js
JavaScript unless macro with sweet.js
syntax unless = function (ctx) {
let test = ctx.next().value;
let body = ctx.next().value;
return #`if (!${test}) ${body}`;
}
var answer = 0;
unless (answer === 42) {