Skip to content

Instantly share code, notes, and snippets.

View pugson's full-sized avatar

pugson pugson

View GitHub Profile
@brampersandon
brampersandon / use-async.tsx
Last active November 1, 2023 11:53
Common hooks I use everywhere but don't want to install
import { useState, useCallback } from "react";
type AsyncStatus = 'notasked' | 'loading' | 'success' | 'error';
// from https://usehooks.com/useAsync/
export const useAsync = <T, E = string>(
asyncFunction: (...args: any[]) => Promise<T>,
) => {
const [status, setStatus] = useState<AsyncStatus>('notasked');
const [value, setValue] = useState<T | null>(null);
import * as React from "react";
import { useMousePosition } from "~/hooks/useMousePosition";
/** Component to cover the area between the mouse cursor and the sub-menu, to allow moving cursor to lower parts of sub-menu without the sub-menu disappearing. */
export function MouseSafeArea(props: { parentRef: React.RefObject<HTMLDivElement> }) {
const { x = 0, y = 0, height: h = 0, width: w = 0 } = props.parentRef.current?.getBoundingClientRect() || {};
const [mouseX, mouseY] = useMousePosition();
const positions = { x, y, h, w, mouseX, mouseY };
return (
<div
@bonniss
bonniss / github-search-cheatsheet.md
Last active January 20, 2026 20:00
Github search cheatsheet from official docs.

Github Search Cheat Sheet

GitHub’s search supports a variety of different operations. Here’s a quick cheat sheet for some of the common searches.

For more information, visit our search help section.

Basic search

@pugson
pugson / readme.md
Created April 4, 2019 15:11
How to fix unknown host on .dev TLD after using puma-dev

How to fix unknown host on .dev TLD after using puma-dev

  1. Run scutil --dns
  2. Check if you have something like this in your output:
resolver #8
  domain   : dev
  nameserver[0] : 127.0.0.1
  port     : 9253
 flags : Request A records, Request AAAA records
@juliendargelos
juliendargelos / imagemagick-trim-transparent.sh
Last active November 20, 2025 13:04
Imagemagick commands that trims transparent pixels from an image.
# Trim a single "input.png" image and save to "output.png"
magick input.png -trim +repage output.png
# Trim a single "image.png" image and overwrite the original file (based on @enijar comment)
mogrify -trim +repage image.png
# Trim and overwrite all png images from the working directory (based on @enijar comment)
mogrify -trim +repage *.png
@jamieparfet
jamieparfet / macOS-mojave-iso.sh
Last active December 10, 2024 14:38
Create an ISO from the mojave installer app
#!/bin/bash
# This assumes that the ~6GB mojave installer is in the /Applications folder.
# If it's not, just open the App Store, search Mojave, and you can download the installer file from there.
hdiutil create -o /tmp/mojave.cdr -size 6g -layout SPUD -fs HFS+J
hdiutil attach /tmp/mojave.cdr.dmg -noverify -mountpoint /Volumes/install_mojave
sudo /Applications/Install\ macOS\ mojave.app/Contents/Resources/createinstallmedia --volume /Volumes/install_mojave
mv /tmp/mojave.cdr.dmg ~/Desktop/InstallSystem.dmg
hdiutil detach /Volumes/Install\ macOS\ mojave

Fixing macOS 10.14, 10.15, 12

Dark main menu without the rest of dark mode

  1. Set Light mode
  2. defaults write -g NSRequiresAquaSystemAppearance -bool Yes
  3. Log out and log back in
  4. Set Dark mode
// This is a worker that can be deployed in a desperate situation in order
// to disable all service worker caching by overwriting the running worker
// with a no-op worker.
//
// Keep it close for when you need it.
self.addEventListener('install', () => {
// Activate immediately, taking control from any broken service workers
self.skipWaiting();
});
@spyesx
spyesx / rsync_backup.sh
Last active November 24, 2025 17:10
Rsync backup excluding node_modules
# Backup files
#https://explainshell.com/explain?cmd=rsync+-azuv+--delete+--progress+--exclude+%27node_modules%27
rsync -auvhp --delete --exclude=node_modules [source] [destination]
# Remove all node_modules folders
# https://explainshell.com/explain?cmd=find+.+-name+%22node_modules%22+-type+d+-prune+-exec+rm+-rf+%27%7B%7D%27+%2B
find . -name "node_modules" -type d -prune -exec rm -rf '{}' +
@argyleink
argyleink / easings.css
Created February 26, 2018 22:34
Handy CSS properties for easing functions
:root {
--ease-in-quad: cubic-bezier(0.55, 0.085, 0.68, 0.53);
--ease-in-cubic: cubic-bezier(0.55, 0.055, 0.675, 0.19);
--ease-in-quart: cubic-bezier(0.895, 0.03, 0.685, 0.22);
--ease-in-quint: cubic-bezier(0.755, 0.05, 0.855, 0.06);
--ease-in-expo: cubic-bezier(0.95, 0.05, 0.795, 0.035);
--ease-in-circ: cubic-bezier(0.6, 0.04, 0.98, 0.335);
--ease-out-quad: cubic-bezier(0.25, 0.46, 0.45, 0.94);
--ease-out-cubic: cubic-bezier(0.215, 0.61, 0.355, 1);
--ease-out-quart: cubic-bezier(0.165, 0.84, 0.44, 1);