[DRAFT] Ghetto Guide to CMS

*and by "ghetto", I mean "extremely applied". Basically, it's just interpretive labor on RFC 5652: Cryptographic Message Syntax and RFC 5280: X.509. P.S. CMS is way more technically elegant than PGP. I dare you to read the RFC and compare. Firstly: the "root object" that you'll be shitting nakedly into a binary (or ASCII-armored) file that sits in the filesystem or gets otherwise transferred is a ContentInfo data stream. …

Javascript: calling asynchronously-initialized libraries from synchronous code

With the power of await, this isn't so difficult: let nacl, scrypt; function main() { /* Synchronous code that calls nacl and scrypt */ } (async () => { [nacl, scrypt] = await Promise.all([new Promise(nacl_factory.instantiate), new Promise(scrypt_module_factory)]); return main(); })();

Auto-updating userscripts hosted on Github Gist

In the process of crafting this small set of improvements to Advance Wars By Web, I found out about the proper URL for auto-updating userscripts which are hosted on Microsoft's "Gist" service: // @updateURL https://gist.githubusercontent.com/USERNAME/GIST_ID/raw/FILENAME.user.js This will always redirect to the latest version of the file.

Javascript: getElementByXPath

function getElementByXPath(path, context=null, _document=undefined) { if( _document === undefined ) _document = document; let res = document.evaluate(path, _document, context, XPathResult.FIRST_ORDERED_NODE_TYPE); if( !res ) return null; return res.singleNodeValue; } function getTextByXPath(path, context=null, _document=undefined) { let e = getElementByXPath(path, context, _document); if( !e ) return undefined; return e.textContent; } function getTextByQuerySelector(selector) { let e = document.querySelector(selector); if( !e ) return undefined; return e.textContent; }

Python: Using XOFs for general-purpose Random

As always, one's own stack overflow answers make the best blog posts. In this case, we craft a version of random.Random with a few modifications: Pulls its data from an arbitrary stream (in our case, a DRBG such as a hash function or deterministic CSPRNG) Is slightly more efficient at generating random integers Has fixed code for .shuffle, on the offchance CPython ever changes theirs, and to make it work …

Python: Rounding fractions half-up

By default, Python's fractions.Fraction rounds halves to the nearest even number. If you, instead, want to round a fraction but send halves up, here's how that's done: from math import floor from fractions import Fraction def roundhalfup(x: Fraction) -> int: """ Rounds x to the nearest integer, with ties being rounded towards positive infinity """ return floor(x + Fraction(1, 2)) def divroundhalfup(a: int, b: int) -> int: """ Returns the …

My WordPress custom CSS

Posted for administrative use as well as archive/reference /* Customizations */ .site-title a { text-decoration: none; } .entry-content aside { font-style: italic; display: inline; } .entry-content .language-python, .entry-content .language-javascript { tab-size: 4; -moz-tab-size: 4; } .entry-content .language-sql, .entry-content .language-css { tab-size: 2; -moz-tab-size: 2; } .entry-content.category-transcript a { color: revert; } body.page-id-1388 { background: url('https://timecube.2enp.com/grid.gif'); } body.page-id-1388 #canvas, body.page-id-1388 #page{ background: revert; } /* undo weird Suki design choices …