Skip to content

Instantly share code, notes, and snippets.

View lxchurbakov's full-sized avatar

Aleksandr Churbakov lxchurbakov

View GitHub Profile
@lxchurbakov
lxchurbakov / init.js
Last active July 31, 2024 06:21
HTML5 Canvas
const canvas = canvasRef.current;
const pixelRatio = window.devicePixelRatio || 1;
const rect = canvas.getBoundingClientRect();
canvas.style.width = rect.width + 'px';
canvas.style.height = rect.height + 'px';
canvas.width = rect.width * pixelRatio;
canvas.height = rect.height * pixelRatio;
@lxchurbakov
lxchurbakov / binary-search.js
Last active August 15, 2024 06:48
Leet Code Algos
const search = (nums, target) => {
let start = 0;
let end = nums.length - 1;
while (start <= end) {
let mid = Math.floor((end + start) / 2);
if (nums[mid] === target) {
return mid;
}
@lxchurbakov
lxchurbakov / use-state.tsx
Last active July 28, 2024 06:23
use-betwee-concept
const getDispatcher = () => {
return (React as any).__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher.current;
};
const setDispatcher = (w: any) => {
(React as any).__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher.current = w;
};
const useForceUpdate = ([v, setv] = useState(false)) =>
@lxchurbakov
lxchurbakov / feeds.json
Last active January 16, 2024 06:16
VIHJ
[
{"url":"https://feeds.megaphone.fm/newheights"},
{"url":"https://vas3k.club/posts.rss"},
{"url":"https://feeds.feedburner.com/abseilio"},
{"url":"https://www.astronet.ru/db/rss.xml"},
{"url":"https://ciechanow.ski/atom.xml"},
{"url":"http://ithare.com/feed/"},
{"url":"https://xkcd.com/rss.xml"},
{"url":"https://nuancesprog.ru/feed/"},
{"url":"https://tproger.ru/feed"},
import React from 'react';
import { Relative, Absolute, Clickable } from '../components/atoms';
const DropContext = React.createContext(null);
const useDrop = () => React.useContext(DropContext);
// If you don't want some kind of effect
// to depend on a callback but wnat the
// freshest version of a callback to be
// available, this one is fo you
@lxchurbakov
lxchurbakov / assets.ts
Last active January 25, 2023 09:38
plugins
export type Image = HTMLImageElement;
const loadImage = async (url: string) => new Promise<Image>((resolve, reject) => {
const img = new Image();
img.onload = () => resolve(img);
img.onerror = (e) => reject(e);
img.src = url;
});
@lxchurbakov
lxchurbakov / rxjs.ts
Created December 6, 2022 08:21
libraries
const observable = (predicate) => (listener) => predicate(listener);
const pipe = (obs) => (...operators) => operators.reduce((acc, op) => op(acc), obs);
const map = (mapper) => (obs) => observable((resolve) => obs((data) => resolve(mapper(data))));
const mergeMap = (mapper) => (obs) => observable((resolve) => obs((data) => mapper(data)(resolve)))
const filter = (predicate) => (obs) => observable((resolve) => obs((data) => predicate(data) && resolve(data)));
// {
// tsconfig
{
"compilerOptions": {
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"baseUrl": "./src",
"outDir": "./dist",
"sourceMap": true,
"declaration": false,
@lxchurbakov
lxchurbakov / atoms.tsx
Last active June 3, 2023 04:25
minimal-ui
import React from 'react';
import styled, { css } from 'styled-components';
type PropsOf<T> = T extends React.FC<infer P> ? P : never;
export type BaseProps = {
p?: string;
pt?: string;
pl?: string;
pr?: string;
@lxchurbakov
lxchurbakov / index.ts
Created November 8, 2022 08:46
moment-like-string-format-parser
const extractParams = (after: string) => {
if (!after.startsWith('(')) {
return [after, {}];
}
const paramsEnd = after.indexOf(')');
return [
after.slice(paramsEnd + 1),
Object.fromEntries(