Skip to content

Instantly share code, notes, and snippets.

@ceving
ceving / Web Component for Copyright Years.md
Last active April 29, 2024 07:06
Web Component for Copyright Years
@OrionReed
OrionReed / dom3d.js
Last active May 5, 2024 14:09
3D DOM viewer, copy-paste this into your console to visualise the DOM topographically.
// 3D Dom viewer, copy-paste this into your console to visualise the DOM as a stack of solid blocks.
// You can also minify and save it as a bookmarklet (https://www.freecodecamp.org/news/what-are-bookmarklets/)
(() => {
const SHOW_SIDES = false; // color sides of DOM nodes?
const COLOR_SURFACE = true; // color tops of DOM nodes?
const COLOR_RANDOM = false; // randomise color?
const COLOR_HUE = 190; // hue in HSL (https://hslpicker.com)
const MAX_ROTATION = 180; // set to 360 to rotate all the way round
const THICKNESS = 20; // thickness of layers
const DISTANCE = 10000; // ¯\\_(ツ)_/¯
@tangentstorm
tangentstorm / sh.mjs
Last active May 5, 2024 02:58
shorthand javascript
// sh.mjs: javascript shorthand
// array helpers (apl/j/k)
export const id=x=>x
export const af=(n,x)=>Array(n).fill(x) // TODO: make this 'afl' or 'fil' (aa?)
export const ii=(n,f)=>{for(let i=0;i<n;i++)f(i)}
export const im=(n,f)=>af(n,0).map((_,i)=>f(i))
export const ia=(n,f)=>im(n,id)
export const at=(a,ixs)=>ixs.map(i=>a[i])
export const io=(xs,ys)=>ys.map([].indexOf.bind(xs))
@Tomn94
Tomn94 / wish-it-were-a-script.md
Last active March 27, 2024 06:40
💻 What to do on new macOS installs

Current — March 2024

  1. During Setup Assistant, Choose French as language and France as region.
    Add English (US) as 2nd preferred language (to be able to search for emoji in French+English, etc.), remove any keyboard besides ABC.
    In Vision settings, enable ⌃-2-fingers zoom and automatic switch between Light & Dark mode.
    Don’t import any backup, connect to iCloud, create an account without touching the avatar (guarantees it’ll use iCloud’s), customize data sharing, enable FileVault, add a fingerprint for Touch ID, set up Apple Pay.

  2. Download apps on the Mac App Store:
    Pages, Numbers, Keynote, Pixelmator Pro, Final Cut Pro, Apple Configurator, 1Blocker for Safari, Supercopy for Safari, Messenger, Ivory, Mactracker, Apple Developer, TestFlight, Key Codes, Boop.

@khalidx
khalidx / node-typescript-esm.md
Last active April 22, 2024 15:40
A Node + TypeScript + ts-node + ESM experience that works.

The experience of using Node.JS with TypeScript, ts-node, and ESM is horrible.

There are countless guides of how to integrate them, but none of them seem to work.

Here's what worked for me.

Just add the following files and run npm run dev. You'll be good to go!

package.json

@dreness
dreness / list_launchd_notifications.sh
Created October 14, 2023 13:14
LaunchEvents -> com.apple.notifyd.matching
find /System/Library/LaunchDaemons /System/Library/LaunchAgents -name "*.plist" \
| while read p ; do plutil -convert json -o - ${p} \
| jq -r ' .. | objects | with_entries(select(.key == "Notification")) | select(. != {}).Notification'
done | sort -u > ~/Desktop/all-launchd-notifications.txt
@kconner
kconner / macOS Internals.md
Last active April 22, 2024 21:28
macOS Internals

macOS Internals

Understand your Mac and iPhone more deeply by tracing the evolution of Mac OS X from prelease to Swift. John Siracusa delivers the details.

Starting Points

How to use this gist

You've got two main options:

@diogox
diogox / hs.lua
Created March 19, 2023 15:27
My Hammerspoon setup
-- Make sure commandline client (/usr/local/bin/hs) is installed
-- and IPC module is running.
require("hs.ipc")
local logger = hs.logger.new("ipc", "info")
local path = "/usr/local"
-- On Macs with Apple chips, install cli in /opt/homebrew/ with Homebrew
-- as /usr/local doesn't seem to be writable.
@kfox
kfox / README.md
Last active December 4, 2023 11:08
TCP echo server for Node.js

TCP echo server for Node.js

Usage

  1. Make sure you have a modern-ish version of Node.js installed.
  2. Type npx https://gist.github.com/kfox/1280c2f0ee8324067dba15300e0f2fd3
  3. Connect to it from a client, e.g. netcat or similar: nc localhost 9000
@nopeless
nopeless / check-prime.ts
Last active April 5, 2024 20:26
static prime checking using typescript types
// Prime checking regex, which this code is based off of
// https://regex101.com/r/RIJkGF/1
type StringDivisible<n extends string, div extends string> = n extends `` ? true : n extends `${div}${infer r}` ? StringDivisible<r, div> : false;
type Substrings<n extends string, d extends string = ""> = n extends `${d}${infer r}` ? readonly [` ${d}`, ...Substrings<r, ` ${d}`>] : readonly [];
type StringFactors<n extends string> = Substrings<n> extends readonly [unknown, ...infer R extends readonly string[], unknown] ? R : never;
type StringIsPrime<n extends string, Factors extends readonly string[] = StringFactors<n>> = Factors extends readonly [infer s extends string, ...infer R extends readonly string[]] ? StringDivisible<n, s> extends true ? false : StringIsPrime<n, R> : true;
type RepeatStringByStringDigit<str extends string, d extends string> =