Skip to content

Instantly share code, notes, and snippets.

View forestbelton's full-sized avatar

Forest Belton forestbelton

View GitHub Profile
@forestbelton
forestbelton / star-levels.html
Last active February 8, 2023 11:51
Shrine of the Spirits: Star levels
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Shrine of the Spirits: Star levels</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap" rel="stylesheet">
<style>
@forestbelton
forestbelton / awk.sh
Last active April 13, 2020 09:44
helpful awk aliases
function awkn {
local ARGS=""
local FLAG=""
local N="$1"
shift
while getopts "F:v:" FLAG; do
case "$FLAG" in
F) ARGS="$ARGS -F$OPTARG" ;;
% A keypad lock on a door has a code of five different digits. Can you use the six clues below to determine the correct code to get in?
%
% 1. There are no zeroes in the five-digit code.
% 2. The first digit is smaller than the second digit.
% 3. Exactly two of the five digits are odd.
% 4. The middile digit is a perfect square.
% 5. The two-digit number formed by the fourth and fifth digits is a perfect square.
% 6. The two-digit number formed by the third and fourth digits is equal to the first digit multiplied by ythe second digit.
is_digit(1).
is_digit(2).
@forestbelton
forestbelton / dataclass.js
Created February 12, 2020 06:18
types without class
const dataclass = f => function() {
Object.entries(f(...arguments)).forEach(([k, v]) => {
this[k] = v
})
}
const F = dataclass((x, y) => ({x, y}))
const f = new F(1, 2)
console.log(f instanceof F) // "true"
@forestbelton
forestbelton / extract-notes.sh
Created April 29, 2019 06:14
Extract notes from Notes.app
#!/usr/bin/bash
set -euxo pipefail
SQLITE=/Volumes/Macintosh\ HD/usr/bin/sqlite3
XXD=/Volumes/Macintosh\ HD/usr/bin/xxd
GZIP=/Volumes/Macintosh\ HD/usr/bin/gzip
NOTES_DB=NoteStore.sqlite
"${SQLITE}" ${NOTES_DB} 'select quote(zdata) from zicnotedata where zdata is not null' > notes-raw.txt
@forestbelton
forestbelton / lexer.h
Last active March 15, 2019 07:36
lexer header sketch
#ifndef CASE_LEXER_H_
#define CASE_LEXER_H_
struct lexer;
/**
* A data type which accepts a string of characters and produces a stream of
* tokens based on a set of predefined rules.
*/
typedef struct lexer lexer;
@forestbelton
forestbelton / trie-monoid.hs
Last active August 12, 2018 02:26
tries are monoids
import qualified Data.Map as M
newtype Trie c = Trie { getTrie :: M.Map c (Trie c) }
deriving (Show)
type Word c = [c]
instance Ord c => Monoid (Trie c) where
mempty = Trie M.empty
(Trie t) `mappend` (Trie t') = Trie $ M.unionWith mappend t t'

Keybase proof

I hereby claim:

  • I am forestbelton on github.
  • I am forestbelton (https://keybase.io/forestbelton) on keybase.
  • I have a public key ASB7l0uda7N7t_GLdLbqcuk7FEIn5nZ1CqS1OEJ3elTQhQo

To claim this, I am signing this object:

@forestbelton
forestbelton / Polynomial.hs
Last active March 2, 2018 20:09
Zhegalkin polynomials and conversion to algebraic normal form
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE GADTs #-}
import qualified Data.Set as S
import Data.List (intercalate, sort)
data UnaryOp
= Not
deriving (Show)
@forestbelton
forestbelton / solver.html
Last active July 8, 2016 05:00
dfs "sliding on ice" puzzle solver
<!DOCTYPE html>
<html>
<head>
<style>
#grid {
line-height: 0;
}
#grid > * {
margin:0;