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 / venv_cheat_sheet.md
Created August 20, 2014 14:16
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

$ echo $WORKON_HOME
/Users/benjamin/.virtualenvs

$ echo $PROJECT_HOME
@bbengfort
bbengfort / nx2gt.py
Created June 26, 2016 12:01
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
@bbengfort
bbengfort / randommer.py
Created April 5, 2024 22:51
Access the randommer.io API to generate fake crypto addresses and names for test fixtures.
#!/usr/bin/env python3
import os
import requests
import argparse
API_KEY_VAR = "RANDOMMER_API_KEY"
CRYPTO_TYPES = "https://randommer.io/api/Finance/CryptoAddress/Types"
CRYPTO_ADDRESS = "https://randommer.io/api/Finance/CryptoAddress"
RANDOM_NAME = "https://randommer.io/api/Name"
@bbengfort
bbengfort / pi.c
Created October 17, 2015 12:59
OpenMP parallel integration to compute Pi.
#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
bbengfort / .dockerignore
Created September 19, 2023 12:15
Dockerfile examples for the blog post "How to Dockerize Python Data Science Processes" on rotational.io
# Ignore docker specific files
.dockerignore
docker-compose.yml
Dockerfile
# Ignore git directory and files
.gitignore
.git
# Ignore text files at the root of the project (optional)
@bbengfort
bbengfort / balance.py
Created December 7, 2017 02:11
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
bbengfort / smiley.py
Last active December 21, 2023 02:54
Matplotlib smiley face.
fig = plt.figure(figsize=(8,8))
ax = fig.add_subplot(1,1,1, aspect=1)
ax.scatter([.5],[.5], c='#FFCC00', s=120000, label="face")
ax.scatter([.35, .65], [.63, .63], c='k', s=1000, label="eyes")
X = np.linspace(.3, .7, 100)
Y = 2* (X-.5)**2 + 0.30
ax.plot(X, Y, c='k', linewidth=8, label="smile")
@bbengfort
bbengfort / cryptpress.go
Created October 27, 2023 22:09
Data encryption and compression are heavyweight algorithms that must be used with care in performance intensive applications; but when applying both mechanics to the same data, which should come first? These benchmarks compare Go gzip compression with AES-GCM cryptography. For more see: https://rotational.io/blog/compression-vs-cryptography/.
package cryptpress
import (
"bytes"
"compress/gzip"
"crypto/aes"
"crypto/cipher"
"crypto/rand"
"io"
)
@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