Skip to content

Instantly share code, notes, and snippets.

View domosedov's full-sized avatar
🏠
Working from home

Aleksandr Grigorii domosedov

🏠
Working from home
View GitHub Profile
@domosedov
domosedov / supabase-tips.ts
Created October 11, 2023 21:02
Supabase Tips
// v1
const { data, error } = await supabase
.from('messages')
.select('*, users!inner(*)')
.eq('users.username', 'Jane')
@domosedov
domosedov / resolvePluralForm.ts
Created February 22, 2023 11:36
resolve plural form
export function resolvePluralForm(count: number) {
const lastNumber = count % 10
const lastNumbers = count % 100
if (lastNumber === 1 && lastNumbers !== 11) return 'one'
if (lastNumber > 1 && lastNumber < 5 && (lastNumbers < 10 || lastNumbers > 20)) return 'few'
return 'many'
}
@domosedov
domosedov / example.api.ts
Created December 8, 2022 12:10 — forked from epicbytes/example.api.ts
NextJS Authorization Files
/*** function that used as middleware ***/
accessToken: async (name) => {
if (typeof document === "undefined") return "";
let token = document.cookie
.split(";")
.filter((cookie) => cookie.startsWith("token"))[0];
if (!token) {
const response = await fetch("/api/refresh", { method: "POST" });
@domosedov
domosedov / tips.ts
Created June 29, 2022 17:41
Next.JS Tips
const isFirstServerCall = req?.url?.indexOf('/_next/data/') === -1
@domosedov
domosedov / effector_track_scope.ts
Last active May 22, 2022 20:21
Await scope all calculations
const start = createEvent()
const waitFx = createEffect(ms => {
return new Promise(r => setTimeout(r, ms))
})
const $ = createStore(null)
sample({
clock: start,
fn: () => 3_000,
@domosedov
domosedov / utils.ts
Last active June 4, 2023 07:46
TS Utils
type WithAutocomplete<T, U = string> = T | (U & Record<never, never>)
type ArrayItemType<T> = T extends (infer U)[] ? U : never
type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
type TupleToObject<
T extends readonly any[],
M extends Record<Exclude<keyof T, keyof any[]>, PropertyKey>,
> = { [K in Exclude<keyof T, keyof any[]> as M[K]]: T[K] }
@domosedov
domosedov / effector_kv.ts
Last active February 7, 2022 06:43
Effector KV
import { createStore, createEvent, type Event, type Store } from "effector";
import { useStoreMap, useEvent } from "effector-react/scope";
import { useCallback } from "react";
type Key = string;
type SetPayload<T> = { key: Key; value: T };
type KeyValueStore<T> = Record<Key, T>;
type KV<T> = {
set: Event<SetPayload<T>>;
@domosedov
domosedov / nextjs_use_effector_scope.ts
Last active February 7, 2022 06:44
Effector Snippets
import * as React from "react";
import type { Scope } from "effector";
import { fork, serialize } from "effector";
let clientScope: Scope;
const initializeScope = (initialData: Record<string, unknown>) => {
let scope = fork({
values: {
...(clientScope ? serialize(clientScope) : {}),
@domosedov
domosedov / effector_snippets.js
Created August 17, 2021 17:34
Effector.js Snippets
// get data from clock & source
guard({
source: sample(
$source,
clock,
(source, clock) => ({ source, clock })
),
})
@domosedov
domosedov / js_roadmap.md
Created August 15, 2021 14:54
JavaScript Roadmap

JavaScript Roadmap by Domosedov

1. Основы

  • Основные типы и структуры данных

    • number, string, boolean, undefined
    • object, array, null
    • symbol, bigint, ...
  • типы переменных