Skip to content

Instantly share code, notes, and snippets.


Armen Michaeli amn

View GitHub Profile
amn / MediaRecorderDataStream.js
Created Sep 23, 2021
A class of readable streams that vend data chunks generated by a media recorder
View MediaRecorderDataStream.js
export default class MediaRecorderDataStream extends ReadableStream {
constructor(recorder) {
const signaler = new AbortController(), { signal } = signaler;
start: controller => {
recorder.addEventListener("dataavailable", ev => {
}, { signal });
recorder.addEventListener("stop", ev => {
amn / uuid.js
Last active Sep 24, 2021
A [`crypto.getRandomValues` based,] "copy avoiding" UUID-4 generator for the Web
View uuid.js
export const uuid4 = () => {
const ho = (n, p) => n.toString(16).padStart(p, 0); /// Return the hexadecimal text representation of number `n`, padded with zeroes to be of length `p`
crypto.getRandomValues(new Uint8Array(16)); /// Fill a data buffer with random data
data[6] = (data[6] & 0xf) | 0x40; /// Patch the 6th byte to reflect a version 4 UUID
data[8] = (data[8] & 0x3f) | 0x80; /// Patch the 8th byte to reflect a variant 1 UUID (version 4 UUIDs are)
const view = new DataView(data.buffer); /// Create a view on the data buffer
return `${ho(view.getUint32(0), 8)}-${ho(view.getUint16(4), 4)}-${ho(view.getUint16(6), 4)}-${ho(view.getUint16(8), 4)}-${ho(view.getUint32(10), 8)}${ho(view.getUint16(14), 4)}`; /// Compile the canonical representation of the data
amn / solarized.vim
Last active Sep 19, 2021
An alternative, "austere" implementation of the Solarized color scheme for Vim
View solarized.vim
" URL:
hi clear
if exists("syntax_on")
syntax reset
let g:colors_name = "Solarized"
amn / set-security-info-by-sddl.c
Last active Mar 15, 2019
Demonstrates how using SetFileSecurity does not result in a [file] ACL with ACEs inherited from parent [folder], while using SetNamedSecurityInfo does, as is proper. Disable (comment) the `SetNamedSecurityInfo` call along with its parent `if` statement and enable (uncomment) the following `SetFileSecurity` call (and its parent `if` statement, ob…
View set-security-info-by-sddl.c
Demonstrates how using SetFileSecurity does not result in a [file] ACL with ACEs inherited from parent [folder], while using SetNamedSecurityInfo does, as is proper.
Disable (comment) the `SetNamedSecurityInfo` call along with its parent `if` statement and enable (uncomment) the following `SetFileSecurity` call (and its parent `if` statement, obviously) to switch the behavior and observe different resultant ACL on the file.
The Windows application entry point in this snippet expects two command line arguments -- the file path of the file you want to set security information on, and the actual security (specified in SDDL format) information desired for the file.
#include <windows.h>
#include <shellapi.h>
amn / IntersectionObserver.js
Created Dec 10, 2018
An implementation of IntersectionObserver class, after, with some deviations
View IntersectionObserver.js
/** An implementation of the IntersectionObserver class, as specified by There are some open issues with the later specification, but an attempt is made here to follow it to the best of ability, unless it is found too difficult to interpret -- the motivation is, after all, to have a working implementation, and as certain elements of specification weren't clarifying in themselves, these parts of implementation may turn out to be lacking or even incorrect.
This was initially written to plug in in user agents that do not provide their own implementation, like Safari on iOS 9.3.5. Hence, the used syntax flavour is such as to work in said user agent. */
IntersectionObserver = (function() {
/** Find intersection product of two rectangles `a` and `b`, itself a rectangle. Essentially, this function is the logical AND operation for rectangles. A rectangle with zero width and/or height is returned if `a` and `b` are adjacent but do not overlap in that axis. No rectangle is re
amn /
Last active Jun 1, 2017
Authentication with tokens, example
import datetime
""" Secrets, must not be shared. """
token_encrypt_decrypt_key = "<YOUR-KEY-TEXT>";
good_token_salt = "<YOUR-SALT-TEXT>";
# Placeholders: encrypt, decrypt, current_date, get_client_ipv4_addr, client_send, Error,
def make_auth_token(username, ipv4_addr, expires):
""" Compose and return an authentication token that can be given to the client (only over private [secure] channel). """
amn /
Last active Aug 4, 2016
Download fresh copy of Cygwin installer if current copy is stale, and invoke it without administration rights (user-local install)
#!/bin/sh -ue
# Usage: /path/to/ [preferred/path/to/setup-x86_64.exe]
# If first argument is omitted, this script behaves as if the value was ".", i.e. current working directory.
# If setup file exists, its extended attributes are checked to see if a property called 'etag' is attached. If it is, its value is used in HTTP request to Cygwin website to download the installer. The website will reply with "not modified, use your own copy" if etag values match, and in this case, the existing setup file will be used. This is in effect local caching of Web resources, the same thing your browser does, but through command line. The setup file is invoked with '--no-admin' option, because my Windows install is managed by crazy paranoid system administrators of our organization where even professionals are not trusted with Administrator role.
# When a fresh installer file is downloaded, an extended attribute with the name 'etag' is attached to it, value being as present in HTTP response. All this so that the c