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
// Code to measure selection rects
// NOTE: this isn't actually JS... it's Oak. But I think the code is readable if you know JS :/
// NOTE: I *think* this event listener only works when attached to `document`.
with document.addEventListener('selectionchange') fn handleSelectionChange {
if active := document.activeElement {
? -> ?
_ -> if active.classList.contains('textarea-itself') {
false -> ?
@thesephist
thesephist / prepare_data.py
Created December 15, 2022 01:57
Data prep script to fine-tune GPT-3 on my past writing
#!/usr/bin/env python
import os
import json
from tqdm import tqdm
from transformers import GPT2TokenizerFast
os.environ['TOKENIZERS_PARALLELISM'] = 'false'
FILENAME = './thesephist.jsonl'
@thesephist
thesephist / options.oak
Created November 14, 2022 22:09
Collection of useful Stable Diffusion prompt modifiers
{ name: 'Lighting', options: [
'golden hour, warm glow'
'blue hour, twilight, ISO12000'
'midday, direct lighting, overhead sunlight'
'overcast, whitebox, flat lighting, diffuse'
'dreamlike diffuse ethereal lighting'
'dramatic lighting, dramatic shadows, illumination'
'studio lighting, professional lighting, well-lit'
'flash photography'
'low-key lighting, dimly lit'

ask CLI

ask is a little CLI I made to interact with OpenAI's GPT-3 (text-davinci-002) from my shell/terminal. The instruction fine-tuning on that model makes it particularly ideal for just asking questions and making requests.

With this CLI, I can do something like:

$ ask 'Write a haskell function that reverses a string'
reverseString :: String -> String
reverseString = foldl (\acc x -> x : acc) []
@thesephist
thesephist / generate-pushid.js
Created September 26, 2022 13:14 — forked from mikelehen/generate-pushid.js
JavaScript code for generating Firebase Push IDs
/**
* Fancy ID generator that creates 20-character string identifiers with the following properties:
*
* 1. They're based on timestamp so that they sort *after* any existing ids.
* 2. They contain 72-bits of random data after the timestamp so that IDs won't collide with other clients' IDs.
* 3. They sort *lexicographically* (so the timestamp is converted to characters that will sort properly).
* 4. They're monotonically increasing. Even if you generate more than one in the same timestamp, the
* latter ones will sort after the former ones. We do this by using the previous random bits
* but "incrementing" them by 1 (only in the case of a timestamp collision).
*/
@thesephist
thesephist / compress-pdfs.sh
Created September 16, 2022 07:36
Bash one-liner (with Oak and Rush) to compress all PDFs in a folder
rush mv *.pdf 'o-{{name}}.pdf && ls *.pdf | oak pipe "print(line), exec('/usr/local/bin/gs', ['-sDEVICE=pdfwrite', '-dCompatibilityLevel=1.4', '-dPDFSETTINGS=/ebook', '-dNOPAUSE', '-dQUIET', '-dBATCH', '-sOutputFile=' + str.trimStart(line, 'o-'), line], '').stdout |> str.trim()"
@thesephist
thesephist / afterglow.md
Last active August 11, 2022 00:18
Prompt: ""Afterglow" is a speculative science fiction novel about a world attempting to rebuild after an apocalyptic nuclear attack on semiconductor foundries in Taiwan causes worldwide silicon shortages and geopolitical turmoil. The novel is praised particularly for its detailed and creative worldbuilding. Write a detailed plot summary of the e…

"Afterglow" is a speculative science fiction novel by Greg Egan about a world attempting to rebuild after an apocalyptic nuclear attack on semiconductor foundries in Taiwan causes worldwide silicon shortages and geopolitical issues.

  1. Synopsis

The novel is set in the year 2040, in the aftermath of a nuclear attack on semiconductor foundries in Taiwan that has left the world without access to silicon. The attack has caused widespread economic and political upheaval, and the novel follows the efforts of a group of scientists, engineers, and entrepreneurs to develop new technologies and rebuild the world.

  1. Characters

The novel follows a large cast of characters, including:

As someone who worked on parsers it's kind of interesting that you picked this particular version of a parsing problem b/c it involves operator precedence, which introduces a fair bit of complexity. The "canonical" solution to operator precedence is Pratt parsing, a variation of which is used in my language parsers. I also just find that algorithm neat, conceptually. But it is kind of hard to wrap your mind around it b/c of its generality.

Two things about parsers, focusing on Pratt parsers, that I have enjoyed

The latter is where I learned how to do Pratt parsing. The former is just a generally very very good blog about PL stuff.


@thesephist
thesephist / README.md
Created July 26, 2022 17:03 — forked from mzabriskie/README.md
Check git status of multiple repos

If you're like me you have a dir like ~/Workspace/Github where all your git repos live. I often find myself making a change in a repo, getting side tracked and ending up in another repo, or off doing something else all together. After a while I end up with several repos with modifications. This script helps me pick up where I left off by checking the status of all my repos, instead of having to check each one individually.

Usage:

git-status [directory]

This will run git status on each repo under the directory specified. If called with no directory provided it will default to the current directory.

@thesephist
thesephist / min-char-rnn.py
Created May 23, 2022 08:08 — forked from karpathy/min-char-rnn.py
Minimal character-level language model with a Vanilla Recurrent Neural Network, in Python/numpy
"""
Minimal character-level Vanilla RNN model. Written by Andrej Karpathy (@karpathy)
BSD License
"""
import numpy as np
# data I/O
data = open('input.txt', 'r').read() # should be simple plain text file
chars = list(set(data))
data_size, vocab_size = len(data), len(chars)