Skip to content

Instantly share code, notes, and snippets.

View zackw's full-sized avatar
🦉
current priorities: (0) day job (1) libxcrypt (2) iclab (3) everything else

Zack Weinberg zackw

🦉
current priorities: (0) day job (1) libxcrypt (2) iclab (3) everything else
View GitHub Profile
@zackw
zackw / revise-iso-c-5.1.2.md
Last active May 27, 2018 18:45
Draft revision to ISO C section 5.1.2

5.1.2 Execution environments

p1 Two execution environments are defined: freestanding and hosted. The implementation shall provide a freestanding environment, and may also provide a hosted environment.

p2 In both environments, all of the facilities of the language (clause 6) are available. In a hosted environment, all of the facilities of the library (clause 7) are also available. In a freestanding environment, the set of library facilities

@zackw
zackw / deserialize.rs
Created May 24, 2017 13:34
I think this works
pub fn deserialize(bytes: &[u8]) -> Result<Self, AlchemistError> {
let key_length = bytestou32(&bytes[0..4]) as usize;
let value_length = bytestou32(&bytes[4..8]) as usize;
let maybe_key = String::from_utf8(bytes[8 .. 8 + key_length].to_vec());
let maybe_value = String::from_utf8(bytes[8 + key_length .. 8 + key_length + value_length].to_vec())
match (maybe_key, maybe_value) {
(Ok(ref key), Ok(ref value)) => Ok(Self::new(key, value)),
_ => Err(AlchemistError::DeserializationFailed)
}
}
# Get nwquantbyage.csv from https://dqydj.com/wp-content/uploads/2015/03/nwquantbyage.csv
library(reshape2)
library(ggplot2)
library(scales)
library(viridis)
biexp2_trans <- function(lim = 100, decade.size = lim)
{
trans <- function(x){
ifelse(abs(x) <= lim,
@zackw
zackw / shapely-pole-crossing-bug.ipynb
Created June 29, 2016 15:02
Shapely pole-crossing bug
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@zackw
zackw / jobspawntest.py
Last active January 1, 2016 01:06
subprocess.Popen wrapper that kills descendants on subprocess exit
#! /usr/bin/env python
# jobspawntest.py - experimental subprocess.Popen wrapper that kills
# descendants on subprocess exit. Windows testing needed.
# Copyright 2015 Zack Weinberg <zackw@panix.com>
# Copying and distribution of this file, with or without modification,
# are permitted in any medium without royalty provided the copyright
# notice and this notice are preserved. This file is offered as-is,
# without any warranty.
@zackw
zackw / EXPLANATION.md
Last active November 27, 2015 15:43
Determine what, exactly, re.compile("\w", re.UNICODE) matches

Which Unicode characters does Python's regular expressions' \w escape match?

It appears that the intent of UNICODE \w in both Python 2 and 3 is to match every character in Unicode general categories L* and N*, plus U+005F ('_'). However, in 2.7 the re module's idea of the Unicode database is a little bit out of sync with the unicodedata module, such that four astral characters in category Nl are not matched when they should be:

  • [U+012432][] CUNEIFORM NUMERIC SIGN SHAR2 TIMES GAL PLUS DISH
@zackw
zackw / unicode-growth-rate.R
Created October 30, 2015 00:30
Compute the growth rate of Unicode.
#! /usr/bin/Rscript
suppressPackageStartupMessages({
library(ggplot2)
library(scales)
library(grid)
})
# Data from https://en.wikipedia.org/wiki/Unicode#Versions

Keybase proof

I hereby claim:

  • I am zackw on github.
  • I am zackw (https://keybase.io/zackw) on keybase.
  • I have a public key whose fingerprint is 82F8 54F3 CE73 174B 8B63 1740 91FC C32B 6769 AA64

To claim this, I am signing this object:

@zackw
zackw / cheatsheet.tex
Created November 15, 2013 00:09
Authenticated encryption mode cheatsheet, aka figure 2 from Bellare and Namprempre 2000.
% This is a visually redesigned version of a table from “Authenticated
% encryption: Relations among notions and analysis of the generic
% composition paradigm.” by Mihir Bellare and Chanathip Namprempre
% (ASIACRYPT 2000). The content is entirely theirs.
% I (Zachary Weinberg) disclaim any copyright interest I might have in
% this redesigned version.
\documentclass[10pt]{article}
\usepackage[letterpaper,margin=0.5in]{geometry}
\usepackage{microtype}
\usepackage{pxfonts}