Skip to content

Instantly share code, notes, and snippets.

assert() (sometimes called invariant())

Instead of checks like:

if (value === null) {
  throw new Error("missing value")
}
doSomethingThatNeedsValue(value)
@rsms
rsms / foo.service
Created October 3, 2020 00:18
Example go http server with systemd socket activation and zero-downtime restart
[Unit]
Description = Foo HTTP server
Requires = foo.socket
After = multi-user.target
[Service]
User = www-data
Group = www-data
WorkingDirectory = /var/foo
ExecStart = /var/foo/bin/foo-server
tell application "System Events"
tell process "Firefox Nightly"
set tmp to value of attribute "AXEnhancedUserInterface"
set value of attribute "AXEnhancedUserInterface" to true
set returnUrl to value of attribute "AXValue" of text field 1 of combo box 1 of toolbar "Navigation" of UI element 1 of front window
set value of attribute "AXEnhancedUserInterface" to tmp
return returnUrl
end tell
end tell
@pirate
pirate / alfred-clipboard.sh
Last active December 5, 2023 18:12
Script to manage searching, backing up, and collecting infinite clipboard history from the Alfred Clipboard History on macOS.
#!/usr/bin/env bash
# This is a script that provides infinite history to get around Alfred's 3-month limit.
# It works by regularly backing up and appending the items in the alfred db to a
# sqlite database in the user's home folder. It also provides search functionality.
# https://www.alfredforum.com/topic/10969-keep-clipboard-history-forever/?tab=comments#comment-68859
# https://www.reddit.com/r/Alfred/comments/cde29x/script_to_manage_searching_backing_up_and/
# Example Usage:
# alfred-clipboard.sh backup
@postspectacular
postspectacular / sdf-svg-heatmap.ts
Last active June 23, 2020 16:43
Shroomania: SDF SVG heatmap
import { DisjointSet } from "@thi.ng/adjacency";
import { cosineColor, GRADIENTS } from "@thi.ng/color";
import { identity, partial } from "@thi.ng/compose";
import { serialize } from "@thi.ng/hiccup";
import { rect, svg, text } from "@thi.ng/hiccup-svg";
import { fitClamped, wrap } from "@thi.ng/math";
import { IRandom, Smush32 } from "@thi.ng/random";
import {
buildKernel2d,
comp,

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
#!/bin/bash
set -e
CONTENTS=$(tesseract -c language_model_penalty_non_dict_word=0.8 --tessdata-dir /usr/local/share/tessdata/ "$1" stdout -l eng | xml esc)
hex=$((cat <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">

texture loading

A utility for loading texture in ThreeJS. Will upload to GPU as soon as the texture is loaded, ensuring that it won't cause jank later in your application.

Example:

const loadTexture = require('./loadTexture');

// Returns a THREE.Texture object
@mattdesl
mattdesl / curl.js
Last active December 2, 2021 09:42
curl noise for ThreeJS; this gist is open source under MIT license.
const SimplexNoise = require('simplex-noise');
const simplex = new SimplexNoise();
module.exports = curlNoise;
function curlNoise (x, y, z, out = new THREE.Vector3()) {
const eps = 1.0;
let n1, n2, a, b;
n1 = simplex.noise3D(x, y + eps, z);
n2 = simplex.noise3D(x, y - eps, z);

procedural mesh generation

Generates an algorithmic 3D OBJ file with ThreeJS and Node.js.

# print to stdout
node generate-mesh.js > test.obj

# write to file
node generate-mesh.js test.obj