Skip to content

Instantly share code, notes, and snippets.

View dbyr's full-sized avatar
🈳

David Byrne dbyr

🈳
  • Australia, Sydney
View GitHub Profile
@dbyr
dbyr / random_from_stream.rs
Last active July 15, 2020 08:39
I came up with an algorithm that provably selects a value at random in a completely balanced and fair manner from an iterator (applicable to streams too) of indeterminate length. I tried searching (admittedly briefly) for such an algorithm but didn't find anything, so I thought I'd publish this gist in case it's never been done before (which I d…
use std::iter::Iterator;
use rand; // requires the rand crate
use rand::Rng;
use std::f64;
// I came up with this little algorithm because it seems
// (as far as I could google) there are no simple methods
// for selecting a single value randomly _and_ fairly
// from a variable-size stream/iterator in a single pass.
@dbyr
dbyr / query.py
Last active September 17, 2022 02:22
A demonstration of a request to AWS's DynamoDB (in this case, a query) that does not use boto3. In benchmark tests this script outperforms boto3 in regards to time to complete a query.
import sys, os, base64, datetime, hashlib, hmac
import requests
import json
from typing import *
# based on the example python code found here:
# https://docs.aws.amazon.com/general/latest/gr/sigv4-signed-request-examples.html
# call this method to query all items for a given primary hash key in a table
# endpoint: the DynamoDB endpoint to query (for AWS servers, this is "https://dynamodb.{region}.amazonaws.com/")
@dbyr
dbyr / main.rs
Last active January 9, 2020 04:25
My first attempt at implementing a linked list in Rust. The basic structure is based off the linked list found in the "rust by example" instruction docs. I have added some extra methods to make the implementation more complete.
mod linked_list {
use std::fmt::Display;
use std::default::Default;
type Next<V> = Option<Box<Node<V>>>;
struct Node<V> {
val: V,
next: Next<V>,
}
@dbyr
dbyr / main.rs
Last active January 7, 2020 00:18
A first attempt by a beginner rustacean to create a generic sorting algorithm
mod sort {
fn insert_from_right<S>(vals: &mut [S], left: usize, right: usize) where S: Clone {
let mut i = right;
let mut temp;
while i > left {
temp = vals[i].clone();
vals[i] = vals[i - 1].clone();
vals[i - 1] = temp;
i -= 1;
}
@dbyr
dbyr / n2-vocab.txt
Created January 20, 2019 03:28
Anki study card import file (vocabulary up to N2). Import using '#' as the delimiting character. Compiled into anki-friendly format from https://jlptstudy.net/N2/?vocab-list
あっ#あっ#Ah!, Oh!#int
ああ#ああ#like that, that way#int
愛#あい#love#n,n-suf,vs
あいかわらず#あいかわらず#as ever, as usual, the same#adv,n
挨拶#あいさつ#greeting, salutation#n,vs
愛情#あいじょう#love, affection#n
合図#あいず#sign, signal#n,vs
アイスクリーム#アイスクリーム#ice cream#n
愛する#あいする#to love#vs-s
間#あいだ#space, room, time#n
@dbyr
dbyr / javatest.sh
Created January 5, 2019 00:42
Since university programming assignments often require "input/output" type of programming, I have made this simple script to run any number of input/output tests on a Java program.
#!/bin/bash
# this script will run input/output tests for java programs
USAGE="Usage:
javatest.sh <progpath> <inputs_folder_path> <expected_outputs_folder_path>
The names of the input files is expected to be the same as the name of the corresponding expected output files."
if [[ $# != 3 ]]; then