Skip to content

Instantly share code, notes, and snippets.

View shmidt-i's full-sized avatar

Ivan Shmidt shmidt-i

  • 0+X
  • Stockholm, Sweden
View GitHub Profile
@shmidt-i
shmidt-i / machine.js
Last active February 14, 2020 13:16
Generated by XState Viz: https://xstate.js.org/viz
//onEntry: sendParent("FAIL")
const failureMachine = Machine({
id: 'failure',
initial: 'INIT',
// context: new Error('Hi there'),
states: {
INIT: {
on: {
"*": [
@shmidt-i
shmidt-i / machine.js
Last active February 13, 2020 16:22
Generated by XState Viz: https://xstate.js.org/viz
const fetchMachine = Machine({
id: "root",
context: {
authorizationCode: "123"
},
initial: "INIT",
states: {
"NOT AUTHORIZED": {
on: {
LOGIN: "AUTHORIZING"
@shmidt-i
shmidt-i / machine.js
Last active August 14, 2019 14:02
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// Machine (machine factory function)
// assign (action)
// XState (all XState exports)
const fetchMachine = Machine({
id: "theWholeSelect",
initial: "init",
context: {
currentValueToShow: null,
@shmidt-i
shmidt-i / tail-semi-path.ts
Created January 16, 2019 09:02
Tail type and Semi-path type
type Tail<T extends any[]> = ((...args: T) => any) extends ((
_: infer First,
...rest: infer Rest
) => any)
? T extends any[] ? Rest : ReadonlyArray<Rest[number]>
: []
type GrabDeepType<T extends Record<any, any>, PathType> = {
'deeper': PathType extends [infer HeadType, ...any[]]
#!/bin/bash
find ./ -type f -print | xargs grep $1 || echo 'Not found'
@shmidt-i
shmidt-i / .eslintrc.js
Created April 20, 2018 11:30
Eslint fix formatting object expression in ternary expression
//Eslint thinks that its wrong:
errorOrMessage instanceof Error
? {
error: errorOrMessage,
meta,
}
: {
error: new Error(errorOrMessage),
meta,
const actionTypeEq = type => pipe(secondArg, propEq('type', type));
const secondArg = (first, second) => second;
const assocMerge = (pathToObjectOrArray, value) =>
assocPath(pathToObjectOrArray, merge(pathOr({}, pathToObjectOrArray), value));
const reducer = cond([
[
actionTypeEq(LOADED),
(state, action) => assocMerge(['data'], action.payload)(state),
],
[T, identity],
@shmidt-i
shmidt-i / customClosure.js
Created May 25, 2017 14:36
Create your own closure for any function
// Lets say we have some function
var ar = 'Some value';
const f = (...args2) => console.log(ar, ...args2);
f(1) //Some value, 1
// Now lets change the behaviour
// without changing the function
const saveToClosure = (data) => {