Skip to content

Instantly share code, notes, and snippets.

View oleggrishechkin's full-sized avatar

Oleg Grishechkin oleggrishechkin

View GitHub Profile
@oleggrishechkin
oleggrishechkin / debounceThrottle.ts
Created January 7, 2024 23:38
Debounce + Throttle decorator
export const debounceThrottle = <T extends any[]>(func: (...args: T) => any, { debounce = 0, throttle = 0 } = {}) => {
let debounceId: any = null;
let throttleId: any = null;
let lastArgs: T | null = null;
const run = () => {
const argsToCall = lastArgs;
lastArgs = null;
@oleggrishechkin
oleggrishechkin / useOutsideClick.ts
Last active December 17, 2023 19:13
useOutsideClick hook to support nested portals
import { useRef, useEffect, useCallback, useLayoutEffect } from 'react';
const useIsomorphicLayoutEffect = typeof window === 'undefined' ? useEffect : useLayoutEffect;
export const useOutsideClick = (onOutsideClick: EventListener) => {
const clickedRef = useRef(false);
const onMouseDownOrTouchStart = useCallback(() => {
clickedRef.current = true;
}, []);
const outsideClickRef = useRef<EventListener | null>(null);
@oleggrishechkin
oleggrishechkin / blurhashDataURL.ts
Last active November 17, 2023 16:43 — forked from mattiaz9/blurhashDataURL.ts
Convert blurhash to a base64 DataURL string (no canvas or node-canvas)
import { decode } from 'blurhash';
// source of code below https://github.com/wheany/js-png-encoder/blob/master/generatepng.js
const DEFLATE_METHOD = String.fromCharCode(0x78, 0x01);
const CRC_TABLE: number[] = [];
const SIGNATURE = String.fromCharCode(137, 80, 78, 71, 13, 10, 26, 10);
const NO_FILTER = String.fromCharCode(0);
const makeCrcTable = () => {
let c;
~/Downloads/ffmpeg -i ~/Downloads/input.mp4 -an -crf 28 -movflags faststart ~/Downloads/output.mp4        

This function sum all numbers in string with this format:

2000 - apples
4000 - oranges
1000 - potatos

let sumNumbers = (value) => value.split('\n').map((el) => el.split(' ')).flat().reduce((res, el) => !isNaN(+el) ? res + +el : res, 0);
// it's color parser snippet for https://developer.apple.com/design/human-interface-guidelines/ios/visual-design/color/
// temp0 - tbody with colors
// returns tuple with [light css variables string, dark css variables string] - values can be copied to your css
Array.from(temp0)
.filter((node) => node.nodeName === 'TR')
.map((node) => {
const [lightNode, darkNode, nameNode] = Array.from(node.childNodes)
.filter((node) => node.nodeName === 'TD')
.slice(0, 3);
  • nvidia (manually)

    enable repo in software center

    sudo dnf update --refresh
    sudo dnf install gcc kernel-headers kernel-devel akmod-nvidia xorg-x11-drv-nvidia xorg-x11-drv-nvidia-libs xorg-x11-drv-nvidia-libs.i686
    

    wait 5-10 minutes

  • git

    1. setup
    git config --global user.email oleggrishechkin@gmail.com
    git config --global user.name "Oleg Grishechkin"
    git config --global core.editor "webstorm -w"
    
  • libreoffice
sudo add-apt-repository ppa:libreoffice/ppa
sudo apt install libreoffice
sudo apt install libreoffice-kde5
  • openvpn
alias go='git checkout'
alias gs='git status'
alias sync='git add .;git commit --amend --no-edit;git push -f origin'
pull() {
git fetch --all;git checkout "$1";git reset --hard origin/"$1"
}