Skip to content

Instantly share code, notes, and snippets.

Jack O'Connor oconnor663

Block or report user

Report or block oconnor663

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@oconnor663
oconnor663 / main.rs
Last active Jun 5, 2019
interior pointers examples
View main.rs
fn bump_smaller(x: &mut i32, y: &mut i32) {
if *x <= *y {
*x += 1;
} else {
*y += 1;
}
}
fn main() {
// example with variables
@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
You can’t perform that action at this time.