Skip to content

Instantly share code, notes, and snippets.

function getNames(xs) {
let idx = 0
let result = []
while (idx < xs.length) {
result[idx] = xs[idx].name
idx = idx + 1
}
return result
}
@alexeygolev
alexeygolev / people.js
Created July 29, 2016 21:59
simple-people
const people = [
{ name: 'John', surname: 'Garry' },
{ name: 'Bambi', surname: 'Pinkman' },
{ name: 'Gina', surname: 'JustGina' },
]
function toHexs(xs) {
let idx = 0
let result = []
while (idx < xs.length) {
result[idx] = xs[idx].toString(16)
idx = idx + 1
}
return result
}
function toStrings(xs) {
let idx = 0
let result = []
while (idx < xs.length) {
result[idx] = xs[idx].toString()
idx = idx + 1
}
return result
}
@alexeygolev
alexeygolev / add1.js
Last active July 29, 2016 21:57
simple add
function add1(xs) {
let idx = 0
let result = []
while (idx < xs.length) {
result[idx] = xs[idx] + 1
idx = idx + 1
}
return result
}
@alexeygolev
alexeygolev / convert.js
Last active May 17, 2016 09:10
convertFromHtml in node
const jsdom = require('jsdom').jsdom
const fs = require('fs')
const path = require('path')
const {
ContentState,
convertToRaw,
convertFromRaw,
} = require('draft-js')
const React = fs.readFileSync(path.join(__dirname, '../node_modules/react/dist/react.js'))
@alexeygolev
alexeygolev / compose.js.flow
Created May 9, 2016 23:16
flowtype compose
type ComposeFn<V0,V1,V2,T1,T2,T3,T4,T5,T6> =
& ( <V0,V1,V2,T1,T2,T3,T4,T5,T6>( fn5:(x: T5) => T6, fn4: (x: T4) => T5, fn3: (x: T3) => T4, fn2: (x: T2) => T3, fn1: (x: T1) => T2, fn0: (x0: V0, x1: V1, x2: V2) => T1, $?: null) => (x0: V0, x1: V1, x2: V2) => T6 )
& ( <V0,V1,T1,T2,T3,T4,T5,T6>( fn5:(x: T5) => T6, fn4: (x: T4) => T5, fn3: (x: T3) => T4, fn2: (x: T2) => T3, fn1: (x: T1) => T2, fn0: (x0: V0, x1: V1) => T1, $?: null) => (x0: V0, x1: V1) => T6 )
& ( <V0,T1,T2,T3,T4,T5,T6>( fn5:(x: T5) => T6, fn4: (x: T4) => T5, fn3: (x: T3) => T4, fn2: (x: T2) => T3, fn1: (x: T1) => T2, fn0: (x0: V0) => T1, $?: null) => (x0: V0) => T6 )
& ( <V0,V1,V2,T1,T2,T3,T4,T5>( fn4: (x: T4) => T5, fn3: (x: T3) => T4, fn2: (x: T2) => T3, fn1: (x: T1) => T2, fn0: (x0: V0, x1: V1, x2: V2) => T1, $?: null) => (x0: V0, x1: V1, x2: V2) => T5 )
& ( <V0,V1,T1,T2,T3,T4,T5>( fn4: (x: T4) => T5, fn3: (x: T3) => T4, fn2: (x: T2) => T3, fn1: (x: T1) => T2, fn0: (x0: V0, x1: V1) => T1, $?: null) => (x0: V0, x1: V1) => T5 )
& ( <V0,T1,T2,T3,T4
@alexeygolev
alexeygolev / _record-syntax.js
Last active August 29, 2015 14:26
Extra stuff for union types
const Color = Type({RGB:[Number, Number, Number], CMYK:[Number, Number, Number, Number]});
const Color_ = Type({RGB:{Red: Number, Green: Number, Blue: Number}, CMYK:{Cyan: Number, Magenta: Number, Yellow: Number, Black:Number}});
const {Person} = Type({Person: {name: String, id: Number, leftEyeColor: Color_, rightEyeColor: Color}});
let person = Person({name: 'John', id: 1, leftEyeColor: Color.RGB(255,100,255), rightEyeColor: Color_.CMYK({Cyan: 50, Magenta: 80, Yellow: 10, Black: 25})});
let personWithoutEyes = Person('John', 2);
let person2 = personWithoutEyes(Color.RGB(100,100,100), Color.CMYK(30,30,30,0));
@alexeygolev
alexeygolev / union-type.js
Created August 6, 2015 14:22
Extract validation
import {curryN} from 'ramda';
var _validate = function(){};
function Constructor(group, name, validators) {
let cons = Object.create(group, {
_ctor: {
value: name
},
toString: {
value: function(){
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory();
else if(typeof define === 'function' && define.amd)
define(factory);
else if(typeof exports === 'object')
exports["fantasy"] = factory();
else
root["fantasy"] = factory();
})(this, function() {