Skip to content

Instantly share code, notes, and snippets.

View ChillyBwoy's full-sized avatar
🕶️
(ノ ˘_˘)ノ ζ|||ζ ζ|||ζ ζ|||ζ

Eugene Cheltsov ChillyBwoy

🕶️
(ノ ˘_˘)ノ ζ|||ζ ζ|||ζ ζ|||ζ
  • 東京都
View GitHub Profile
@ChillyBwoy
ChillyBwoy / transducers.js
Last active March 30, 2017 16:02
Transducers JavaScript
class Reduced {
static isReduced(inst) {
return (inst instanceof Reduced);
}
constructor(wrapped) {
this._wrapped = wrapped;
}
unwrap() {
@ChillyBwoy
ChillyBwoy / demo.hs
Created March 29, 2017 14:53
Demo.hs
-- bar a b c = c + b - 2 * a
-- foo ... = bar ...
-- foo ... = ... bar ...
fib :: Integer -> Integer
fib n = fn n (0, 1)
where
fn 0 (a, b) = a
fn n (a, b) = fn (n - 1) (a + b, a)
@ChillyBwoy
ChillyBwoy / Grid.css
Last active March 28, 2017 23:02
Flex grid of: 'double', 'tripple', 'one-two', 'two-one'
$gridPadding: 7px;
@define-mixin padding-double $p {
&._padding-h {
&:nth-child(odd) { padding: 0 $p 0 0 }
&:nth-child(even) { padding: 0 0 0 $p }
}
&._padding-v {
padding: $p 0 $p 0;
@ChillyBwoy
ChillyBwoy / index.js
Last active August 8, 2016 12:31
Y-combinator
"use strict";
function recur (f) {
return f(f);
}
function wrap (h) {
return recur(function (f) {
return h(function (n) {
return f(f)(n);
@ChillyBwoy
ChillyBwoy / promisedQueue.js
Last active March 29, 2017 14:37
Promises Queue
function queue (operations, finished = []) {
let [curr, ...rest] = operations;
return !curr ? Promise.resolve(finished) : new Promise(resolve => {
curr()
.then(result => {
resolve(queue(rest, finished.concat(result)));
})
.catch(() => {
resolve(queue(rest, finished));
@ChillyBwoy
ChillyBwoy / fn.js
Last active March 29, 2017 14:38
fn with acc
function fibonacci (n) {
const fn = (n, a, b) => n === 0 ? a : fn(n - 1, a + b, a);
return fn(n, 0, 1);
};
function factorial (n) {
const fn = (n, acc) => n === 0 ? acc : fn(n - 1, n * acc);
return fn(n, 1);
}
@ChillyBwoy
ChillyBwoy / index.js
Created January 20, 2016 13:55
FizzBuzz
// with array. More more more faster
Array.apply(null, Array(100)).map((_, i) => {
var n = i + 1;
return (n % 3 === 0 && n % 5 === 0 ? 'FizzBuzz' :
(n % 3 === 0 ? 'Fizz' :
(n % 5 === 0 ? 'Buzz' : n)))
});
// with recursion
const fizzBuzz = (size, acc = []) => {
@ChillyBwoy
ChillyBwoy / fest.pegjs
Created October 20, 2015 10:51
peg.js rules for parsing fest-templates
start =
element
validchar = [0-9a-zA-Z\-_\{\}\.\:\/]
_ = [ \t\r\n]*
tagAttrs =
_ name:validchar+ '="' value:validchar+ '"' _ {
@ChillyBwoy
ChillyBwoy / multimethod.js
Last active March 29, 2017 14:47
Multimethod in js
function multi(pred) {
const methods = new Map();
const fn = (...args) => {
const f = methods.get(pred(...args));
return f ? f(...args) : null;
};
fn.method = (predKey, methodFn) => {
methods.set(predKey, methodFn);
@ChillyBwoy
ChillyBwoy / readme.md
Last active August 1, 2017 19:26
IIFE Parentheses

If you don't care about the return value of the IIFE, it could also be any of the following:

!function(){}();  // => true
~function(){}(); // => -1
+function(){}(); // => NaN
-function(){}();  // => NaN

Let's explore this a bit more.