Skip to content

Instantly share code, notes, and snippets.

View bbengfort's full-sized avatar
🎯
Focusing

Benjamin Bengfort bbengfort

🎯
Focusing
View GitHub Profile
@bbengfort
bbengfort / bench.go
Last active September 26, 2018 21:50
Blast throughput in Go.
type Blast struct {
requests uint64 // the number of successful requests
failures uint64 // the number of failed requests
started time.Time // the time the benchmark was started
duration time.Duration // the duration of the benchmark period
latencies []time.Duration // observed latencies in the number of requests
}
// Run N operations against the server at addr by putting a unique key with
// random values of size S. Returns a Benchmark object whose objects can be
@bbengfort
bbengfort / ols_plot.py
Created September 13, 2018 13:22
Create OLS example image.
%matplotlib inline
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
from sklearn.datasets import make_regression
from sklearn.preprocessing import StandardScaler
from matplotlib.patches import Rectangle
@bbengfort
bbengfort / fdate.py
Created September 11, 2018 21:42
Computes a date in the future from the current or specified date.
#!/usr/bin/env python3
import argparse
from datetime import datetime, timedelta
try:
from dateutil.relativedelta import relativedelta
except ImportError:
relativedelta = None
@bbengfort
bbengfort / writeat.go
Last active September 11, 2018 13:34
Use the `WriteAt` specification to write to a file at offsets.
package main
import (
"log"
"os"
)
func main() {
var (
fobj *os.File
@bbengfort
bbengfort / aggchan.go
Created August 25, 2018 12:20
Aggregating reads from a go channel
package main
import (
"fmt"
"strings"
"time"
)
var (
count uint64
@bbengfort
bbengfort / reviewer_match.py
Created August 19, 2018 19:00
Grepping through the reviewers list to find matches
import csv
from tabulate import tabulate
from operator import itemgetter
from collections import Counter
def parse_inner_csv(val):
return list(
map(lambda s: s.strip(), val.lower().split(","))
@bbengfort
bbengfort / residuals.py
Created August 12, 2018 13:30
Benchmark ResidualsPlot performance on a large dataset
import time
import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets import make_regression
from sklearn.model_selection import train_test_split as tts
from sklearn.linear_model import LinearRegression
from yellowbrick.regressor import ResidualsPlot
@bbengfort
bbengfort / slideshow.sh
Created June 1, 2018 11:42
Run a Jupyter notebook as a slideshow.
#!/bin/bash
# Execute the reveal.js slides form of a Notebook
# Make sure the first argument to this script is a notebook
if [ "$#" -ne 1 ]; then
echo "Usage: ./slideshow.sh Notebook.ipynb"
exit 1
fi
# Make sure the notebook exists
@bbengfort
bbengfort / mahalanobis.py
Created May 29, 2018 17:20
Draws the mahalanobis figure
#!/usr/bin/env python
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Ellipse, Circle
np.random.seed(42)
def draw_mahalanobis(path="atap_ch06_mahalanobis_distance.png"):
@bbengfort
bbengfort / distances.py
Created May 29, 2018 15:58
Generates taxicab vs. euclidean distance graphic
#!/usr/bin/env python
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator, FormatStrFormatter
def draw_distances(path="atap_ch06_euclidean_manhattan_distance.png"):