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 / wintypes_guid.py
Last active February 28, 2025 19:01
Python wintypes missing GUID structure
import ctypes
import uuid
__all__ = ['wintypes_GUID']
class wintypes_GUID(ctypes.Structure):
_fields_ = [
('Data1', ctypes.c_uint32),
('Data2', ctypes.c_uint16),
('Data3', ctypes.c_uint16),
@James-E-A
James-E-A / demo_kem_trans.py
Created February 12, 2025 18:07
Python simple KEM-TRANS example
#!/usr/bin/env python3
from Crypto.Cipher import AES # https://pypi.org/project/pycryptodome/
from Crypto.Hash import SHAKE256
from types import SimpleNamespace
def _demo():
# DEMO
from pqc.kem import mceliece6960119f as kemalg # https://pypi.org/project/pypqc/
@James-E-A
James-E-A / util_web.fragment.ex
Last active January 17, 2025 16:42
Elixir parse HTML datetime form input values
defmodule FooWeb.Util do
# https://html.spec.whatwg.org/multipage/common-microsyntaxes.html#valid-local-date-and-time-string
@spec parse_web_time!(String.t()) :: NaiveDateTime.t()
@spec parse_web_time!(String.t(), Calendar.time_zone()) :: DateTime.t()
@spec parse_web_time!(String.t(), Calendar.time_zone(), Calendar.time_zone_database()) :: DateTime.t()
def parse_web_time!(<<s::binary-size(16)>>) do
Timex.parse!(s, "{YYYY}-{0M}-{0D}T{h24}:{m}")
end
def parse_web_time!(<<s::binary-size(19)>>) do
Timex.parse!(s, "{YYYY}-{0M}-{0D}T{h24}:{m}:{s}")
@James-E-A
James-E-A / model.fragment.ex
Last active February 10, 2025 20:38
Elixir actor GenServer pattern
use GenServer
def act(action, state, actor \\ nil)
def act(_, _, _) do
{:error, :badarg}
end
@James-E-A
James-E-A / core_components.ex
Last active January 6, 2025 01:15
Elixir "core components" with tailwind prefix
defmodule FooWeb.CoreComponents do
@moduledoc """
Provides core UI components.
At first glance, this module may seem daunting, but its goal is to provide
core building blocks for your application, such as modals, tables, and
forms. The components consist mostly of markup and are well-documented
with doc strings and declarative assigns. You may customize and style
them in any way you want, based on your application growth and needs.
@James-E-A
James-E-A / application.ex
Last active January 27, 2025 00:38
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 December 30, 2024 21:05
Beancount clear different legs of transaction on different dates
from contextlib import contextmanager
from datetime import date, timedelta
from functools import reduce
from gettext import dgettext
import re
import traceback
from types import SimpleNamespace
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