Skip to content

Instantly share code, notes, and snippets.

View stenin-nikita's full-sized avatar

Nikita Stenin stenin-nikita

View GitHub Profile
export interface Fn<Args extends any[] = [], Result = void> {
(...args: Args): Result;
}
export type Getter<T> = Fn<[track: Track], T>;
export type Setter<T> = Fn<[value: T], void>;
export type Updater<T> = Fn<[reducer: Fn<[value: T], T>], void>;
@stenin-nikita
stenin-nikita / isAction.ts
Last active October 27, 2020 15:41
reatom-helpers
import { Action } from '@reatom/core';
export function isAction(arg: any): arg is Action<any> {
return arg && typeof arg === 'object' && typeof arg.type === 'string';
}
const paths = declareAtom({}, on => [
on(itemsAtom, (state, items) => {
const ims = values(items);
const paths = {};
for (const id of ims) {
paths[id] = getPathForItem(id, items);
}
return paths;
import React, { FC } from 'react';
import { useAtom } from '@reatom/react';
import { declareAtom } from '@reatom/core';
interface TreeNode {
id: string;
parentId: string | null;
name: string;
children: string[];
properties: {
import { useContext, useEffect } from 'react';
import { context } from '@reatom/react';
export function useActionEffect(actionCreator, callback) {
const store = useContext(context);
useEffect(() => store.subscribe(actionCreator, () => callback()), [store, callback]);
}
const EFFECT = Symbol('@@Reatom/EFFECT');
function createActionCreatorWithEffect(type, effect) {
return (payload) => ({
type,
payload,
[EFFECT]: (store) => effect(payload, store),
})
}
@stenin-nikita
stenin-nikita / ApolloUpload.php
Last active May 12, 2018 13:40
ApolloUpload Middleware for Laravel
<?php
declare(strict_types=1);
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
/**
* Class ApolloUpload
@stenin-nikita
stenin-nikita / calc.php
Created December 11, 2017 17:32
kmyacc example
<?php
/* Prototype file of PHP parser.
* Written by Masato Bito
* This file is PUBLIC DOMAIN.
*/
$buffer = null;
$token = null;
$toktype = null;
@stenin-nikita
stenin-nikita / react-verificator-example-1.jsx
Created November 12, 2017 18:38
Example API for react-verificator
import React, { Component } from 'react'
import validator from 'react-verificator'
const mapValidatorToProps = ({ ownProps, validator }) => ({
validator
})
@validator({
rules: {
name: 'required',
@stenin-nikita
stenin-nikita / install-packages.sh
Last active August 1, 2017 08:14
Install packages for Debian 8
#!/usr/bin/env bash
# run command:
# wget -qO- https://gist.githubusercontent.com/stenin-nikita/069e653666be5612aec509011c2af498/raw/install-packages.sh | DB_ROOT_PASSWORD="secret" DB_USER_PASSWORD="secret" bash
export DEBIAN_FRONTEND=noninteractive
function print_green {
echo -e "\e[32m${1}\e[0m"
}