Skip to content

Instantly share code, notes, and snippets.

View kl0tl's full-sized avatar

Cyril Sobierajewicz kl0tl

View GitHub Profile
@kl0tl
kl0tl / es7-decorators
Created March 18, 2015 16:12
Some fun with the hypothetical ES7 decorators notation (`@xxx`)
class Class {
@Bound
method() {}
@Lazy
get data() {}
}
function Bound(prototype, name, descriptor) {
const { value, writable, enumerable, configurable } = descriptor;
@kl0tl
kl0tl / async.js
Created December 14, 2014 17:11
ES7 async functions with ES6 generators and promises
/*
ES7
```
async function f() {
await ...
}
```
@kl0tl
kl0tl / main.js
Last active June 6, 2021 11:20
DOM diffing inside a `Worker` with `virtual-dom`
var VDOMWorkerRenderer = require('./vdom-worker-renderer');
var renderer = new VDOMWorkerRenderer(function (h) {
return function ui(state) {
return counter(state.counter)
};
function counter(value) {
return h('div', { className: 'counter' }, [String(value)]);
}
@kl0tl
kl0tl / transducers.js
Last active August 29, 2015 14:06
Transducers are awesome
var foldr = Function.prototype.call.bind(Array.prototype.reduceRight);
var source = [9, 8, 7];
var pipeline = compose(filter(odd), map(add(1)));
var pusher = {
step: function (arr, value) { arr.push(value); return arr; },
result: identity
};
context.f(...args)
f.call(context, ...args)
Function.prototype.call.bind(f)(context, ...args)
Function.prototype.bind.bind(Function.prototype.call)(f)(context, ...args)
@kl0tl
kl0tl / pi.macro.sjs
Created June 29, 2014 16:53
`Math.PI` shorthand
macro π {
rule {} => { Math.PI }
}
export π;
@kl0tl
kl0tl / findIndex.macro.sjs
Last active August 29, 2015 14:03
Inline `Array#findIndex`
macro inline_findIndex {
rule { ($list:expr, function ($value:ident, $index:ident, $ref:ident) {
$return:expr
}, $context:expr) } => {
(function ($ref) {
var length = $ref.length;
for (var $index = 0; $index < length; $index += 1) {
var $value = $ref[$index];
@kl0tl
kl0tl / find.macro.sjs
Last active August 29, 2015 14:03
Inline `Array#find`
macro inline_find {
rule { ($list:expr, function ($value:ident, $index:ident, $ref:ident) {
$return:expression
}, $context:expr) } => {
(function ($ref) {
var length = $ref.length;
for (var $index = 0; $index < length; $index += 1) {
var $value = $ref[$index];
@kl0tl
kl0tl / from.macro.sjs
Created June 29, 2014 16:44
Inline `Array.from`
macro inline_from {
rule { ($constructor:expr, $list:expr, function ($value:ident, $index:ident, $ref:ident) {
$return:expr
}, $context:expr) } => {
(function (constructor, ref) {
var length = ref.length, res = new constructor(length);
for (var $index = 0; $index < length; $index += 1) {
var $value = ref[$index];