Skip to content

Instantly share code, notes, and snippets.

class Option<T> {
private readonly value?: T;
constructor(value?: T) {
this.value = value;
}
public isSome() {
return this.value !== void 0;
}
@tynor
tynor / genpw.py
Created July 23, 2019 01:19
Generates passwords with specific symbol sets to better follow wild requirements.
#!/usr/bin/env python3
import argparse
import itertools
import os
import random
import string
import sys
@tynor
tynor / results.txt
Last active November 10, 2018 23:05
Lookup in list vs dict
.....................
dict[int]: Mean +- std dev: 28.2 ns +- 1.3 ns
.....................
list[int]: Mean +- std dev: 105 ns +- 5 ns

git b (. ~/.githelpers && pretty_git_branch):

   lockr-api-cp  122e757  (12 days)  <Tynor Fujimoto>  Add barebones lockr-api capnp schema
*  master        f464998  (12 days)  <Tynor Fujimoto>  Merge branch 'lockr-api-storage'

git l (. ~/.githelpers && pretty_git_log):

*   f464998  (12 days)  <Tynor Fujimoto>   (HEAD -> master, origin/master) Merge branch 'lockr-api-storage'

|\

Keybase proof

I hereby claim:

  • I am tynor on github.
  • I am tynor (https://keybase.io/tynor) on keybase.
  • I have a public key ASAFpOInxl1C-VVjj9GgO3GAKT3CqhmYfg-qPqDUktQwuwo

To claim this, I am signing this object:

@tynor
tynor / map.rs
Last active February 21, 2017 00:04
map.iter() // Get an iterator over the map as (key, value) pairs: Iter<K, V>
.find(|&(k, _)| *k >= index) // Find the first key that is greater than the desired index: Option<(&K, &V)>
.map(|(_, v)| v) // Extract the value from (key, value): Option<&V>
.or_else(|| map.values().next()) // If an index was not found, just get the first value: Option<&V>
map.range(index..) // Get an iterator over the map, starting at the first node equal to or greater than index: Range<K, V>
.map(|(_, v)| v) // Extract the value from (key, value): Option<&V>
.or_else(|| map.values().next()) // If an index was not found, just get the first value: Option<&V>
@tynor
tynor / years.sql
Last active December 8, 2016 03:21
CREATE TABLE years (
id uuid PRIMARY KEY,
start_date date NOT NULL,
end_date date NOT NULL,
CHECK (start_date < end_date),
CONSTRAINT overlapping_dates EXCLUDE USING GIST (
box(
point(date_part('epoch', start_date), date_part('epoch', start_date)),
// ex:ts=4:sts=4:sw=4:et:
#![allow(dead_code, unused_variables)]
use std::io::Result;
use byteorder::{ByteOrder, LittleEndian};
use mio::TryRead;
use super::util::{PartialUsize, bytes_into_words, fill_vec, parse_u32};
fn parse_seg_count<R: TryRead>(&mut self,
mut stream: R,
off: usize,
scratch: usize) -> Result<Option<Message>> {
match try!(parse_u32(&mut stream, off, scratch)) {
PartialUsize::More(off, scratch) => {
self.state = State::SegCount(off, scratch);
Ok(None)
}
PartialUsize::Done(seg_count) => {
package main
import (
"bytes"
"compress/gzip"
"fmt"
"io"
"net/http"
"os"
"time"