Skip to content

Instantly share code, notes, and snippets.

View 73nko's full-sized avatar
💭
👨‍💻

73NKo 73nko

💭
👨‍💻
View GitHub Profile
@73nko
73nko / maybe-monad.js
Created January 31, 2019 10:18
Maybe monad In Javascript
// Naive definition
const Some = (v) => ({
val: v,
map (f) {
return Some(f(this.val))
},
chain (f) {
return f(this.val)
}
@73nko
73nko / useReducerWithLogger.js
Created April 11, 2019 06:50
A Hook to implement a logger in console after each reducer action is dispatched
function enchanceDispatchWithLogger(dispatch) {
return function (action) {
console.groupCollapsed('Action Type:', action.type);
return dispatch(action);
}
}
function useReducerWithLogger(...args) {
let prevState = useRef(initialState);
const [state, dispatch] = useReducer(...args);
@73nko
73nko / pipe.js
Created May 11, 2019 16:30
Simple pipe function
const pipe = (...fns) => x => fns.reduce((v, f) => f(v), x);
const fn1 = s => s.toLowerCase();
const fn2 = s => s.split('').reverse().join('');
const fn3 = s => s + '!'
const newFunc = pipe(fn1, fn2, fn3);
const result = newFunc('Time'); // emit!
@73nko
73nko / IterableBackwards.js
Last active May 14, 2019 10:31
Reverse loop array with iterables.
class IterableBackwards {
constructor(xs) {
this._xs = xs;
this._i = xs.length;
}
[Symbol.iterator]() { return this; }
next() {
return (this._i <= 0)
@73nko
73nko / infinite-fibonnachi.js
Created May 14, 2019 10:41
Create a infinite fibbonachi list.
function* fib() {
let a = 1, b = 0;
for (; ;) {
[a, b] = [b, a + b];
yield b;
}
}
const f = fib();
for (let i = 0; i < 6; i++)
[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]][([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+([][[]]+[])[+!+[]]+(![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[+!+[]]+([][[]]+[])[+[]]+([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]])[+!+[]+[+[]]]+(!![]+[])[+!+[]]](([][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+(![]+[])[!+[]+!+[]]+(!![]+[])[+[]]+(!![]+[])[!+[]+!+[]+!+[]]+(!![]+[])[+!+[]]]+[])[!+[]+!+[]+!+[]]+(!![]+[][(![]+[])[+[]]+([![]]+[][[]])[+!+[]+[+[]]]+
@73nko
73nko / anagram.js
Created August 8, 2019 06:17
Anagram with Maps
const isAnagram = (str1, str2) => {
if (str1.length !== str2.length) return false;
const map = new Map();
for (let char of str1) {
const count = map.has(char) ? map.get(char) + 1 : 1;
map.set(char, count);
};
const textPath = document.querySelector("#text-path");
const h = document.documentElement,
b = document.body,
st = 'scrollTop',
sh = 'scrollHeight';
document.addEventListener("scroll", e => {
let percent = (h[st]||b[st]) / ((h[sh]||b[sh]) - h.clientHeight) * 100;
textPath.setAttribute("startOffset", (-percent * 40) + 1200)
@73nko
73nko / hack.css
Created September 9, 2019 06:36
CSS trick to see inconsistencies in css layout
* { background-color: rgba(255,0,0,.2); }
* * { background-color: rgba(0,255,0,.2); }
* * * { background-color: rgba(0,0,255,.2); }
* * * * { background-color: rgba(255,0,255,.2); }
* * * * * { background-color: rgba(0,255,255,.2); }
* * * * * * { background-color: rgba(255,255,0,.2); }
* * * * * * * { background-color: rgba(255,0,0,.2); }
* * * * * * * * { background-color: rgba(0,255,0,.2); }
* * * * * * * * * { background-color: rgba(0,0,255,.2); }
@73nko
73nko / useIntersect.js
Created September 21, 2019 07:20
IntersectionObserverHook in react
import { useEffect, useRef, useState } from "react";
export default ({ root = null, rootMargin, threshold = 0 }) => {
const [entry, updateEntry] = useState({});
const [node, setNode] = useState(null);
const observer = useRef(
new window.IntersectionObserver(([entry]) => updateEntry(entry), {
root,
rootMargin,