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 / uuid.lua
Last active May 5, 2026 21:59
Lua basic UUID function (UUIDv1, UUIDv4, UUIDv7)
local uuid = {}
assert(1<<60 ~= 0, "Requires at least 64-bit lua_Integer")
local nominal_unix_epoch = {year = 1970, month = 1, day = 1, hour = 0, min = 0, sec = 0}
local unix_epoch = os.time(os.date("!*t", os.difftime(os.time(nominal_unix_epoch), os.time(os.date("!*t", os.time(nominal_unix_epoch))))))
local unix_time_sec
if unix_epoch == 0 then
-- Lua's "some epoch" is just the Unix epoch
unix_time_sec = os.time
else
@James-E-A
James-E-A / lua55_makefile.microsoft_nmake
Last active February 5, 2026 00:21
Lua 5.5 MSVC Makefile
# Makefile for building Lua on Windows with MSVC
# See ../doc/readme.html for installation and customization instructions.
# == CHANGE THE SETTINGS BELOW TO SUIT YOUR ENVIRONMENT =======================
# Your platform. See PLATS for possible values.
PLAT= msvc
CC= cl.exe
CFLAGS= /O2 /Wall /DLUA_BUILD_AS_DLL $(SYSCFLAGS) $(MYCFLAGS)
@James-E-A
James-E-A / sunsetmode.py
Last active May 13, 2026 20:59
[WIP] script to automatically change OS theme between light/dark according to sunrise and sunset
from contextlib import contextmanager
import datetime
import hashlib
import inspect
import itertools
import json
import os
from pathlib import Path
import re
import sqlite3
@James-E-A
James-E-A / tkinter_async_helper.py
Last active February 12, 2026 16:14
Python tkinter async mainloop
import asyncio, tkinter
import ctypes
import math
import threading
from types import coroutine
__all__ = ["ATk"]
if tkinter.TclVersion == 8.6:
try:
@James-E-A
James-E-A / surrogate_wakelock.py
Last active August 9, 2025 16:07
keep Windows awake until process exits
import argparse
import asyncio
import ctypes
import concurrent
from contextlib import AsyncExitStack, ExitStack, asynccontextmanager, closing, contextmanager
import csv
import functools
import inspect
import logging
import os
@James-E-A
James-E-A / bash_profile.inc.sh
Created August 7, 2025 17:51
Elixir fix "Failed to fetch record…from registry" / "ssl_handshake.erl:… generated CLIENT ALERT: Fatal - Unknown CA"
# https://github.com/hexpm/hex/pull/727#issuecomment-3165170464
export HEX_UNSAFE_HTTPS=1;
@James-E-A
James-E-A / simple_rng.ex
Last active September 9, 2025 20:33
Elixir simple seeded AES-CTR rng
defmodule Foo.SimpleRNG do
@moduledoc """
A simple glue layer to use CTR-mode `:crypto` algorithms with the `:rand` module.
iex> new(:aes_128_ctr, <<0::size(128)>>)
...> |> :rand.seed()
iex> :rand.uniform(10**10)
3992083247
iex> :rand.uniform(10**10)
4813258075
@James-E-A
James-E-A / filenameSafeTimestamp.mjs
Last active August 20, 2025 15:21
Format timestamp safe for filename
// https://en.wikipedia.org/wiki/List_of_UTC_offsets
const TZLETTER = new Map([
[0, "Z"],
[60, "N"],
[120, "O"],
[180, "P"],
[210, "P30"],
[240, "Q"],
[300, "R"],
[360, "S"],
@James-E-A
James-E-A / settings.json
Last active July 24, 2025 20:13
VS Code set git editor only when using VS Code
{
// File > Preferences > Settings > User > Terminal > Integrated > Env
"terminal.integrated.env.windows": {
"GIT_EDITOR": "code -w"
}
}
@James-E-A
James-E-A / code_normalize.css
Created July 11, 2025 16:45
CSS make code elements regular sized
p code, code[role=presentation] {
font-size: 1.140625em;
}