Skip to content

Instantly share code, notes, and snippets.

View djleonskennedy's full-sized avatar
🌌
Loading...

Yuriy Yakovenko djleonskennedy

🌌
Loading...
View GitHub Profile
let clicks$ = Rx.Observable.fromEvent(document.getElementById('button'), 'click');
clicks$
.buffer(clicks$.debounce(250))
.map(list => list.length)
.filter(x => x === 2)
.subscribe(() => {
console.log('doubleclick');
})
@djleonskennedy
djleonskennedy / futurizeP.js
Created January 26, 2017 16:31
futurizeP get payload with json()
const Task = require('data.task');
const fetch = require('node-fetch');
// futurizeP :: (* -> Promise a b) -> * -> Task a b
const futurizeP = require('futurize').futurizeP(Task);
// fetchJson_ :: Url -> Promise Error Object
const fetchJson_ = url => fetch(url).then(res => res.json());
// fetchJson :: Url -> Task Error Object
@djleonskennedy
djleonskennedy / laws.js
Last active January 25, 2017 20:16
laws for some algebraic data structures
// Functor => F.map
/*
laws
const id = x => x
*/
//fx.map(f).map(g) === fx.map(x => g(f(x)))
//fx.map(id) === id(fx)
// Monad => F.of, chain (also: flatMap, bind, >>=)
.truncate {
width: 250px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
const service = {
getUsers: () => fetch(`https://jsonplaceholder.typicode.com/users`),
getGroups: () => fetch(`https://jsonplaceholder.typicode.com/posts`)
};
async function getData() {
try {
const peoplePromise = await service.getUsers();
const groupsPromise = await service.getGroups();
@djleonskennedy
djleonskennedy / getPlatform.js
Last active January 15, 2017 11:25
getPlatform by Brian Lonsdorf and me)
import Either from 'data.either'
import Task from 'data.task'
// We don't want to tie ourselves to any global environment so Task here
const win = new Task((rej, res) => res(window))
const nav = new Task((rej, res) => res(navigator))
// We chain because we want to work with `win` (another Task) if nothing's found.
const userAgent = nav
.chain(n =>
compare : List a -> List a -> Maybe (a -> a -> Bool) -> Bool
compare list1 list2 callback =
if (List.length list1) /= (List.length list2) then
False
else
let
test a b =
case callback of
Just cb ->
cb a b
/**
* @function compare
* @description function compares two arrays with ids to figure out: are they equal? (elements position can be different)
* @param arraFrom {Array}
* @param arraTo {Array}
* @param compareFunction {Function}
* @returns {Boolean}
*/
function compare(arrayFrom, arrayTo, compareFunction) {
import Html exposing (text)
transform : List Int -> List Int
transform =
List.map ((*) 2)
<< List.filter (flip (%) 2 >> (==) 0)
main =
[1,2,3,4,5,6,7,6,2]
|> text
[{item = { pid = 1 }, qty = 1 }, ...]
List.sortBy (.item >> .pid) listOfItems