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
<meta charset="UTF-8">
<!-- <script src="http://www.myersdaily.org/joseph/javascript/md5.js" integrity="sha256-8tgc1DyxWwU+qElo1Jwd9aTZiU8H+y3QKZttyeCoIlg=" crossorigin="anonymous"/> -->
<script src="md5.js" integrity="sha256-8tgc1DyxWwU+qElo1Jwd9aTZiU8H+y3QKZttyeCoIlg="></script>
<script>
// aXMLHttpRequest: an asynchronous XHR function
function aXMLHttpRequest(method, location, responseType="", body=undefined) {
// somewhat basic; improvements welcome
return new Promise( (resolve, reject) => {
const xhr = new XMLHttpRequest();
@James-E-A
James-E-A / async-cookbook.js
Created March 2, 2021 18:17
Trivial JS Asyncification functions
asleep = (delay => new Promise(resolve => setTimeout(resolve, delay)));
aalert = ((message) => new Promise((resolve) => resolve(alert(message))));
aconfirm = ((message) => new Promise((resolve) => resolve(confirm(message))));
aprompt = ((message, deflt) => new Promise((resolve) => resolve(prompt(message, deflt))));
@James-E-A
James-E-A / dnsoid.py
Last active December 1, 2023 15:56
Free OID Generator
#!/usr/bin/env python3
"""DEC Sixbit bijective hierarchicial mapping
of the DNS namespace onto hereby-proposed child arc dns-root(52)
of IANA's unused OID {iso(1) identified-organization(3) iana(90)}
NOTE that this is a horrific hack I made as a joke / proof-of-concept / demo.
There are several legitimate alternatives you could consider, h/t http://oid-info.com/faq.htm#10
@James-E-A
James-E-A / svg2ico.py
Last active September 29, 2023 15:14
from PIL import Image # https://packages.ubuntu.com/jammy/python3-pil https://pypi.org/project/Pillow/
import cairosvg.surface # https://packages.ubuntu.com/jammy/python3-cairosvg https://pypi.org/project/CairoSVG/
from io import BytesIO
def svg2ico(*args, resolutions={128, 96, 64, 48, 32, 16}, write_to=None, dpi=96, winxp_compat=False, **kwargs):
maxres = max(resolutions, key=lambda res: (0, res) if res is not None else (1, ), default=None)
# "DPI" from https://github.com/Kozea/CairoSVG/blob/2.2.0/cairosvg/__init__.py#L62
imsave_kwargs = {'format': 'ICO'}
@James-E-A
James-E-A / 00_README.md
Last active February 19, 2023 00:53
Advance Wars By Web QoL fixes

This is a collection of small quality-of-life tweaks to improve the Advance Wars By Web experience. You can use just one, or all of them; it's up to personal preference.:

  • [Pixel Art]
    Changes the sprites to be crisp instead of blurry (only works on 2.0x and 3.0x Zoom)
  • [Game Saver]
    Automatically stores copies of all played games so you never lose them
  • [Cap-Limit Info]
    Show property percentages when creating a match with a cap-limit. Also shows "relative share" values when creating ≥3-player matches with cap limits.
  • [Jade Sun Accesibility Fix]
    Modified version of the Jade Sun sprites that's easier to identify (this is primarily for color-impaired users; I am not color-impaired, myself, so I'd love feedback in the comments!)
@James-E-A
James-E-A / main.js
Created August 6, 2021 05:47
DuckDuckGo .Onion redirect
const DDG_ONION = browser.runtime.getManifest().permissions.find(p =>
p.match(/duckduckgo.*\.onion/));
const DDG_CLEARNET = browser.runtime.getManifest().permissions.find(p =>
p.match(/duckduckgo(?!.*\.onion)/))
const DDG_ONION_HOST = DDG_ONION.match(/^\*:\/\/(.+)\/\*$/)[1];
function injectOnionHeader(details) {
let u = new URL(details.url);
let h = details.responseHeaders;
u.host = DDG_ONION_HOST;
@James-E-A
James-E-A / sync-ipns-shares.sh
Last active February 20, 2022 09:15
easily sync MFS to IPNS
#!/bin/bash
set -e
rootfolder="/shares"
IFS='
'
ipfs files stat "$rootfolder" >/dev/null || (ipfs files mkdir "$rootfolder"; echo "Go to http://127.0.0.1:5001/webui#/files/$rootfolder to create new dynamic shared folders!")
for share in $(ipfs files ls "$rootfolder"); do
cid="$(ipfs files stat "$rootfolder/$share" --hash)"
ipfs key list | grep -q '^'"ipns-shares/$share"'$' || (echo "Generating new key for ipns share \"$share\""; ipfs key gen "ipns-shares/$share")
echo -n "Updating share \"$share\"... "
@James-E-A
James-E-A / extract_preview.py
Last active May 3, 2022 20:06
Extract preview image from Barotrauma .sub files
#!/usr/bin/env python3
import gzip, base64, xml.etree.ElementTree as ElementTree
# USAGE:
# cd steamapps/common/Barotrauma
# python3 extract_preview.py LocalMods/Foo/Foo.sub preview.png
# TESTED WITH SUBS GENERATED BY:
# - v0.17.12.0
@James-E-A
James-E-A / sync_to_async.js
Last active June 18, 2024 16:32
Easily execute functions in a Worker, even from file://
function offmainthread(f, options) {
// Converts long-running synchronous CPU-bound
// function or eval-able string
// into an asynchronous WebWorker-based function
// to avoid blocking the main thread.
// DOES NOT CURRENTLY SUPPORT WASM FUNCTIONS.
"use strict";
options = options || {};
try {
@James-E-A
James-E-A / async_idb.mjs
Last active June 23, 2025 18:18
easy-to-use async wrapper around indexedDB
export class IdbHandle {
#db;
#inTransaction; // This is only non-null for temporary instances created as a context "view" of a particular transaction
constructor(db, inTransaction) {
this.#db = db;
this.#inTransaction = inTransaction !== undefined ? inTransaction : null;
}
/**
* Open a new connection to a database.