Skip to content

Instantly share code, notes, and snippets.

View thesephist's full-sized avatar
🍷
Ridin' in a getaway car

Linus Lee thesephist

🍷
Ridin' in a getaway car
View GitHub Profile
@thesephist
thesephist / trash.sh
Created October 24, 2018 22:47
Instead of `rm`-ing files that you don't need, which doesn't leave a backup, use "trash" in the CLI
HOME_TRASH_DIR=~/.trash/
function trash () {
mkdir -p $HOME_TRASH_DIR
mv "$@" $HOME_TRASH_DIR
}
@thesephist
thesephist / light.sh
Created November 19, 2018 08:32
Adjust laptop backlight beyond min/max
function light() {
sudo su -c "echo $1 > /sys/class/backlight/intel_backlight/brightness"
}
@thesephist
thesephist / longestsubstring.js
Created January 4, 2019 17:18
Longest Common Substring
const longestSubstring = (a, b) => {
// assert that a.length > b.length
if (b.length > a.length) {
[a, b] = [b, a]
}
// If b is a full substring of a,
// just bail early.
if (a.includes(b)) {
@thesephist
thesephist / quicksort.js
Created January 13, 2019 20:28
Slow JS Quicksort
//> Not-in-place quicksort for illustrative purposes
// This console.log's the call tree for sorting a given array.
const INDENT_UNIT = ' '; // 4 spaces
const values = [17, 32, 24, 4, 2, 6, 4, 11, 0, 3, 56, 2, 6, 34, 4, 76, 3, 2, 7, 23];
const quickSort = (arr, indent = '') => {
if (arr.length <= 1) {
return arr;
@thesephist
thesephist / queue.ink
Created December 23, 2019 15:31
Concurrent asynchronous queue in Ink
` concurrent task queue `
std := load('std')
log := std.log
each := std.each
range := std.range
new := maxConcurrency => (
s := {
@thesephist
thesephist / debounce.js
Created June 2, 2020 19:24
ESNext Debounce
//> Debounce coalesces multiple calls to the same function in a short
// period of time into one call, by cancelling subsequent calls within
// a given timeframe.
const debounce = (fn, delayMillis) => {
let lastRun = 0;
let to = null;
return (...args) => {
clearTimeout(to);
const now = Date.now();
const dfn = () => {
@thesephist
thesephist / analysis.ink
Last active June 8, 2020 11:19
Blog writing analysis script, referenced in thesephist.com/posts/blog-analysis/ ✍️
` Count sentence length, word size distribution over past posts `
std := load('std')
str := load('str')
quicksort := load('quicksort')
log := std.log
f := std.format
append := std.append
cat := std.cat
@thesephist
thesephist / inkfmt.sh
Last active July 20, 2020 08:20
Thin CLI wrapper around inkfmt utility to format files on disk
#!/bin/sh
#
# This is a thin wrapper around https://github.com/thesephist/ink
# to give me two CLI commands when this script is placed
# in /usr/local/bin.
#
# 1. I can type `inkfmt file.ink` to see any formatting changes
# needed in file.ink.
# 2. I can type `inkfmt fix file.ink` to make the script fix
# all formatting errors in file.ink in-place of the file.
@thesephist
thesephist / farey.ink
Created July 17, 2020 04:00
Ink script that uses Farey sequences to approximate rational numbers as arbitrarily close fractions
#!/usr/bin/env ink
` farey addition to approximate numbers `
std := load('std')
log := std.log
f := std.format
Threshold := 0.000000005
@thesephist
thesephist / remake-tutorial.md
Last active October 24, 2020 16:43
Remake Tutorial

Build your first Remake app

Remake the Web.

This is a story of two problems and two solutions.

My first problem was a problem of my own creation. I read a lot of blog posts online, many of them so good that I save them for later, to re-read and share. I started with a simple page on my website where I just kept a list of those links, and why I enjoyed them. But eventually, the list became slow and annoying to update manually -- I wanted an app.

That’s when I came upon my second problem, which was very much not my own: Even for something super, super simple, like I want a page on the Internet where I can share an updated list of links, it takes a lot of work to get something working. The road from idea to prototype is covered with excuses not to build, and that problem is bigger than myself.