Skip to content

Instantly share code, notes, and snippets.

@oconnor663
oconnor663 / main.rs
Last active March 14, 2022 17:36
calling conventions
#[cfg(unix)]
std::arch::global_asm!(
"with_rsp:",
"xor rax, rax",
"add rax, rdi",
"shl rsi, 1",
"add rax, rsi",
"shl rdx, 2",
"add rax, rdx",
"shl rcx, 3",
@oconnor663
oconnor663 / _readme.md
Last active March 4, 2022 17:43
running blake3-py tests against the proposed hashlib implementation
@oconnor663
oconnor663 / ownership_and_defer.zig
Created January 28, 2022 17:58
An example of how defer/errdefer interacts with ownership.
const std = @import("std");
const Allocator = std.mem.Allocator;
const ArrayList = std.ArrayList;
const Person = struct {
pet: Pet,
const Self = @This();
// Takes ownership of pet.
@oconnor663
oconnor663 / ..json_parsing_examples
Last active January 26, 2022 22:19
JSON parsing examples
We couldn’t find that file to show.
@oconnor663
oconnor663 / Cargo.toml
Created November 21, 2021 23:26
HKDF collision between different salts
[package]
name = "scratch"
version = "0.1.0"
edition = "2021"
[dependencies]
hex = "0.4.3"
hkdf = "0.11.0"
sha2 = "0.9.8"
@oconnor663
oconnor663 / _windows_scripts
Last active November 14, 2021 03:36
windows scripts
.
const PYTHON_PROGRAM: &str = r#"
import sys
print("something for stdout")
print("something for stderr", file=sys.stderr)
"#;
fn main() {
let logf = std::fs::File::create("logfile.txt").unwrap();
duct::cmd!("python", "-c", PYTHON_PROGRAM)
@oconnor663
oconnor663 / sha256_debugging.txt
Last active October 26, 2021 17:21
SHA-256 round-by-round debugging info for the empty input
message: b''
padded message:
b'\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' +
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' +
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' +
b'\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
message schedule: [
2147483648, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
2147483648, 0, 2117632, 0, 570427392, 0, 84448578, 2147483648,
@oconnor663
oconnor663 / main.rs
Last active October 22, 2021 23:39
Rust in 59 seconds
use rand::prelude::*;
use std::io::prelude::*;
fn main() {
let random = thread_rng().gen_range(1..=100);
println!("Guess a number between 1 and 100");
for line in std::io::stdin().lock().lines() {
let parsed = line.expect("io error").parse::<i64>();
let guess = if let Ok(n) = parsed { n } else { continue };
if guess < random {
@oconnor663
oconnor663 / .Krastorio 2 Blueprints
Created October 18, 2021 05:31
Krastorio 2 blueprints
0eNrdnU1uI8kRRq/S4NIgB5X/mVrM1gtvDXhhDASKqpYKTZFykWxMe6AD+B4+mU/iojgtlqQKfl9G99geb2YgNvWYVRkvKvJHyV9mN+tD+9h3m/31zXb7aXb1y/mV3ezqr6Mfj//Wrbab08u77m6zXB9f2395bGdXs27fPszms83y4fjT5rBat8t+0bfL1X7bz57ms25z2/48uzJPP81n7Wbf7bv2hHr+4cv15vBw0/bDG14g6+1dt9t3q8Xqvt3tFwOp+9wuHvvt5+52eOd89rjdDZjt5tiMIzqkH8J89mV2tfDuh/D0NH8Hty/wbrNr+z3C2AEzn912fbs6vcNPQJ3U4r7922H4//SH5Fdtnc9+ffP1x249/Mbp1ny9Zy8fcOiXm+7wsPh4aNeLVbteD+TV9nDsneHGTrTNUxec31zw0M37fru+vmnvl5+7of+GN666fnXo9tfDv92+/PbHrh+a/C4YPnf9/rBcn+Ph9I7hhtzOTvjdfnlsdHP84eFx2S+PUXI1+9c//jl7Or1jc7rluyPWHP9z/OVRvHTDT2G45uHd289t3w8xcT1QV5+G5vy9Pd6P93cjnBt0uBne/HwZ7+9HNF97hm/KODCOP6c3P9tk373iTs3ftN3d/c328Nzpw/vmw79M9WXUxFl0/5E4S0ycjdry/x1nWZ/Dokc5rFC32tflMNO8UD/1iyGWhn5/7B7bxX67uOuHnr+d+JAmvnyIoT7ETH/IZXQzfRvMOZfft8v9ov15db/c3E3ejeac4Bqime41WWpifnX1UyDPgQoEBQpkGgiKHMhAUOLv/ojG3P3MNdHCJhYO5BDINhXX6muu1RquiR420XKgAEFc7JsIQVzsmwRBgU4aBiYNG3lYgrDEXSLME5YMeZgnbKmI1FITqa6hmmhhBnJcyFuYgVxF/re26lo5ByzMQI5zwMIM5Lj8b2GecFz+tzBPuIr8P6Ixd5+TwcIM5Lj8b2EG8hX531ZVGp6UAWYQz+V/CzOI52LfQc89F/sOeu4