Skip to content

Instantly share code, notes, and snippets.

View mg901's full-sized avatar
🎯
Focusing

mg901

🎯
Focusing
View GitHub Profile
@yurypaleev
yurypaleev / path.ts
Last active May 17, 2021 10:13
Type Path returns all possible variants of the key for the function lodash.get
type ValueOf<T> = T[keyof T];
type ArrayPath<T> =
T extends Array<unknown>
? ArrayPath<Omit<T, keyof []>>
: T extends object
? ValueOf<{
[K in keyof T]: [K] | [K, ...ArrayPath<T[K]>];
}>
: never;

restore

https://effector.now.sh/en/api/effector/restore

Используется тогда, когда необходимо из ивента напрямую выставить значение в стор в обход .on.

Аналог без restore:

const $store = createStore('');
const event = createEvent();
$store.on(event, (_, payload) => payload);
const TIMEOUT = 500
patterns = {
's-r': [83, 82]
}
handler = e => {
// console.log(e.which)
clearTimeout(handler.timer)
handler.keys[e.which] = true
@gauravtiwari
gauravtiwari / counter.js
Created February 19, 2017 11:59
A simple counter example using vanilla JS
// A simple counter example
// The setup will be more complicated in modern apps built using React
const incrementNode = document.getElementById('increment');
const decrementNode = document.getElementById('decrement');
const inputNode = document.getElementById('counter');
const counter = {
initialize() {
incrementNode.addEventListener('click', (event) => {
@srdjan
srdjan / 100+ different counter apps...
Last active February 19, 2024 22:41
100+ different js counter apps...
100+ different js counter apps...
@bisubus
bisubus / ES5-ES6-ES2017-ES2019 omit & pick
Last active April 13, 2024 21:03
ES5/ES6/ES2017/ES2019 omit & pick
@Avaq
Avaq / combinators.js
Last active May 1, 2024 09:38
Common combinators in JavaScript
const I = x => x
const K = x => y => x
const A = f => x => f (x)
const T = x => f => f (x)
const W = f => x => f (x) (x)
const C = f => y => x => f (x) (y)
const B = f => g => x => f (g (x))
const S = f => g => x => f (x) (g (x))
const S_ = f => g => x => f (g (x)) (x)
const S2 = f => g => h => x => f (g (x)) (h (x))
@jbmusso
jbmusso / fold.js
Created November 19, 2015 22:41 — forked from kpuputti/fold.js
Functional acrobatics using folds in JavaScript.
/*eslint-env es6 */
// Inspired by the paper "A tutorial on the universality and
// expressiveness of fold" by Graham Hutton (available at
// http://www.cs.nott.ac.uk/~gmh/fold.pdf), implementing some generic
// list handling functions in JavaScript in terms of `fold`.
// Personally I had an enlightnening moment when I realised the
// beautiful interplay of cons lists and foldr during the FP101x
// Haskell course. JavaScript's syntax doesn't make this very apparent
@SleepWalker
SleepWalker / swipe.js
Created September 30, 2015 04:59
A simple swipe detection on vanilla js
var touchstartX = 0;
var touchstartY = 0;
var touchendX = 0;
var touchendY = 0;
var gesuredZone = document.getElementById('gesuredZone');
gesuredZone.addEventListener('touchstart', function(event) {
touchstartX = event.screenX;
touchstartY = event.screenY;