Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Benjamin Bengfort bbengfort

🎯
Focusing
View GitHub Profile
@bbengfort
bbengfort / ca.go
Created Dec 30, 2020
Implements a simple CLI certificate authority for self-signed certs
View ca.go
package main
import (
"crypto/rand"
"crypto/rsa"
"crypto/tls"
"crypto/x509"
"crypto/x509/pkix"
"encoding/pem"
"fmt"
@bbengfort
bbengfort / wide_argparse.py
Created Nov 3, 2020
Create a wider argument parser for better options on --help
View wide_argparse.py
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 Oct 21, 2021
Dealing with Zip archives and json data in Python
View zipr.py
#!/usr/bin/env python3
import os
import json
import random
import zipfile
config = {
"color": "red",
"amount": 42.24,
@bbengfort
bbengfort / ani.py
Last active Jul 14, 2020
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.
View ani.py
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 Mar 3, 2021
Automatically manage requirements.txt with Python
View requires
#!/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
#
View btrdb_random_walk_generate.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View ldaviz.py
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 Aug 29, 2019
Make the Yellowbrick gource video
View ybvid.sh
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
View 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
View bitmask.go
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 }