Skip to content

Instantly share code, notes, and snippets.

View patrickhulce's full-sized avatar
😎
Live, eat, breathe JS

Patrick Hulce patrickhulce

😎
Live, eat, breathe JS
View GitHub Profile
@patrickhulce
patrickhulce / mac-setup.md
Last active January 8, 2024 16:44
Macbook Setup

setup steps

  1. Show battery percentage (now in control center prefs)

  2. Enable tap click, right click

  3. Hide dock

  4. Uncheck "close Windows when quitting an application"

  5. Update device name in Preferences > Sharing

  6. Install homebrew (installs xcode command line utils)

  7. Install Terminal

@patrickhulce
patrickhulce / client.js
Created November 1, 2023 15:46
How node request cancellation works.
/* eslint-disable */
const fetch_ = require('node-fetch');
const fetchWithTimeout = async (url, options, timeout) => {
const controller = new AbortController();
const id = setTimeout(() => controller.abort(), timeout);
const response = await fetch(url, {
...options,
@patrickhulce
patrickhulce / web-events.test.ts
Created July 12, 2023 02:25
Cheatsheet for web events.
import {ReadableStream} from 'node:stream/web';
// Custom logger that accumulates log statements
const logger = {
logs: [],
log(...messages) {
this.logs.push(messages.join(' '));
},
error(...messages) {
this.logs.push(`ERROR: ${messages.join(' ')}`);
@patrickhulce
patrickhulce / findkeys.sh
Last active July 10, 2023 10:09
Find all keys without a TTL in Redis
#!/bin/sh
redis-cli keys "*" | head -n $1 > keys.txt
cat keys.txt | xargs -n 1 -L 1 redis-cli ttl > ttl.txt
paste -d " " keys.txt ttl.txt | grep .*-1$ | cut -d " " -f 1 | redis-cli del
@patrickhulce
patrickhulce / plate-checker.js
Created July 8, 2023 19:42
Checks for a particular license plate combination in Texas.
async function checkAvailability(plate: string): Promise<string> {
const encodedPlate = encodeURIComponent(plate);
const url = `https://www.myplates.com/api/licenseplates/passenger/carbon-fiber/${encodedPlate}?_=${Date.now()}`;
const response = await fetch(url, {
headers: {
accept: 'application/json, text/javascript, */*; q=0.01',
'accept-language': 'en-US,en;q=0.9',
Referer: 'https://www.myplates.com/design/personalized/passenger/carbon-fiber/',
'Referrer-Policy': 'strict-origin-when-cross-origin',
},
@patrickhulce
patrickhulce / mac-setup.sh
Last active December 2, 2022 04:03
GitHub Self-Hosted Runners
#!/bin/bash
# Non-scripted Tasks:
# - Configure device name in Preferences > Sharing
# - Enable Remote Login & Remote Management in Preferences > Sharing
# - Enable automatic login/disable password after sleep in Preferences > Security & Privacy > General
# - Disable screensaver/sleep in Preferences > Energy Saver
# - Disable spotlight indexing of home directory
# - Add a runner in GitHub UI to grab your token https://github.com/<org>/<repo>/settings/actions/runners/new
@patrickhulce
patrickhulce / Dockerfile
Created February 11, 2022 19:47
Chromium hangs on screenshots when `--disable-frame-rate-limit` is used.
FROM node:16-buster
WORKDIR /app
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN echo 'deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main' | tee /etc/apt/sources.list.d/google-chrome.list
RUN apt-get update
RUN apt-get install -y google-chrome-stable
COPY package.json ./
@patrickhulce
patrickhulce / killall-ssh.sh
Created July 15, 2016 17:55
Kill all open SSH mux sessions
#!/bin/sh
ps aux | grep ssh[:] | awk {'print $2'} | xargs kill -9
@patrickhulce
patrickhulce / typedoc.sh
Created February 15, 2022 22:13
Automatically generate typedoc markdown on multiple platforms.
#!/bin/bash
set -euxo pipefail
./pnpm exec typedoc \
--treatWarningsAsErrors \
--excludePrivate \
--gitRevision master \
--githubPages false \
--plugin typedoc-plugin-markdown \
@patrickhulce
patrickhulce / microtasks.mjs
Created February 8, 2022 21:18
Microtask flush example
let x = 0;
new Promise(resolve => resolve()).then(() => {
x = 1
new Promise(resolve => resolve()).then(() => {
x = 2
})
})
await flushAllMicrotasks()