Skip to content

Instantly share code, notes, and snippets.

View jacobobryant's full-sized avatar

Jacob O'Bryant jacobobryant

View GitHub Profile
@jacobobryant
jacobobryant / init.vim
Created July 3, 2025 16:56
nvim config as of 2025-07-03
call plug#begin()
function! DoRemote(arg)
UpdateRemotePlugins
endfunction
Plug 'tpope/vim-sexp-mappings-for-regular-people'
Plug 'guns/vim-sexp'
"Plug 'tpope/vim-repeat' " TODO fix the error this triggers on undo
Plug 'tpope/vim-surround'
@jacobobryant
jacobobryant / profile.py
Created June 5, 2025 09:00
profiling code for python inspired by clojure tufte library
import time
from fastapi import Request
from starlette.middleware.base import BaseHTTPMiddleware
from contextlib import contextmanager
from collections import defaultdict
import threading
_profiling_data = threading.local()
@contextmanager
@jacobobryant
jacobobryant / example.clj
Created August 31, 2024 21:17
Clojure / RocksDB Java interop examples
(ns com.biffweb.impl.index
(:require [taoensso.nippy :as nippy])
(:import java.util.Map
java.util.HashMap
java.util.function.Function
(java.io Closeable File)
(java.nio.file Files Path)
java.nio.file.attribute.FileAttribute
(org.rocksdb BlockBasedTableConfig Checkpoint CompressionType FlushOptions LRUCache
DBOptions Options ReadOptions RocksDB RocksIterator
@jacobobryant
jacobobryant / index-example.clj
Created August 31, 2024 20:52
Some index code from Yakread
(defattr newsletter-subs :user/email-subscriptions [:vector :biff.attr/ref]
{:biff.attr/input [:xt/id]
:biff.attr/output [{:user/email-subscriptions [:sub/user
:sub/newsletter
:sub/kind
:sub/unread
:sub/last-published
:sub/pinned
:sub/total
:sub/read]}]}
@jacobobryant
jacobobryant / 1howto.md
Created August 31, 2024 18:23
How to add extra fields to your signup form with Biff's authentication module

Adding fields to the signup form is more complex than just setting a custom :biff.auth/new-user-tx function because both authentication flows (email link and six-digit code) include multiple requests (e.g. in the email link flow, first you submit a form with your email address, then you click a link), and new-user-tx doesn't get called until the last request. So we have to modify the auth flows to take the extra form params from the first request and propagate them so that new-user-tx has access to them.

Below is a diff of the starter app showing exactly how to do that. First, you'll need to copy over the authentication module code into your project, as demonstrated in step 4 of the Postgres howto. Then apply the changes in the diff below to your auth.clj file. Remove the com.biffweb.impl.* namespaces and use a single [com.biffweb :as biff] require instead.

@jacobobryant
jacobobryant / stripe-examples.md
Created August 3, 2024 23:14
Some examples of using Stripe via Clojure/Biff

These are some examples of using the Stripe API in a Clojure/Biff app, taken verbatim from Yakread. For more details, see the Stripe documentation. For the most part I recommend using the REST API directly rather than going through the Java SDK.

Yakread has an advertising page that lets you connect a credit card via Stripe checkout. The card is charged later, after your advertisement has run.

Here's some of the code for the advertising page:

@jacobobryant
jacobobryant / init.vim
Created January 13, 2024 20:40
neovim config as of jan 2024
call plug#begin()
function! DoRemote(arg)
UpdateRemotePlugins
endfunction
Plug 'tpope/vim-sexp-mappings-for-regular-people'
Plug 'guns/vim-sexp'
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-surround'
@jacobobryant
jacobobryant / instructions.md
Created December 9, 2023 00:21
How to make cider use `bb dev` to start the REPL

Put this in .dir-locals.el:

((nil . ((cider-preferred-build-tool . babashka)
         (cider-babashka-parameters . "dev"))))
@jacobobryant
jacobobryant / biff-logging.md
Created December 3, 2023 07:11
Notes on default logging in Biff

Thanks to @olavfosse for writing this up:


The logging architecture of our aplication looks like this. The leftmost nodes are user-facing logging APIs. They all hand their logs over to slf4j, which in turns hand them over to slf4j-simple, which prints them.

clojure.tools.logging -\

@jacobobryant
jacobobryant / app.js
Created June 14, 2023 19:35
Some javascript code I use for rendering emails in Yakread
// This assumes you have an element like <div id="post-content" data-contents="..."></div>,
// where data-contents has the html you'd like to render. Then call renderPost().
function $(selector) {
return document.querySelector(selector);
}
function renderPost() {
let element = $("#post-content");
let html = element.getAttribute('data-contents');