Skip to content

Instantly share code, notes, and snippets.

View theKashey's full-sized avatar
🤔
what's happening?

Anton Korzunov theKashey

🤔
what's happening?
View GitHub Profile
@theKashey
theKashey / .yarnrc
Last active November 5, 2023 06:08
using yarn 2 plugin to run "postinstall script"
#....
plugins:
- path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
spec: '@yarnpkg/plugin-workspace-tools'
- .yarn/plugins/ts-referent-plugin.cjs ### ⬅️ ⬅️ ⬅️ ⬅️
@theKashey
theKashey / plugin.ts
Created May 22, 2021 08:21
Node Workers based Webpack StartServerPlugin
import { Worker } from "worker_threads";
import type { Compiler, compilation, Plugin } from "webpack";
interface Options {
name: string;
require?: string[];
keyboard?: boolean;
}
import { useState, useEffect } from 'react';
type UseResizeObserverCallback = (ref: Element) => void;
type ResizeObserverCallback = (
entries: IResizeObserverEntry[],
observer: ResizeObserver,
) => void;
interface IResizeObserverEntry {
@theKashey
theKashey / scroll-memory.js
Created July 3, 2020 23:22
scroll-memory
import React from "react";
import { withRouter } from "react-router-dom";
import { getPageScroll, scrollTo } from "./utils";
const ScrollContext = React.createContext(new Map());
const getLocationKey = location => `${location.pathname}?${location.search}`;
const ScrollMemory = ({ children, history: _history, location }) => {
@theKashey
theKashey / story-machine.js
Created April 30, 2020 07:07
kills-state
const initial = {};
const fetchMachine = Machine({
id: 'panel',
initial: 'waiting',
context: initial,
states: {
waiting: {
// always reset to initial context
entry: assign(() => null),
on: {
@theKashey
theKashey / report-bundle-size.js
Created March 13, 2020 08:33
Report total entry size using webpack-imported
const fs = require("fs");
const gzipSize = require("gzip-size");
const stats = require("../build/imported");
function collectSize(assets) {
return assets.reduce((acc, asset) => acc + (stats.assets.find(({ name }) => name === asset) || { size: 0 }).size, 0);
}
function collectGSize(assets) {
"use strict";
exports.__esModule = true;
exports.default = void 0;
var _pluginSyntaxDynamicImport = _interopRequireDefault(require("@babel/plugin-syntax-dynamic-import"));
var _chunkName = _interopRequireDefault(require("./properties/chunkName"));
var _isReady = _interopRequireDefault(require("./properties/isReady"));
@theKashey
theKashey / prefetchWorker.js
Created October 11, 2019 02:24
cloudflare HTTP(not HTML!) prefetch
// see cloudflare workers - https://workers.cloudflare.com
addEventListener('fetch', event => {
event.respondWith(fetchAndStream(event.request))
})
async function fetchAndStream(request) {
let streamResponse = fetch(request); // dont await, as majority of CF examples do
let { readable, writable } = new TransformStream()
@theKashey
theKashey / helmet.tsx
Created July 31, 2019 11:52
jsLingui compatible "Helmet"
import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { createChannel } from 'react-push-channel';
function setDescription(description: string) {
const meta = document.querySelector('meta[name=description]') || document.createElement('meta');
meta.setAttribute('name', 'description');
meta.setAttribute('content', description);
document.head!.appendChild(meta);
}
@theKashey
theKashey / use-scroll-drag.js
Last active July 23, 2019 22:21
Slide "scrollable containers" with you mouse like a... touch
import {useState, useEffect, useLayoutEffect, useRef} from "react";
const getMouseCoords = (e) => [e.clientX, e.clientY];
const useDragHandle = (ref) => {
const [mouseDown, setMouseDown] = useState(null);
const [initialScroll, setInitialScroll] = useState(null);
useEffect(() => {
const {current: container} = ref;