Skip to content

Instantly share code, notes, and snippets.

Avatar

Jacob O'Bryant jacobobryant

View GitHub Profile
@jacobobryant
jacobobryant / _howto.md
Last active May 25, 2023 23:49
How to add a toggle button for dark mode with Biff and Tailwind
View _howto.md

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 / deps.edn
Created April 18, 2023 17:16
Get # of unique slack channel participants per month
View deps.edn
{:deps {clj-http/clj-http {:mvn/version "3.12.3"}
org.jsoup/jsoup {:mvn/version "1.11.3"}}}
@jacobobryant
jacobobryant / dashboard.clj
Last active March 28, 2023 06:08
Internal dashboard code being used in yakread.com
View dashboard.clj
(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
@jacobobryant
jacobobryant / howto.md
Last active May 25, 2023 23:26
How to let users upload images to S3 with Biff
View howto.md

How to let users upload images to S3 with Biff

Add the provided s3.clj file to your project, and set the following keys in config.edn and secrets.env:

;; config.edn
:s3/origin "https://nyc3.digitaloceanspaces.com"
:s3/edge "https://example.nyc3.cdn.digitaloceanspaces.com"
:s3/bucket "your-bucket"
:s3/access-key "..."
@jacobobryant
jacobobryant / juice.js
Last active February 25, 2023 02:08
Some JS functions used in Yakread
View juice.js
// A serverless function for Readability that I'm currently using
let juice = require('juice');
function main(opts) {
let html = juice(opts['html'], { webResources: { images: false } });
return { body: { html } };
}
exports.main = main;
@jacobobryant
jacobobryant / Dockerfile
Created December 18, 2022 01:30
Dockerfile for deploying Biff on Fly.io
View Dockerfile
from clojure:temurin-17-tools-deps-bullseye
ENV TRENCH_VERSION=0.4.0
ENV BB_COMMIT=965c177bca31ae9882c975ef7db448e12f59984e
ENV TAILWIND_VERSION=v3.2.4
RUN apt-get update && apt-get install -y \
curl \
&& rm -rf /var/lib/apt/lists/*
RUN curl https://github.com/athos/trenchman/releases/download/v$TRENCH_VERSION/trenchman_${TRENCH_VERSION}_linux_amd64.tar.gz \
@jacobobryant
jacobobryant / tfidf.py
Created September 16, 2022 17:30
Newsletter topic extraction
View tfidf.py
"""
Usage: python tfidf.py extract_keywords
Reads from storage/keywords/corpus.csv, which has columns `<ID>,<Title>,<Description>`. Writes
keywords to storage/keywords/output.csv
I use this for newsletter topic modeling at https://thesample.ai/.
"""
import sys
import nltk
@jacobobryant
jacobobryant / git-dad.md
Created February 4, 2022 01:26
git dad: improve git's error message
View git-dad.md

Add this to your .bashrc to improve git's error message for a common typo:

git() {
  if [ "$1" = dad ]; then
    curl -H "Accept: text/plain" https://icanhazdadjoke.com/
    echo
  else
    $(which git) "$@"
 fi
@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)
View debug-biff-route.md
View announcement.md

Ratings API

I just added an API endpoint which gives you all your ratings as JSON. You could use it to e.g. fetch all your favorited articles and send them to your aunt. You can enable it from the settings page.

Also, Findka Essays has been a little flaky this week. There have been a couple days when it hasn't sent the emails out. I can trigger them manually, but I, uh, sometimes get distracted. Anyway, I've tweaked some things and hopefully it won't be an issue anymore. But either way, I'm keeping an eye on it, and I'll dig in further if the problem persists.