Skip to content

Instantly share code, notes, and snippets.

View jacobobryant's full-sized avatar

Jacob O'Bryant jacobobryant

View GitHub Profile
@jacobobryant
jacobobryant / debug-biff-route.md
Created August 20, 2021 18:25
Example of debugging an http endpoint (or function in general) in Biff (or Clojure in general)
@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 / _howto.md
Last active April 13, 2024 16:37
How to add a toggle button for dark mode with Biff and Tailwind

How to add a toggle button for dark mode with Biff and Tailwind

By default, Tailwind's dark mode classes will take effect automatically if the user's operating system is already set to dark mode. Follow these instructions if you would also like to provide a toggle button so the user can override the operating system setting.

Set darkMode: 'class' in tailwind.config.js:

@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 / bookmarklet.js
Last active February 2, 2024 16:53
How to make your own airtable bookmark bookmarklet
// 1. Create a table on Airtable, and make URL/text columns with these names:
// URL, Title, Description, Image, Feed
//
// 2. Add a Form view. Click "Open form", then copy the URL. Set `airtable_form_url`
// below to that URL.
//
// 3. Create a new bookmark in your web browser, and paste in the code below. Whenever
// you're on a page you want to save, click the bookmark ("bookmarklet", technically).
// You'll go to the airtable form, and the columns listed above will be prefilled.
//
@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 / dashboard.clj
Last active December 16, 2023 15:17
Internal dashboard code being used in yakread.com
(ns com.yakread.report.dashboards
(:require [com.biffweb :as biff]
[clojure.string :as str]
[cheshire.core :as cheshire]))
(defn debug [x]
[:pre (with-out-str (biff/pprint x))])
;; slight modification of clojure.core/distinct
(defn distinct-by