Skip to content

Instantly share code, notes, and snippets.

Benjamin Bengfort bbengfort

View GitHub Profile
View PCA_Visualizer.py
import numpy as np
import matplotlib.pyplot as plt
from yellowbrick.datasets import load_credit
from sklearn.preprocessing import StandardScaler
from sklearn.decomposition import PCA
# Load data from yellowbrick.datasets
X, y = load_credit()
View squares.py
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.gridspec as grid
from mpl_toolkits.axes_grid1 import make_axes_locatable, axes_size
def joint_plot(x, y, ax=None):
"""
Create a square joint plot of x and y.
@bbengfort
bbengfort / bench.go
Last active Sep 26, 2018
Blast throughput in Go.
View bench.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 Sep 13, 2018
Create OLS example image.
View ols_plot.py
%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 Sep 11, 2018
Computes a date in the future from the current or specified date.
View fdate.py
#!/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 Sep 11, 2018
Use the `WriteAt` specification to write to a file at offsets.
View writeat.go
package main
import (
"log"
"os"
)
func main() {
var (
fobj *os.File
@bbengfort
bbengfort / aggchan.go
Created Aug 25, 2018
Aggregating reads from a go channel
View aggchan.go
package main
import (
"fmt"
"strings"
"time"
)
var (
count uint64
@bbengfort
bbengfort / reviewer_match.py
Created Aug 19, 2018
Grepping through the reviewers list to find matches
View reviewer_match.py
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 Aug 12, 2018
Benchmark ResidualsPlot performance on a large dataset
View residuals.py
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 Jun 1, 2018
Run a Jupyter notebook as a slideshow.
View slideshow.sh
#!/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
You can’t perform that action at this time.