Skip to content

Instantly share code, notes, and snippets.

View vicimpa's full-sized avatar
👨‍💻

PromiSe#### vicimpa

👨‍💻
View GitHub Profile
@vicimpa
vicimpa / mini-zustand.ts
Last active October 14, 2025 16:51
A minimal reactive store for React in TypeScript, built only with native hooks. Provides immutable state, type-safe selectors, and simple integration — the store itself is a hook.
import { useCallback, useSyncExternalStore } from "react";
type StoreContext<T extends object> = {
$set(update: Partial<T>): void;
$set(update: (prev: T) => Partial<T>): void;
};
type InitialStore<T extends object> = T & ThisType<Readonly<T> & StoreContext<T>>;
type ListenerStore<T extends object> = (state: Readonly<T>, preview: Readonly<T>) => any;
type DisposeSubsribe = () => void;
@vicimpa
vicimpa / index.ts
Last active September 16, 2024 22:38
#simplecodetest
// Проверочка
@vicimpa
vicimpa / tast1.js
Created September 16, 2024 18:16
#simplecodetaskquest
/**
@description Небольшая тестовая задачка, для проверки редактора кода.
*/
// CODE_START
function sum(a, b) {
return a + b;
}
// CODE_END
import React, { createElement, forwardRef, useCallback, useLayoutEffect, useState } from "react";
const URL = "https://jsonplaceholder.typicode.com/users";
// Хук для работы с асинхронщиной
function useAsync<T>(
asyncFunc: () => T | Promise<T>,
deps: any[] = []
): [
data: T | null,
@vicimpa
vicimpa / github_know_hosts.sh
Created March 4, 2024 16:04
Auto append github.com ssh keys to know_hosts
#!/bin/bash
ssh-keyscan github.com | while read line
do
grep -qxF "$line" ~/.ssh/known_hosts || echo "$line" >> ~/.ssh/known_hosts
done
@vicimpa
vicimpa / useCalc.ts
Created January 9, 2024 11:55
useCalc.ts
import { useSignal } from "@preact/signals-react";
import { runFrame, TFrameSub, useFrame } from "./useFrame";
export const useCalc = <T extends TFrameSub>(calc: T) => {
const signal = useSignal<ReturnType<T>>(runFrame(calc));
useFrame((dtime, time) => {
const result = calc(dtime, time);
@vicimpa
vicimpa / useEvents.ts
Created January 9, 2024 11:55
useEvents.ts
import { useCallback, useRef } from "react";
export const useEvent = <T extends Function>(func: T) => {
const ref = useRef(func);
ref.current = func;
return useCallback<T>(((...args: any[]) => ref.current(...args)) as any, []);
};
@vicimpa
vicimpa / useFrame.ts
Last active January 9, 2024 12:00
useFrame.ts
import { useLayoutEffect } from "react";
import { useEvent } from "./useEvent";
export type TFrameSub = (dtime: number, time: number) => any;
const FRAME_SUBS = new Set<TFrameSub>();
let lastTime = -1;
let lastDelta = 0;
@vicimpa
vicimpa / isEqual.ts
Created January 13, 2022 09:17
Функция для проверки на еквивалентность объектов
export const isEqual = (a: any, b: any) => {
const toEqual: [any, any][] = [[a, b]];
let iters = 0;
for (let j = 0; j < toEqual.length; j++) {
iters++;
const [a, b] = toEqual[j];
if (a === b) continue;
if (a === null || b === null)