Skip to content

Instantly share code, notes, and snippets.

View sb8244's full-sized avatar

Stephen Bussey sb8244

View GitHub Profile
@sb8244
sb8244 / extract_caller.ex
Created March 4, 2026 04:10
(Hacky) solution to extract the call site of an Ecto Repo query
defp extract_caller do
{:current_stacktrace, stack} = Process.info(self(), :current_stacktrace)
closest_caller =
Enum.reduce_while(stack, false, fn
caller = {mod, _fun, _a, [file: file_charlist, line: _]}, found_repo? ->
is_repo_caller? = mod in [Super.Repo, DBConnection] || List.starts_with?(file_charlist, ~c"lib/ecto")
skip? = file_charlist in [~c"lib/enum.ex"]
cond do
@sb8244
sb8244 / TLS.md
Created January 25, 2026 16:53
Setup TLS node networking on Fly.io

TLS is used for node-node communication. This is fairly tricky to setup with Erlang distribution because you have to generate a full CA and keys for it.

The following script is specific to Fly.io, because it generates a CACert for *.internal domains.

cd rel/overlays/tls
rm -f *.{pem,srl,conf}

# Generate the certificate authority
import { Plugin, PluginKey, Transaction } from "prosemirror-state"
import { BlockInfo, getBlockInfoFromPos } from "../helpers/getBlockInfoFromPos"
// ProseMirror Plugin which automatically assigns indices to ordered list items per nesting level.
const PLUGIN_KEY = new PluginKey(`numbered-list-indexing`)
interface Options {
getListCharacter?: (positionDetails: { depth: number; index: number }) => string
}
defmodule SuperWeb.Plug.AssetNotFound do
import Plug.Conn
alias Plug.Conn
def init(opts) do
%{
at: Keyword.fetch!(opts, :at) |> Plug.Router.Utils.split(),
only: {Keyword.fetch!(opts, :only), []}
}
end
import React, { useEffect, useRef, useState } from "react"
import { createReactBlockSpec } from "@blocknote/react"
import { SuperedBlockNoteEditor } from "../../BlockNoteEditor"
import useReload from "../../../useReload"
export const TABLE_OF_CONTENTS_TYPE = "table-of-contents"
interface Heading {
id: string
level: 1 | 2 | 3 | 4
public class ImmutableCounter {
private final int counter;
public ImmutableCounter(int num) {
this.counter = num;
}
public int getCount() {
return this.counter;
}
@sb8244
sb8244 / ImmutableDemo.java
Created September 12, 2023 05:17
Immutability Lecture (Activity 1)
import java.util.HashMap;
// This class is broken, follow the TODOs
public class ImmutableDemo {
// TODO: How to prevent external actors from accessing the map directly?
public HashMap<String,String> map;
public ImmutableDemo() {
this.map = new HashMap<String, String>();
this.map.put("Important", "OKAY");
defmodule Super.RepoTest do
use Super.DataCase, async: true
require Logger
@skipped_schemas [UserService.User]
defp tenant_schemas do
{:ok, mods} = :application.get_key(:super, :modules)
Enum.map(mods, fn mod ->
var links = document.getElementsByTagName('a');
var params = new URLSearchParams(window.location.search);
var utmParams = {};
params.forEach(function (val, name) {
if (name.startsWith('utm_')) {
utmParams[name] = val;
}
});
export const SpaceLayoutEditor = {
// Not important for the integration, just something for my specific use case
recentItems: [],
mounted() {
// IMPORTANT LINE: LiveView -> React data flow
this.handleEvent("react.update_items", ({ items }: { items: string }) => {
const newItems: SpaceItem[] = JSON.parse(items)
this.mountEditor(newItems)
})