Skip to content

Instantly share code, notes, and snippets.

View zbjornson's full-sized avatar

Zach Bjornson zbjornson

View GitHub Profile
@zbjornson
zbjornson / macos-10.15
Created July 22, 2022 00:57
Output of `sysctl -a | grep machdep.cpu` for all of the macos versions for GitHub-hosted runners
machdep.cpu.max_basic: 13
machdep.cpu.max_ext: 2147483656
machdep.cpu.vendor: GenuineIntel
machdep.cpu.brand_string: Intel(R) Xeon(R) CPU E5-1650 v2 @ 3.50GHz
machdep.cpu.family: 6
machdep.cpu.model: 58
machdep.cpu.extmodel: 3
machdep.cpu.extfamily: 0
machdep.cpu.stepping: 9
machdep.cpu.feature_bits: 18427078393948011519
@zbjornson
zbjornson / test.js
Created September 28, 2020 22:44
Simple TOTP
//@ts-check
"use strict";
const TOTP = require("../../app/util/totp.js");
const assert = require("chai").assert;
describe("TOTP", function () {
describe("verify", function () {
it("works according to RFC6238 test vectors", function () {
// From https://www.rfc-editor.org/rfc/rfc6238.html#appendix-B
@zbjornson
zbjornson / fastvector.cc
Created August 31, 2019 20:30
Fast vector experiments
// Essentially a std::vector<uint8_t>, but uses mmap+mremap to manipulate the
// Linux page table. Not portable. Memory is not freed when the class is
// destructed; use FastVector::free.
// In some basic benchmarks, this is not faster than realloc (with glibc),
// although in principle it should provide better guarantees that data movement
// is avoided (regardless of alloc size).
#include <sys/mman.h>
@zbjornson
zbjornson / accurate.cc
Last active December 21, 2022 17:32
Code for fast, accurate float summation
#include <cstddef>
#include <cmath>
#ifdef __FAST_MATH__
#error Compensated summation is unsafe with -ffast-math (/fp:fast)
#endif
inline static void kadd(double& sum, double& c, double y) {
y -= c;
auto t = sum + y;
c = (t - sum) - y;
/**
* Jest's require() cache is reset between tests (modules are re-evaluated)
* for most, but not all modules. In the "not all" group are native modules,
* so all interactions with them must be idempotent.
* https://github.com/facebook/jest/issues/4413
*
* Encountered in https://github.com/Automattic/node-canvas/issues/1310,
* https://github.com/Automattic/node-canvas/issues/1294,
* https://github.com/Automattic/node-canvas/issues/1250
*/
@zbjornson
zbjornson / dns.js
Last active January 12, 2019 12:15
const name = "<some domain>";
const AWS = require("aws-sdk");
const route53 = new AWS.Route53();
const DNS = require("@google-cloud/dns");
const dns = new DNS({projectId: "<your project id>"});
const dnsZone = dns.zone("<zone name>");
const resolvers = [ // See note below -- set to the NS for your zone
"<dns server 1>",
"<dns server 2>"//, ...
hoistDotArgs = function(fn) {
dotCalls = list()
findDotArgs = function(exp) {
if (typeof(exp) == "closure") { # entry point
expL = as.list(exp)
args = names(expL)
if (!("..." %in% args)) return(invisible()) # no dots to hoist
body = expL[[length(expL)]]
findDotArgs(body)
@zbjornson
zbjornson / styler.js
Created May 24, 2017 20:39
Styler utility
/**
* Tool to change styles with dynamic CSS. Use instead of setting style
* properties on individual elements.
*/
function Styler() {
this.styleEl = document.createElement("style");
document.head.appendChild(this.styleEl);
// Map for quickly looking up an existing rule by its selector.
this.ruleMap = new Map();
}
@zbjornson
zbjornson / github-issues.wl
Last active December 14, 2016 03:20
GitHub Issue Charts in Mathematica
(* Common: *)
ToJSON[x_] := ImportString[FromCharacterCode[x, "Unicode"], "RawJSON"](*Ignore emoji*)
getIssues[repo_] := getIssues[repo, "*"]
getIssues[repo_, milestone_] :=
getIssues[repo, milestone] = Block[{url, head, pageCount, issues},
url = URLBuild[{"https://api.github.com/repos", repo, "issues"},
{"state" -> "all",
(*"access_token" -> "...",*) (* use for private repos, larger API quota*)
"sort" -> "created",
@zbjornson
zbjornson / EmbeddedTLB
Created August 14, 2016 20:35
SO 38945481
// Generated .IDL file (by the OLE/COM Object Viewer)
//
// typelib filename: VWorksCPPATL.dll
[
uuid(83ED4BB2-4E00-4349-AD9E-493801A0FC62),
version(1.0),
custom(DE77BA64-517C-11D1-A2DA-0000F8773CE9, 134218331),
custom(DE77BA63-517C-11D1-A2DA-0000F8773CE9, 1471199125),
custom(DE77BA65-517C-11D1-A2DA-0000F8773CE9, "Created by MIDL version 8.00.0603 at Sun Aug 14 11:25:24 2016