Skip to content

Instantly share code, notes, and snippets.

View James-E-A's full-sized avatar

James E. A. James-E-A

View GitHub Profile
@James-E-A
James-E-A / application.ex
Last active July 8, 2025 19:49
Elixir lazy upsert storing SECRET_KEY_BASE in Ecto
defmodule Foo.Application do
@moduledoc false
use Application
@impl true
def start(_type, _args) do
children = [
FooWeb.Telemetry,
Foo.Repo,
@James-E-A
James-E-A / load_oceanView.m
Last active December 12, 2024 01:48
MATLAB load OceanView TXT files
function [intensities, wavelengths, t] = load_oceanView(filesGlobString)
%load_oceanVew
% - output is INSTANTLY ready to be graphed
% via surf(t, wavelengths, intensities)
% - does NOT fail on data that's non-uniform in time
% e.g. when OceanView malfunctions
files = matlab.buildtool.io.FileCollection.fromPaths( ...
replace(filesGlobString,'/',filesep));
paths = files.paths;
@James-E-A
James-E-A / util.fragment.ex
Last active February 10, 2025 17:50
Elixir DynamicSupervisor start child if it doesn't already exist
defmodule FooApp.Util do
@doc """
Exactly like [DynamicSupervisor.start_child/2](https://hexdocs.pm/elixir/1.18/DynamicSupervisor.html#start_child/2)
except that the "id" field is not [disregarded](https://hexdocs.pm/elixir/1.15/DynamicSupervisor.html#start_child/2:~:text=while%20the%20:id%20field%20is%20still%20required,the%20value%20is%20ignored),
but instead used as a unique key.
Only works with simple GenServer supervisees for now.
Does NOT work with remote DynamicSupervor or distributed systems for now.
@James-E-A
James-E-A / temporal_settlement.py
Last active September 11, 2025 02:11
Beancount clear different legs of transaction on different dates
from contextlib import contextmanager
from datetime import date
from functools import reduce
from gettext import dgettext
from traceback import format_exception
from types import SimpleNamespace
import re
import uuid
from beancount.core.account import join as account_join, leaf, root, sans_root
from contextlib import contextmanager
import re
import traceback
from beancount.core.data import *
from beancount.core.prices import get_price, build_price_map
from beancount.plugins.implicit_prices import ImplicitPriceError as ImplicitPriceError_t
"""Beancount plugin to make certain prices transitive
@James-E-A
James-E-A / resource_ctx.mjs
Last active November 19, 2024 18:32
Javascript safe "Python-with like" pattern
/* pending https://github.com/tc39/proposal-explicit-resource-management */
/* Usage:
let result = await use_resource({
async acquire(url) {
// "__enter__"
const e = document.createElement('iframe');
e.src = url;
e.hidden = true;
@James-E-A
James-E-A / simple_tkinter_threaded_helper.py
Last active June 25, 2025 17:46
simple tkinter multithreaded comunication
import queue
import logging
from tkinter import TclError
import weakref
__all__ = ['data_bind']
def data_bind(widget, callback, *, pass_tk_event=False, timeout=0.0, catastrophic_timeout=5.0, queueing_mode='auto'):
"""Foolproof, thread-safe workaround for https://github.com/python/cpython/issues/47655
@James-E-A
James-E-A / tkinter_iss47655_polyfill.py
Last active August 29, 2024 14:23
tkinter module send data with virtual event / event_generate
__all__ = ['check_for_bug', 'patch_bug', 'auto_patch_bug']
import logging
import os
import pdb
import platform
import sys
import threading
import tkinter
@James-E-A
James-E-A / configuration.nix.inc
Last active August 11, 2024 02:36
NixOS custom kernel with AMDGPU SI & CIK support
# Custom Kernel to use AMDGPU driver with Radeon HD 7790, HD 7750-7970, HD 7790, R7 240, R7 250, R7 260, R9 270, R9 280
# https://www.x.org/wiki/RadeonFeature/#:~:text=Southern%20Islands&text=Sea%20Islands
# https://wiki.archlinux.org/title/AMDGPU#:~:text=Compile%20kernel%20which%20supports%20amdgpu%20driver
# https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/gpu/drm/amd/amdgpu/Kconfig?h=v6.10&id=0c3836482481200ead7b416ca80c68a29cfdaabd#n37
boot.kernelPatches = [ {
name = "amdgpu-si-cik";
patch = null;
extraConfig = ''
DRM_AMDGPU_SI y
DRM_AMDGPU_CIK y
@James-E-A
James-E-A / rtc_ex.mjs
Last active August 7, 2024 20:10
WebRTC simple perfect negotiation wrapper
// To use the functions exported by this module,
// you must already have an existing_channel
// connecting the two endpoints -- a so-called
// "signaling server" -- before you can establish
// a WebRTC connection.
/*
const config = { iceServers: [{ urls: 'stun:stun.l.google.com:19302' }] };
const _signaling_server = new MessageChannel();
_signaling_server.port1.start();