Skip to content

Instantly share code, notes, and snippets.

View davidbalbert's full-sized avatar

David Albert davidbalbert

View GitHub Profile
//
// ContentView.swift
// FastNote
//
// Created by David Albert on 6/9/21.
//
import SwiftUI
struct Note: Identifiable {
@davidbalbert
davidbalbert / issue.sh
Created December 20, 2020 05:15
UniFi Certificate - acme.sh + Route 53
# Run this once in your shell. All access keys and all settings will be saved by acme.sh
DOMAIN=unifi.example.com
AWS_ACCESS_KEY_ID=foo AWS_SECRET_ACCESS_KEY=bar acme.sh \
--issue -d $DOMAIN \
--dns dns_aws \
--fullchain-file /tmp/$DOMAIN.crt \
--key-file /tmp/$DOMAIN.key \
--reloadcmd /path/to/unifi-import-certificate.sh
@davidbalbert
davidbalbert / miniKanren.swift
Last active April 4, 2024 19:47
miniKanren
// miniKanren.swift, written by David Albert, and released into the public domain.
//
// An implementation of the miniKanren relational programming language. Somewhat
// reductively, relational programs can be run both forwards and backwards. In
// addition to asking "what does this function return when passed these arguments,"
// you can also ask "what arguments to this function return the following value?"
// This lets you ask questions like like "what pairs of numbers sum to 12," which
// if you allow for negative numbers has an infinite number of solutions.
//
// Some mind bending miniKanren programs that others have written include: a
@davidbalbert
davidbalbert / main.swift
Last active June 8, 2020 15:57
MiniKanren
func nullo(_ x: Term) -> Goal {
x =~ []
}
func conso(_ a: Term, _ d: Term, _ p: Term) -> Goal {
p =~ .pair(a, d)
}
func appendo(_ l: Term, _ t: Term, _ out: Term) -> Goal {
disj {
; ht to http://www.shlomifish.org/lecture/Lambda-Calculus/slides/
(define λ lambda)
(define 0 (λ (f) (λ (x) x)))
(define +1 (λ (n) (λ (f) (λ (x) (f ((n f) x))))))
(define pred_next_tuple
(λ (tuple)
(cons (car (cdr tuple)) (cons (+1 (car (cdr tuple))) '()))))
(define 定義しろ define)
(定義しろ 見せろ display)
(定義しろ 車 car)
(定義しろ 来るだ cdr)
(定義しろ 組み立てろ cons)
(定義しろ 原子 atom)
(定義しろ 同 eq)
(定義しろ 条件 cond)
#!/usr/bin/env ruby
nesting = 0
ARGF.each_line do |l|
nesting -= l.count("}")
puts " "*nesting + l
nesting += l.count("{")
@davidbalbert
davidbalbert / macosx-dp-2.sh
Last active February 24, 2023 22:03
Install and run Mac OS X DP2 in QEMU
#!/bin/sh
# To create and format a 10 GB hard drive image
dd if=/dev/zero of=hd.img bs=1048576 count=10240
pdisk hd.img # `i` for initialize then `w` for write
# To boot from install CD, add:
# -drive file=dp2.iso,index=2,format=raw,media=cdrom \
# -prom-env 'boot-device=ide1:9,\\BootX' \
function countPossibilities(n, m) {
if (n === -1 || m === -1) {
return 0;
} else if (n === 0 && m === 0) {
return 1;
}
return countPossibilities(n-1, m) + countPossibilities(n, m-1);
}
@davidbalbert
davidbalbert / database.html
Last active January 16, 2018 21:56
Database.js
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Database.js</title>
</head>
<body>
<script>
'use strict';