Skip to content

Instantly share code, notes, and snippets.

@jstrong-tios
jstrong-tios / async-throttle.rb
Created May 1, 2019 18:00
bare-bones example with concurrent-ruby gem of async io with limiting in flight requests to an arbitrary size
#!/usr/bin/env ruby
require 'json'
require 'date'
require 'http'
require 'concurrent'
# I could not get bundle to install the 'concurrent-edge' gem so I just
# grabbed a couple classes I needed. code for Concurrent::Throttle is here:
# https://github.com/ruby-concurrency/concurrent-ruby/blob/master/lib-edge/concurrent/edge/throttle.rb
@jstrong-tios
jstrong-tios / dthr.rs
Last active November 22, 2019 15:51
hourly/daily integer wrapper types
use std::fmt::{self, Debug, Display};
use std::convert::TryFrom;
use chrono::{NaiveDate, NaiveTime, NaiveDateTime, Timelike};
/// Represents number of hours since 1970
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone,
Hash, Copy, Serialize, Deserialize)]
pub struct DtHr(pub i32);
/// Represents number of days since 1970. Note: will break on June 6, 2149
@jstrong-tios
jstrong-tios / urlencode.py
Created July 23, 2020 20:40
command line tool for url-encoding text - takes either stdin or arguments
#!/usr/bin/python3
import fileinput
import copy
import sys
special_chars = "! # $ & ' ( ) * + , / : ; = ? @ [ ]".split()
replacements = "%21 %23 %24 %26 %27 %28 %29 %2A %2B %2C %2F %3A %3B %3D %3F %40 %5B %5D".split()
def encode(line: str) -> str:
encoded = copy.copy(line)