Skip to content

Instantly share code, notes, and snippets.

Avatar

Jack O'Connor oconnor663

View GitHub Profile
View hash_to_digits.py
#! /usr/bin/python3
import sys
from hashlib import sha256
def ten_digits_from_u64(n):
assert len(str(2**64)) == 20
assert n < 2**64
s = "{:020}".format(n)
View gist:6c44a6a8a5a10705cdb00130246b37e9
Compiling cc v1.0.55
Compiling example v0.1.0 (/home/jacko/tmp/sanitizer_example)
warning: src/oops.c:5:12: warning: address of stack memory associated with local variable 'local_array' returned [-Wreturn-stack-address]
warning: return local_array;
warning: ^~~~~~~~~~~
warning: 1 warning generated.
error: linking with `cc` failed: exit code: 1
|
= note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "/home/jacko/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/home/jacko/tmp/sanitizer_example/target/debug/deps/example-9c8dfc3293cab709.29uisxezum6f4udt.rcgu.o" "/home/jacko/tmp/sanitizer_example/target/debug/deps/example-9c8dfc3293cab709.2hvzw3qk092jmz19.rcgu.o" "/home/jacko/tmp/sanitizer_example/target/debug/deps/example-9c8dfc3293cab709.2vwfxc7xli1op523.rcgu.o" "/home/jacko/tmp/sanitizer_example/target/debug/deps/example-9c8dfc3293cab709.2ymvkyqxyu1kfubm.rcgu.o" "/home/jacko/tmp/sanitizer_example/target/debug/deps/example-9c8dfc32
@oconnor663
oconnor663 / gist:a5a667b6955afbcafc0e32a8b6e1b7a0
Created Apr 17, 2020
[Gloomhaven] A micro-optimization of the POWER build for the Triforce class
View gist:a5a667b6955afbcafc0e32a8b6e1b7a0
A micro-optimization of the POWER build described as described by
Themris in https://imgur.com/gallery/xoBunR9. Disclaimer, I haven't
played the Triforce all the way through yet, so I'm making a lot of this
up / leaning on the original guide. Also a mild *item spoiler* below.
Observations:
1. The choice of Simulacrum at level 6 is a weak point in the POWER
build. COURAGE and WISDOM retain it in their final builds, but POWER
is going to drop it just 3 levels later.
View gist:5c5a87db3c35dd2d49e054b1aa123150
C:\Users\Jack\pyo3\examples\word-count>cargo +nightly build --release
Compiling proc-macro2 v1.0.9
Compiling unicode-xid v0.2.0
Compiling syn v1.0.16
Compiling autocfg v1.0.0
Compiling lazy_static v1.4.0
Compiling cfg-if v0.1.10
Compiling semver-parser v0.7.0
Compiling memchr v2.3.3
Compiling scopeguard v1.1.0
@oconnor663
oconnor663 / test.py
Last active Oct 23, 2020
A demonstration of GIL-releasing hashing leading to a data race in Python
View test.py
#! /usr/bin/env python3
import hashlib
import threading
def hash_buf(buf):
return hashlib.blake2b(buf).hexdigest()
@oconnor663
oconnor663 / b3sum.go
Created Feb 12, 2020
a simple "hash stdin" CLI program using zeebo/blake3
View b3sum.go
package main
import (
"encoding/hex"
"fmt"
"io"
"os"
"github.com/zeebo/blake3"
)
View gist:4c4350aa409ba16532d2257676da2d94
# dmidecode 3.2
Getting SMBIOS data from sysfs.
SMBIOS 3.2.1 present.
# SMBIOS implementations newer than version 3.2.0 are not
# fully supported by this version of dmidecode.
Handle 0x0052, DMI type 16, 23 bytes
Physical Memory Array
Location: System Board Or Motherboard
Use: System Memory
@oconnor663
oconnor663 / main.rs
Created Dec 22, 2019
sampling what rdtsc reports for the clock frequency (often wrong)
View main.rs
fn ticks() -> u64 {
let mut discard = 0;
unsafe { core::arch::x86_64::__rdtscp(&mut discard) }
}
fn main() {
let t0 = std::time::Instant::now();
let c0 = ticks();
std::thread::sleep(std::time::Duration::from_secs(1));
let t1 = std::time::Instant::now();
@oconnor663
oconnor663 / main.c
Created Nov 10, 2019
Libsodium crypto_generichash demo
View main.c
#include <sodium.h>
#include <stdio.h>
#include <unistd.h>
int main() {
if (sodium_init() < 0) {
printf("init error\n");
return 1;
}
unsigned char hash[crypto_generichash_BYTES];
@oconnor663
oconnor663 / benches.txt
Last active Nov 3, 2019
baokeshed benchmarks
View benches.txt
AWS t3.nano (AVX-512)
=====================
# baokeshed
test bench_compress64_portable ... bench: 117 ns/iter (+/- 4) = 1094 MB/s
test bench_compress_portable ... bench: 84 ns/iter (+/- 3) = 761 MB/s
test bench_compress_sse41 ... bench: 69 ns/iter (+/- 2) = 927 MB/s
test bench_fficompress64_portable ... bench: 105 ns/iter (+/- 2) = 1219 MB/s
test bench_fficompress_avx512 ... bench: 59 ns/iter (+/- 1) = 1084 MB/s
test bench_fficompress_portable ... bench: 93 ns/iter (+/- 4) = 688 MB/s