Skip to content

Instantly share code, notes, and snippets.


Benjamin Bengfort bbengfort

View GitHub Profile
bbengfort /
Created Dec 7, 2017
Database transactions blog post.
#!/usr/bin/env python3
import os
import logging
import psycopg2 as pg
from decimal import Decimal
from functools import wraps
from psycopg2.pool import ThreadedConnectionPool
bbengfort /
Last active Oct 21, 2021
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 /
Created Aug 20, 2014
My virtualenv and virtualenv wrapper cheat sheet. I alias the commands of virtualenv and virtualenv wrapper for my own development environment.

Ben's VirtualEnv Cheatsheet

This cheat sheet describes my usage/implementation of virtualenv with virtualenv wrapper and the bash foo that I added with the help of many blogs to make it all tick together in fun land.

Quick Reference


bbengfort /
Last active Sep 7, 2021
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 /
Created Jun 14, 2017
Runs multiple subprocesses in parallel, serializing stdout.
#!/usr/bin/env python3
# pproc
# Runs multiple subprocesses in parallel, serializing stdout.
# Author: Benjamin Bengfort <>
# Created: Wed Jun 14 15:20:05 2017 -0400
# Copyright (C) 2017
# For license information, see LICENSE.txt
bbengfort / locks.go
Created Mar 3, 2017
Synchronized, thread safe buffer using mutex embedding
View locks.go
package main
import (
bbengfort /
Last active Aug 10, 2021
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 / pi.c
Created Oct 17, 2015
OpenMP parallel integration to compute Pi.
View pi.c
#include <omp.h>
#include <stdio.h>
#include <stdlib.h>
#define MAX_THREADS 8
static long steps = 1000000000;
double step;
int main (int argc, const char *argv[]) {
bbengfort / noplog.go
Created Mar 20, 2017
No-op logger to turn off logging in Go without too much of a performance hit.
View noplog.go
package noplog
import "log"
var noplog = &NopLogger{
log.New(NullWriter(1), "", log.LstdFlags),
// NullWriter implements the io.Write interface but doesn't do anything.
type NullWriter int
bbengfort /
Created Jun 26, 2016
Convert a networkx to graph-tool graph
import networkx as nx
import graph_tool as gt
def get_prop_type(value, key=None):
Performs typing and value conversion for the graph_tool PropertyMap class.
If a key is provided, it also ensures the key is in a format that can be