Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:

Arutyunyan Artyom artalar

:octocat:
View GitHub Profile
View const.ts
import * as t from 'runtypes'
export const oneMillisecond = 1
export const oneSecond = oneMillisecond * 1000
export const oneMinute = oneSecond * 60
export const oneHour = oneMinute * 60
export const oneDay = oneHour * 24
/** 30 messages per second for all users
* and one message per second for one user
View useCallbackRef.ts
import { useRef } from 'react'
export function useCallbackRef<Deps extends any[], Args extends any[], Return>(
fn: (deps: Deps, ...args: Args) => Return,
deps: Deps,
): (...args: Args) => Return {
const argsRef = useRef({
fn: (...args: Args) => fn(argsRef.current.deps, ...args),
deps,
})
@artalar
artalar / index.js
Created Nov 9, 2021
Pseudocode that's demonstrate how react hooks work under hood
View index.js
let currentComponent;
let currentMemory;
let currentIndex;
function useState(initState) {
if (currentIndex in currentMemory === false) {
currentMemory.push(initState);
}
const state = currentMemory[currentIndex];
currentIndex++;
View ghtr54t36y45u6jyh.js
const getPrev = (n, list) => (n > 0 ? n - 1 : list.length - 1);
function shake(input) {
const result = input.slice(0);
let debug_CyclesCount = 0;
result.forEach((el, i) => {
const next = result[i + 1];
if (el !== next) return;
View links - code optimization techniques.md
View reatom-redux-devtools.ts
import { Action, Causes, Fn, Patch, Rec, StoreOnPatch, TransactionResult } from '@reatom/core'
function getActionsType(actions: ReadonlyArray<Action>) {
return actions.length === 1
? actions[0].type
: actions.map(({ type }) => type).join(', ')
}
function parsePatch(patch: Patch) {
View docker-compose.yml
version: '3.6'
services:
postgres:
image: postgres:12
restart: always
volumes:
- db_data:/var/lib/postgresql/data
environment:
POSTGRES_PASSWORD: postgrespassword
hasura:
View hello-form.html
<form>
<label>
Enter your name
<input />
</label>
<button type="submit">Submit</button>
</form>
<p></p>
View reatom_perf.ts
import { performance } from 'perf_hooks'
import * as effector from 'effector'
import w from 'wonka'
import { Action, Atom, createStore } from '../build'
const w_combine = <A, B>(
sourceA: w.Source<A>,
sourceB: w.Source<B>,
): w.Source<[A, B]> => {
const source = w.combine(sourceA, sourceB)