Skip to content

Instantly share code, notes, and snippets.

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

Yuriy Yakovenko djleonskennedy

🌌
Loading...
View GitHub Profile
/**
* @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) {
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
@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 =>
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();
.truncate {
width: 250px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
@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, >>=)
@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
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 / randomColorGenerator.ts
Last active April 18, 2017 08:11
generates random HEX color
// TS
const randomColorGenerator = (): string =>
`#${(Math.random().toString(16) + '0000000').slice(2, 8)}`;
// ES6
const randomColorGenerator = () =>
`#${(Math.random().toString(16) + '0000000').slice(2, 8)}`;
// ES5
var randomColorGenerator = function () {
@djleonskennedy
djleonskennedy / renderSharePointList.js
Last active April 27, 2017 20:45
example how to render SharePoint List to App, es5
requirejs.config({
paths: {
ramda: '../Scripts/vendor/ramda.min',
jquery: '../Scripts/vendor/jquery-1.12.4.min',
}
});
require(['ramda', 'jquery'], function (R, $) {
$.ajaxSetup({