Skip to content

Instantly share code, notes, and snippets.

@oconnor663
oconnor663 / two_tables.py
Last active August 22, 2018 20:49
two tables in sqlite
#! /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 / Cargo.toml
Last active March 15, 2019 21:31
Rust HN fetch example
[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 / main.rs
Last active March 16, 2019 06:38
HN example without crossbeam
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 / lib.rs
Created March 25, 2019 19:09
slice reverse benchmark
#![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
Created April 2, 2019 22:28
relaxed atomics
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 / main.rs
Created April 3, 2019 22:09
dirty JSON with nom
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 / data.txt
Created April 21, 2019 16:33
BLAKE2bp throughput varying across input byte offset
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
Last active June 5, 2019 19:45
interior pointers examples
fn bump_smaller(x: &mut i32, y: &mut i32) {
if *x <= *y {
*x += 1;
} else {
*y += 1;
}
}
fn main() {
// example with variables
@oconnor663
oconnor663 / Cargo.toml
Created September 23, 2019 13:37
hash function benchmarks
[package]
name = "scratch"
version = "0.1.0"
edition = "2018"
[dependencies]
rayon = "1.2.0"
blake2s_simd = "0.5.8"
@oconnor663
oconnor663 / Cargo.toml
Last active October 9, 2019 19:38
Windows race test
[package]
name = "race"
version = "0.1.0"
authors = ["Jack O'Connor <oconnor663@gmail.com>"]
edition = "2018"
[dependencies]
os_pipe = "0.9.0"
[[bin]]