Skip to content

Instantly share code, notes, and snippets.

Jack O'Connor oconnor663

View GitHub Profile
@oconnor663
oconnor663 / data.txt
Created Apr 21, 2019
BLAKE2bp throughput varying across input byte offset
View data.txt
0 1.003
1 1.006
2 1.002
3 1.006
4 1.008
5 1.009
6 1.008
7 1.008
8 1.006
9 1.008
@oconnor663
oconnor663 / main.rs
Created Apr 3, 2019
dirty JSON with nom
View main.rs
use nom::types::CompleteStr;
use nom::*;
use std::collections::HashMap;
#[derive(Clone, Debug)]
enum Value {
Num(f64),
String(String),
List(Vec<Value>),
Object(HashMap<String, Value>),
@oconnor663
oconnor663 / main.rs
Created Apr 2, 2019
relaxed atomics
View main.rs
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::mpsc::sync_channel;
use std::sync::{Arc, Barrier};
static MY_ORDERING: Ordering = Ordering::Relaxed;
static A: AtomicBool = AtomicBool::new(false);
static B: AtomicBool = AtomicBool::new(false);
fn main() {
@oconnor663
oconnor663 / lib.rs
Created Mar 25, 2019
slice reverse benchmark
View lib.rs
#![feature(test)]
extern crate test;
use std::ptr;
use test::Bencher;
pub fn reverse_slice_orig<T>(s: &mut [T]) {
let mut i: usize = 0;
let ln = s.len();
@oconnor663
oconnor663 / main.rs
Last active Mar 16, 2019
HN example without crossbeam
View main.rs
use serde::Deserialize;
use std::sync::{Arc, Mutex};
const STORIES_URL: &str = "https://hacker-news.firebaseio.com/v0/topstories.json";
const ITEM_URL_BASE: &str = "https://hacker-news.firebaseio.com/v0/item";
#[derive(Deserialize)]
struct Story {
title: String,
}
@oconnor663
oconnor663 / Cargo.toml
Last active Mar 15, 2019
Rust HN fetch example
View Cargo.toml
[package]
name = "fetch_hn"
version = "0.1.0"
edition = "2018"
[dependencies]
serde = { version = "1.0.89", features = ["derive"] }
reqwest = "0.9.11"
crossbeam-utils = "0.6.5"
@oconnor663
oconnor663 / two_tables.py
Last active Aug 22, 2018
two tables in sqlite
View two_tables.py
#! /usr/bin/python3
import os
import sqlite3
import time
filename = "two_tables.db"
# Delete the db file so we can recreate it from scratch.
if os.path.exists(filename):
@oconnor663
oconnor663 / b2sum.c
Last active Aug 10, 2018
libsodium example
View b2sum.c
#include <sodium.h>
#include <stdio.h>
#include <unistd.h>
#define BUFSIZE 65536
#define HASHSIZE 32
int main() {
if (sodium_init() == -1) {
return 1;
@oconnor663
oconnor663 / cycle.py
Last active May 21, 2018
the 100 prisoners problem
View cycle.py
import itertools
import random
def cycle_len(boxes, num):
steps = 1
position = num
while boxes[position] != num:
steps += 1
position = boxes[position]
return steps
@oconnor663
oconnor663 / blake2b.rs
Last active Jun 21, 2018
toy blake2b implementation
View blake2b.rs
extern crate byteorder;
use byteorder::{ByteOrder, LittleEndian};
type Digest = [u8; OUTBYTES];
pub const BLOCKBYTES: usize = 128;
pub const OUTBYTES: usize = 64;
pub const KEYBYTES: usize = 64;
pub const SALTBYTES: usize = 16;
You can’t perform that action at this time.