This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/escape#return_value | |
const R = /(^[0-9a\-zA-Z]|[,-=<>#&!%:;@~'`"])|([\^\$\\\.\*\+\?\(\)\[\]\{\}\|\/])|([\t\f\n\v\r\x20])|((?![\u0000-\u007f])\s)|([\ud800-\udbff](?=$|[^\udc00-\udfff])|(?<=^|[^\ud800-\udbff])[\udc00-\udfff])/g; | |
const W = { "\u0009": '\\t', "\u000c": '\\f', "\u000a": '\\n', "\u000b": '\\v', "\u000d": '\\r', "\u0020": '\\x20' }; | |
export function escape(s) { | |
if (typeof s !== 'string') | |
throw new TypeError("input argument must be a string") | |
return s.replaceAll( | |
R, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script type="text/javascript">(async () => { | |
const currentScript = document.currentScript; // scoped to this IIFE, does not pollute global namespace or vanish on future event loop ticks | |
// You are 100% free to do async stuff in this block | |
console.info(await 42); | |
// ... // | |
})().then((value) => {if (value) !== undefined console.debug(value);});</script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A nonnegative integer. | |
* @typedef {number} NaturalNumber | |
*/ | |
/** | |
* Datatype representing a polynomial as an array of coefficients. | |
* e.g. "5X^3 + X + 2" is represented by [2, 1, , 5]. | |
* e.g. "0" is represented by []. | |
* Must have no trailing zeroes. Array slots containing 0 are equivalent to empty (sparse) array slots. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Calculate the number of days since the start of the Gregorian calendar. | |
* @param {Date} [date] - The reference date. Defaults to the current instant. | |
* @param {boolean} [useLocalTime] - Whether to calculate in local time. WARNING: By default, UTC is used; this will, for instance, give a Tuesday result when run at 10pm on a Monday in the United States. | |
* @returns {number} | |
*/ | |
export function gregorianDateInteger(d, useLocalTime) { | |
if (d === undefined) d = new Date(); | |
if (useLocalTime === undefined) useLocalTime = false; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import threading | |
def _thread_start_immed(*a, **k): | |
"""Usage: | |
@_thread_start_immed("my background thread") | |
def t(name): | |
import time | |
time.sleep(3) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const END_OF_FIELD = Symbol('\u001f'); | |
const END_OF_RECORD = Symbol('\u001e'); | |
export async function* csv_iterate(text_stream) { | |
// public iterator. | |
if (typeof text_stream === 'string') | |
text_stream = [text_stream]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
__all__ = ['logical_xor'] | |
def logical_xor(a, b): | |
# technically, all of the parentheses on the following line may be removed | |
return ((not b) and a) or ((not a) and b) | |
# correct | |
assert logical_xor(True, False) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def is_dir_writable(path='.', *, _q=None): | |
import multiprocessing as mp | |
from queue import Empty | |
import tempfile | |
if _q is None: | |
# caller | |
_q = mp.Queue() | |
p = mp.Process( | |
target=is_dir_writable, # IF YOU RENAME THE FUNCTION ENSURE YOU ALSO RENAME ITS INVOCATION HERE | |
args=[path], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ctypes | |
from ctypes import GetLastError, WinError, byref, create_unicode_buffer | |
from uuid import UUID | |
__all__ = ['wintypes_GUID'] | |
_CLSIDFromString = ctypes.windll.Ole32['CLSIDFromString'] | |
_CLSIDFromString.argtypes = [ctypes.c_wchar_p, ctypes.c_void_p] | |
_CO_E_CLASSSTRING = ctypes.c_int(0x800401F3).value # nominally positive, but physically negative on most platforms |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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/ |
NewerOlder