Skip to content

Instantly share code, notes, and snippets.

@idettman
idettman / util.js
Last active November 25, 2017 02:40
es6 utils
/**
* @param obj {Object}
* @returns {string} Object's type {string} value
*/
export function getType (obj) {
return Object.prototype.toString.call(obj);
};
/**
* @param {string} url
@idettman
idettman / es6-util.js
Created January 31, 2017 02:20
ES6 utils
'use strict';
/**
* @param obj {Object}
* @returns {string} Object's type {string} value
*/
function getType (obj) {
return Object.prototype.toString.call(obj);
};
@idettman
idettman / es-event-sandbox.js
Last active January 31, 2017 02:23
event sandbox
setTimeout(function ()
{
let element = document.createElement('div');
element.textContent = 'subtree modification test';
document.body.appendChild(element);
console.log('setTimeout exit');
}, 1000);
@idettman
idettman / es6-util.js
Created January 31, 2017 21:20
ES6 Utils - Includes GC optimized event system
'use strict';
/**
* @param obj {Object}
* @returns {string} Object's type {string} value
*/
function getType (obj) {
return Object.prototype.toString.call(obj);
};
@idettman
idettman / es6-optimized-event-system.js
Last active February 1, 2017 16:19
ES6 Optimized Event System
'use strict';
/**
* @param obj {Object}
* @returns {string} Object's type {string} value
*/
function getType (obj) {
return Object.prototype.toString.call(obj);
};
@idettman
idettman / simple.js
Created February 3, 2017 16:18 — forked from philogb/simple.js
window.addEventListener('DOMContentLoaded', function() {
//check support
if (!supportsWebGL()) {
$('webgl-canvas').innerHTML = 'Your browser doesn\'t seem to support WebGL. More info <a href=\'http://get.webgl.org/\'>here</a>.';
return;
}
//get context
var canvas = $('webgl-canvas'),
gl = getWebGLContext(canvas);
@idettman
idettman / functional-css-rule-generation.js
Last active September 5, 2025 22:05
Prototype to create css rules using functional concepts
'use strict';
/**
* @param {Function} a - Function is called using the result of 'b' as the argument
* @param {Function} b - Function 'b' is executed first with the callback arguments; the result is passed to 'a'
* @returns {*}
*/
function compose (a, b)
{
return (...args) => a(b(...args));
@idettman
idettman / curry-examples.js
Last active November 25, 2017 19:37
JavaScript curry examples using Ramda and ES6
const eventHandler = message => event => {
alert(message, event.target.id);
}
// <button id="button1" onClick="eventHandler('hello from')">click</button>
// Ramda
const requestWithOpts = R.curry((protocol, hostname, port) =>
protocol + '://' + hostname + (port === 80 ? '' : ':' + port)
@idettman
idettman / named-curry.js
Created February 19, 2017 02:13
JavaScript Named Curry
function namedCurry(source_fn, arg_order){
function receiver( received_values, n_received, defaults ){
received_values = (received_values || []).slice()
n_received = n_received || 0
Object.keys(defaults).forEach(function( input_arg ){
var value = defaults[ input_arg ]
var required_index = arg_order.indexOf( input_arg )
var is_known_argument = required_index > -1
@idettman
idettman / namedCurry.js
Created February 19, 2017 02:15 — forked from CrossEye/namedCurry.js
Named Curry
var R = require('./ramda');
// Discussion at https://github.com/ramda/ramda/issues/1258
var namedCurry = function(fn, argNames) {
// TODO: what if fn.length != argNames.length?
var f = R.curryN(fn.length, function() {
return fn.apply(this, arguments);
});
f['secret-sauce'] = {