Skip to content

Instantly share code, notes, and snippets.

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

Acorn1010 acorn1010

🏠
Working from home
View GitHub Profile
@acorn1010
acorn1010 / FirestoreUtils.ts
Created May 16, 2021 11:28
Hacky Firestore onWrite without slow initialization.
const service = 'firestore.googleapis.com';
// Note: We avoid importing firebase-functions because we don't want to slow down startup times.
type Change<T> = any;
type DocumentSnapshot = any;
type EventContext = any;
type CloudFunction<T> = any;
/**
* Creates an onWrite function for use as a Firestore onWrite callback. Replaces functions.firestore.document().onWrite().
* @param projectId the Firebase project id for the entire project (e.g. "foo-123").
* @param path a Firestore path such as "usernames/{username}"
@acorn1010
acorn1010 / createContainer.ts
Created June 5, 2022 10:26
createGlobalState
import {
Dispatch,
SetStateAction,
useCallback,
useEffect,
useState,
} from 'react';
const isFunction = (fn: unknown): fn is Function => (typeof fn === 'function');
@acorn1010
acorn1010 / useEffectDebugger.ts
Last active June 13, 2023 11:59
useEffectDebugger.ts
import {useEffect, useRef} from "react";
/**
* Prefer this to react-use. We're deprecating react-use later.
* Returns `value` from the previous render.
*/
export function usePrevious<T>(value: T, initialValue?: T) {
const ref = useRef<T | undefined>(initialValue);
useEffect(() => {
ref.current = value;
@acorn1010
acorn1010 / wsl2_firewall_hole_puncher.bat
Created July 20, 2022 14:09
WSL2 Firewall Hole Puncher
$remoteport = bash.exe -c "ifconfig eth0 | grep 'inet '"
$found = $remoteport -match '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
if( $found ){
$remoteport = $matches[0];
} else{
echo "The Script Exited, the ip address of WSL 2 cannot be found";
exit;
}
@acorn1010
acorn1010 / available_domains.txt
Last active September 11, 2022 17:58
Small Domain Tool and 2-character .gg domains
# These domains were available as of about 2 days ago. Best of luck!
https://www.namecheap.com/domains/registration/results/?domain=a7.gg
https://www.namecheap.com/domains/registration/results/?domain=a8.gg
https://www.namecheap.com/domains/registration/results/?domain=b6.gg
https://www.namecheap.com/domains/registration/results/?domain=b7.gg
https://www.namecheap.com/domains/registration/results/?domain=c8.gg
https://www.namecheap.com/domains/registration/results/?domain=d7.gg
https://www.namecheap.com/domains/registration/results/?domain=d8.gg
https://www.namecheap.com/domains/registration/results/?domain=e0.gg
https://www.namecheap.com/domains/registration/results/?domain=e5.gg
@acorn1010
acorn1010 / .bashrc
Last active September 8, 2022 18:46
Acorn1010's .bashrc
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples
# If not running interactively, don't do anything
case $- in
*i*) ;;
*) return;;
esac
@acorn1010
acorn1010 / generate_images.sh
Last active November 25, 2022 14:46
Foony Generate Images Script (credit keraion)
#!/usr/bin/env bash
# Credit to keraion for huge readability improvements and parallelization.
set -e
# Creates webp / avif images for images that don't already exist and places them in the public folder
# This script can take a while to run
# Install deps
# sudo apt-get install -f webp ffmpeg
@acorn1010
acorn1010 / OverflowText.tsx
Created November 25, 2022 14:44
OverflowText.tsx
import {
createStyles,
makeStyles,
Tooltip,
Typography,
TypographyProps,
} from '@material-ui/core';
import clsx from 'clsx';
import React, {CSSProperties, useCallback, useState} from 'react';
import useResizeObserver from 'use-resize-observer';
@acorn1010
acorn1010 / aoc.ts
Created December 8, 2022 16:18
AoC Day 8
import * as fs from "fs";
function readFile(path: number) {
const result =
fs.readFileSync(`/home/acorn/projects/js/foony/scripts/src/aoc/${path}.txt`, 'utf-8').split('\r\n');
for (let i = result.length - 1; i >= 0; --i) {
if (!result[i].trim()) {
--result.length; // Last line is empty, remove it
} else {
return result;
@acorn1010
acorn1010 / createGlobalStore.ts
Last active April 1, 2024 01:11
Easier Zustand store
import {SetStateAction, useCallback} from 'react';
import {create} from "zustand";
export type EqualityFn<T> = (left: T | null | undefined, right: T | null | undefined) => boolean;
export type StoreType<State> = {
use<K extends keyof State>(
key: K,
defaultValue?: State[K],
equalityFn?: EqualityFn<State[K]>,