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 / wide_argparse.py
Created November 3, 2020 14:38
Create a wider argument parser for better options on --help
def main(args):
pass
def make_wide(formatter, width=120, max_help_position=42):
"""
Increase space between arguments and help text, if possible.
See: https://stackoverflow.com/questions/5462873/
"""
try:
@bbengfort
bbengfort / zipr.py
Last active December 5, 2021 01:34
Dealing with Zip archives and json data in Python
#!/usr/bin/env python3
import os
import json
import random
import zipfile
config = {
"color": "red",
"amount": 42.24,
@bbengfort
bbengfort / ani.py
Last active October 6, 2023 03:08
Experiments with live animation using asyncio and writing to a file. Works with two different processes, but only data generator works in asyncio, not the animation itself.
import json
import random
import asyncio
import argparse
import matplotlib.pyplot as plt
import matplotlib.animation as animation
from functools import partial
@bbengfort
bbengfort / requires
Last active March 3, 2021 15:06
Automatically manage requirements.txt with Python
#!/usr/bin/env python
# requires
# Creates a requirements.txt file using pip freeze.
#
# Author: Benjamin Bengfort <benjamin@bengfort.com>
# Created: Fri Jan 22 08:50:31 2016 -0500
#
# Copyright (C) 2016 Bengfort.com
# For license information, see LICENSE.txt
#
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
from sklearn.pipeline import Pipeline
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.decomposition import LatentDirichletAllocation
from yellowbrick.datasets import load_hobbies
class LDAViz(object):
"""
@bbengfort
bbengfort / ybvid.sh
Created August 29, 2019 13:49
Make the Yellowbrick gource video
gource -1280x720 --camera-mode track --seconds-per-day 4 --auto-skip-seconds 1 \
--file-idle-time 0 --key --title "Yellowbrick" -o - | ffmpeg -y -r 60 \
-f image2pipe -vcodec ppm -i - -vcodec libx264 -preset ultrafast \
-pix_fmt yuv420p -crf 1 -threads 0 -bf 0 gource.mp4
@bbengfort
bbengfort / dist_extract.py
Created August 22, 2019 18:42 — forked from stewartm888/dist_extract.py
dist_extract.py
#!/usr/bin/env python3
import os
import glob
import argparse
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
type Bitmask uint8
const (
F0 bitmask = 1 << iota
F1
F2
)
func Set(b, flag Bitmask) Bitmask { return b | flag }
func Clear(b, flag Bitmask) Bitmask { return b &^ flag }
@bbengfort
bbengfort / pca_projection_yb.py
Created July 17, 2019 13:07
Example projection visualizer with Yellowbrick
from yellowbrick.features.projection import ProjectionVisualizer
from sklearn.pipeline import Pipeline
from sklearn.decomposition import PCA
from sklearn.preprocessing import StandardScaler
from sklearn.datasets import make_regression
class Visualizer(ProjectionVisualizer):