Skip to content

Instantly share code, notes, and snippets.

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

Eugene Cheltsov ChillyBwoy

🕶️
(ノ ˘_˘)ノ ζ|||ζ ζ|||ζ ζ|||ζ
View GitHub Profile
@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 / 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 / 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 / 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 / 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() {
const Y = h => (f => f(f))(f => h(n => f(f)(n)));
/* by steps */
// helpers
const recur = (f) => f(f);
const wrap = h => recur(f => h(n => f(f)(n)));
const fact0 = (n) => n < 2
? 1
@ChillyBwoy
ChillyBwoy / index.ts
Created November 24, 2017 23:36
Invert RGB color
const invertColor = (hex: string) => [
(x: string) => parseInt(x.substring(1), 16),
(x: number) => 0xFFFFFF ^ x,
(x: number) => `000000${x.toString(16)}`.slice(-6),
(x: string) => `#${x}`,
].reduce((acc, f: (...args: any[]) => any) => f(acc), hex);
@ChillyBwoy
ChillyBwoy / example.ts
Created December 6, 2017 13:17
Thunk-like middleware for redux and TypeScript 2.6 (without extra argument)
import * as Redux from "redux";
import { MiddlewareAction } from "./redux-middleware";
export interface StateType {
foo: string;
bar: number;
}
export type ActionType
= {
function factory() {
var count = 0;
return function() {
function fx() {
count += 1;
return fx;
}
fx.valueOf = function() {
@ChillyBwoy
ChillyBwoy / Person.css
Last active February 13, 2018 15:41
TypeScript React Sample
.root {
position: relative;
}
.isActive {
background: green;
}
.gender_male {
border: 1px solid #00f;