Navigation Menu

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 / 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 / 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 / .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 / 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 / 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 / counter.go
Created September 19, 2022 15:19
Atomic vs Mutex Counter Benchmark
package counter
import (
"sync"
"sync/atomic"
)
type Counter interface {
Inc()
Load() uint64
@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"
)
@bbengfort
bbengfort / editor.go
Last active January 10, 2022 18:42
Edit files from a Go program by calling a CLI editor like vim with exec.
/*
Wrapper for a command line editor to edit files.
*/
package main
import (
"encoding/json"
"errors"
"flag"
"fmt"
@bbengfort
bbengfort / ca.go
Created December 30, 2020 20:11
Implements a simple CLI certificate authority for self-signed certs
package main
import (
"crypto/rand"
"crypto/rsa"
"crypto/tls"
"crypto/x509"
"crypto/x509/pkix"
"encoding/pem"
"fmt"