Skip to content

Instantly share code, notes, and snippets.

//! Kat Spiers has yet again bullied me into writing code.
//! Today we worked on type-level arithmetic.
use std::ops::{Add, Sub, Mul};
#[derive(Debug, Clone, PartialEq)]
enum Kat {
Kat(Box<Kat>),
Hryn,
}
@9999years
9999years / scheme-infix.scm
Created August 22, 2019 02:04
Infix evaluation in scheme...?
#lang r5rs
(#%require schemeunit)
(define ** expt)
(define (!= x y) (not (= x y)))
(define (^^ a b) (or (and a (not b))
(and b (not a))))
; can you believe they made && and || special forms???
(define (&& a b) (and a b))
(define (|| a b) (or a b))
#lang r5rs
(define-syntax push!
(syntax-rules (push!)
((push! x s)
(set! s (cons x s)))))
(define-syntax pop!
(syntax-rules (pop!)
((pop! s)
@9999years
9999years / static-site-generator.md
Created May 28, 2019 21:00
Ideal static site generator

I want a static site generator that

  • Lets me write in Markdown, but with some syntax for injecting HTML I can't express in plain Markdown, like Hugo's shortcodes
  • Has a good pipeline for writing CSS in SASS, Javascript in Typescript, and ideally minifying / importing those assets into the page in different ways (i.e. inline OR linking) with low friction
  • Has a good templating language that I can configure on a per-page basis, customize (to add new functions / constructs), and import data to from YAML
#! /usr/bin/env python3
# Short program to read macOS plist files and output JSON; useful for manipulating / viewing the JSON with a tool like jq.
import fileinput
import json
import plistlib
def plist_to_json(plist):
@9999years
9999years / weird_rust_error.rs
Created March 15, 2019 16:27
Build fails when using type parameter for function in Rust
// this compiles
fn validator<F, T>(f: F) -> Box<Fn(String) -> Result<(), String> + 'static>
where F: Fn(String) -> Result<T, String> + 'static {
Box::new(move |s| f(s).map(|_| ()))
}
// this fails with:
// error[E0308]: mismatched types
// --> src\main.rs:17:14
// |
@9999years
9999years / build-command-t.ps1
Created February 27, 2019 22:51
Command-T Vim plugin build script
Begin { pushd; cd 'ruby/command-t/ext/command-t' }
Process {
/tools/ruby26/bin/ruby ./extconf.rb
/tools/msys64/usr/bin/make
}
End { popd }
@9999years
9999years / infix.scm
Created February 4, 2019 22:22
Infix arithmetic evaluation in Scheme
#lang r5rs
(#%require schemeunit)
(define (any pred lst)
(if (null? lst)
#f
(or (pred (car lst)) (any pred (cdr lst)))))
(define (list-contains? el lst)
(any (lambda (el*) (equal? el el*)) lst))
@9999years
9999years / girlmarkdown.py
Last active February 4, 2019 22:20
Girl’s Markdown
import sys
# `pip install Markdown`
from markdown import markdown
FLOWER = '🌸'
START_PINK = '<span style="color: pink">'
END_PINK = '</span>'
def girlmarkdown(text):
@9999years
9999years / ligs.py
Created February 4, 2019 15:08
something about the LaTeX listings package and OpenType ligatures
import sys
def esc(txt):
left = txt
right = txt
chrs = r'\~^'
for chr in chrs:
right = right.replace(chr, '\\char"' + format(ord(chr), 'X'))
left = left.replace('\\', '\\\\')
chrs = r'$&%#{}_'