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 / 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 / lsys.py
Last active August 16, 2023 06:03
Draw an L-System with Python's turtle graphics library, where the L-System is defined with a turning angle (d) a line length (l) and an axiom in the using the characters 'F', 'f', '+', and '-' to indicate rules. You can also iterate the axiom for fractal like patterns.
#!/usr/bin/env python
import turtle
D = 90
L = 10
def iterate(axiom, num=0, initator='F'):
"""
Compute turtle rule string by iterating on an axiom
@bbengfort
bbengfort / jsonexplorer.py
Last active July 25, 2023 14:37
Interactive JSON explorer using Python's cmd module
#!/usr/bin/env python
# jsonexplorer
# An interactive interface to explore JSON documents
#
# Author: Benjamin Bengfort <benjamin@bengfort.com>
# Created: Wed Jun 17 12:15:23 2015 -0400
#
# Copyright (C) 2015 Bengfort.com
# Licensed under the OSI Approved MIT License
#
@bbengfort
bbengfort / interval.py
Last active July 7, 2023 04:33
Run a function every n seconds using Python threading.
from threading import Timer
from functools import partial
class Interval(object):
def __init__(self, interval, function, args=[], kwargs={}):
"""
Runs the function at a specified interval with given arguments.
"""
self.interval = interval
@bbengfort
bbengfort / hashtopic.py
Last active April 3, 2023 17:18
Murmur3 comparison and test fixtures
#!/usr/bin/env python3
import mmh3
import json
import base64
def topic_hash(name):
hash = mmh3.hash128(name.encode('utf-8'), signed=False).to_bytes(16, byteorder='big', signed=False)
hash = hash[8:] + hash[:8]
@bbengfort
bbengfort / cleangcr.py
Last active February 12, 2023 19:22
A helper script that uses gcloud commands to cleanup old GCR images and reduce storage costs. By default it keeps any images tagged with a semver label and automatically removes any images with no tags. Users can specify a minimum number of images to keep and a grace period to allow images to stay for a specific time period.
#!/usr/bin/env python3
# Uses gcloud commands to cleanup old GCR images and reduce storage costs.
import re
import json
import argparse
import subprocess
from datetime import datetime, timedelta, timezone
@bbengfort
bbengfort / sentiment.py
Last active December 27, 2022 05:17
An end-to-end demonstration of a Scikit-Learn SVM classifier trained on the positive and negative movie reviews corpus in NLTK.
import os
import time
import string
import pickle
from operator import itemgetter
from nltk.corpus import stopwords as sw
from nltk.corpus import wordnet as wn
from nltk import wordpunct_tokenize
@bbengfort
bbengfort / gitseries.py
Last active December 5, 2022 13:12
Iterate through all commits and yield file version information or a time series of file changes.
## Imports
import os
import git
## Module Constants
DATE_TIME_FORMAT = "%Y-%m-%dT%H:%M:%S%z"
EMPTY_TREE_SHA = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
@bbengfort
bbengfort / publisher.go
Created October 4, 2022 16:45
A quick ensign publisher routine.
package main
import (
"context"
"encoding/json"
"fmt"
"log"
"time"
api "github.com/rotationalio/ensign/pkg/api/v1beta1"
@bbengfort
bbengfort / merge.go
Created August 24, 2022 20:35
Merging a struct from another struct using reflection in Go. https://go.dev/play/p/m4dXDahCgyW?v=goprev
// Merging a struct from another struct using reflection.
package main
import (
"encoding/json"
"errors"
"fmt"
"reflect"
)