Skip to content

Instantly share code, notes, and snippets.

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

Yuriy Yakovenko djleonskennedy

🌌
Loading...
View GitHub Profile
-- The Y combinator, discovered by Haskell B. Curry, is defined as: Y = \f.(\x.f (x x)) (\x. f (x x))
-- haskell
newtype Mu a = Mu (Mu a -> a)
y f = (\h -> h $ Mu h) (\x -> f . (\(Mu g) -> g) x $ x)
-- javascript
const factSource = partial => n => n === 0 ? 1 : n * partial(n - 1);
@djleonskennedy
djleonskennedy / contavatiant-example.hs
Last active March 27, 2019 15:56
Contravariant Functor how to use it in practice
import Data.Functor.Contravariant
-- newtype Predicate a = Predicate { getPredicate :: a -> Bool }
--instance Contravariant Predicate where
-- contramap f (Predicate p) = Predicate (p . f)
-- | `- First, map the input...
-- `----- then apply the predicate.
fb = Predicate (\x -> x > 20)
@djleonskennedy
djleonskennedy / simple-FP-stuff.js
Last active September 27, 2018 13:39
some FP stuff :)
// compose
const compose = (...fns) => x =>
fns.reduceRight((v, f) => f(v), x);
/*
const toSlug = compose(
encodeURIComponent,
join('-'),
map(toLowerCase),
split(' ')
I had the same issue but manually triggering configure script
```(cd ./node_modules/react-native/third-party/glog-0.3.4 && ../../scripts/ios-configure-glog.sh)``` resolves it.
Also - If you want to build app for iOS 12 you have to switch path to the active developer directory
```(xcode-select -s /Applications/Xcode-beta.app/Contents/Developer).```
@djleonskennedy
djleonskennedy / sync-control.directive.spec.ts
Created September 17, 2018 08:17 — forked from Fredx87/sync-control.directive.spec.ts
Angular SyncControl directive
import { Component } from '@angular/core';
import { async, TestBed } from '@angular/core/testing';
import { FormControl, FormGroup, ReactiveFormsModule } from '@angular/forms';
import { By } from '@angular/platform-browser';
import { SyncControlDirective } from './sync-control.directive';
class FormGroupHostComponent {
formGroup = new FormGroup({
ctrl: new FormControl('')
});
@djleonskennedy
djleonskennedy / haskell-monad-laws.hs
Created February 20, 2018 23:03
haskell monad laws
-- Left identity
-- return x >>= f 'same as' f x
return 3 >>= (\x -> Just (x+100000))
-- Just 100003
(\x -> Just (x+100000)) 3
-- Just 100003
-- Right identity
@djleonskennedy
djleonskennedy / identity-functor-compare.hs
Created August 19, 2017 19:41
Compare Identity Functor Implementation
// Typescript
class Identity {
constructor(private x: any) {
}
map(f: Function): any {
this.x = f(this.x);
}
}
const id = new Identity(2);
// Recursive:
const factorial = n =>
n < 2
? 1
: n * factorial(n-1);
// Tail-recursive:
@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({
@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 () {