Skip to content

Instantly share code, notes, and snippets.

View slinkardbrandon's full-sized avatar
🎯
Focusing

Brandon Slinkard slinkardbrandon

🎯
Focusing
View GitHub Profile
@slinkardbrandon
slinkardbrandon / Dockerfile
Last active June 13, 2023 13:00
Serverless in docker example
FROM node:12-alpine
WORKDIR /app
COPY tsconfig.json ./
COPY serverless.yml ./
COPY package.json ./
COPY package-lock.json ./
RUN npm ci
@slinkardbrandon
slinkardbrandon / wait-for-postgres.sh
Last active February 18, 2021 13:41
A simple script that accepts arguments and waits for a postgres connection to be available
#!/bin/sh
main() {
usage() { echo "Usage: $0 [-d <string*>] [-t <string*>] [-u <string*>] [-p <string*>] [-h <string>] [-m <number>]" 1>&2; exit 1; }
while getopts ":h:d:t:u:p:m:" o; do
case "${o}" in
u)
u=${OPTARG}
;;
@slinkardbrandon
slinkardbrandon / shading.ts
Created February 16, 2021 22:57
Hex/RGB Color Functions
import { PaletteColor, RgbString } from "../Theme";
export type RGB = [number, number, number];
type BackgroundColor = string;
export function getRedGreenBlue(rgbStr: string): RGB {
const [r, g, b] = /rgba?\((.+)\)/
.exec(rgbStr)[1]
.split(",")
.map((c) => Number(c.trim()));
@slinkardbrandon
slinkardbrandon / types.ts
Created February 18, 2021 02:38
TypeScript padding & margin types
type Without<T, U> = { [P in Exclude<keyof T, keyof U>]?: never };
export type XOR<T, U> = T | U extends object
? (Without<T, U> & U) | (Without<U, T> & T)
: T | U;
export type PaddingValue =
| number
| `${number}px`
| `${number}em`
@slinkardbrandon
slinkardbrandon / Component.tsx
Last active March 4, 2021 18:45
React useKeyBinds hook
export const MyComponent: React.FC = () => {
useKeyBinds({
"ctrl+z": () => {
console.log('undo');
},
"ctrl+y": () => {
console.log('redo');
},
});
@slinkardbrandon
slinkardbrandon / useDebouncedCallback.ts
Created April 28, 2021 01:17
A simple hook leveraging lodash debounce to create a debounced callback that persists properly across renders
import { debounce } from 'lodash';
import { useCallback, useRef } from 'react';
type Callback = (...args: any[]) => void;
/**
* Create the memoized / debounced function one time.
*
* This stores the current instance of the function to be debounced in a ref and updates
* it every render (preventing stale data). Instead of debouncing that function directly we
export const Screen: React.FC = () => {
useIdleTimer({
idleMs: 30 * 60000,
warningBeforeIdleMs: 25 * 60000,
onWarning: () => console.log('pop warning dialog'),
onIdle: async () => {
console.log('close warning dialog, sign the user out, etc');
},
});
@slinkardbrandon
slinkardbrandon / convertJsToTs.js
Last active April 8, 2023 10:30
Recursively rename all file extensions in a given directory from javascript to typescript
const { resolve } = require('path');
const { readdir, rename } = require('fs').promises;
const DIRECTORY = 'src';
async function* getFiles(dir) {
const dirents = await readdir(dir, { withFileTypes: true });
for (const dirent of dirents) {
const res = resolve(dir, dirent.name);
if (dirent.isDirectory()) {
@slinkardbrandon
slinkardbrandon / cypress.js
Created September 17, 2021 21:02
Cypress automatic globbing feature files and measurements
const cypress = require('cypress');
const { DateTime } = require('luxon');
const { green, white, yellow, red } = require('chalk');
const glob = require('glob');
const RUNTIME_MINUTES_GOOD = 6;
const RUNTIME_MINUTES_OKAY = 10;
const BASE_DIRECTORY = 'cypress/tests/integration';
/**
@slinkardbrandon
slinkardbrandon / elvui export (redone completely)
Created August 29, 2022 01:42
wow elvui export (redone completely)
A0aLHgAsVLeItEtEDaPkGKSWqdQzINMAXaPQNpF8U8E4oDqHotYRUnmnQmUgIaEOAtRCJA9VyERCykWiNqLwUSWNVImTlFpJSMhMADchdlL0k9RQUEcJqWqpSD2lmipcBWmrCoWvhERnCQnWElLlrQqluypU7VX+ishgFHEYajHBYxEmE3FZajOIzxSMVtFpVa1Woeg1IWm2KrcJsVvUb5LhkFiOeI7SdMl1Qm1H6jtQxqNI5wGyHpLsh6QeejGX4MICJuxiXidpXIv52d9w1swbOAf7kjpnAg/3ak4aRVy4vsqLeWcsvB61mmNUTX71Yt4ZC68nrFZzQ+cm+C3mpapF2MXcQBRYnaJ90on6Ks8vOm2LnjYDMMCc/ah6ptGasyg48bNhJvhqLqgsZrVwzE7UpxtW7K+v8hwwNPRcUFVKBMa534R54Sfqz4ZLYwmDYJH2BH49Ez1XwjE7UZ9uBsEifelvOGsm0LLmNH7iTqinyGIujJEyppiZgffBCLrRQGAKOIjUCJobxgAyA41o9IH5YAFBt2VZg0iNoDkZAzyFBk+BgCnQ4UaDUsypQaRG0Gou8vMXwSiLOftR9cz7tlaruYiim7CLufxowFQS+JzSERpJ29dLcPnRUBvGpHNxSkdoJG1fL8GlQA4C3XNKDIGwiKKbzEPDaft6CY4gF/UkTXhoGEBmBJceuDVHMBglhkBYqp8CQ37+IhgFUXSTOaUjNJK2r5fgUBvGpHNxSkdoJG1fL8GlQGYQvy3mOaVYlhJXqTyndIRGuPxoqA1j0rk4pSM0wqU36MBv4GEOoFQxCBZpRNFN5qFhAJkRXH401IYx6Vw8NAwgM4ID0eBcigZPzUVP5QYs/PcL0JzSERrh8qOhNoxJ5+KUjtAIv0EHfgMPc1eJjx/SWYwousk8NAwgM4LLj4baMCadi4eGAWRGcCCXosEPc1iBNaEwOVK58M9NEEU3mYeGufxoqA1j0rl4aJhbXHowzuVHQxlJcNcRZkvABFF0kzmlIzTC5UdD