Skip to content

Instantly share code, notes, and snippets.

View benhagen's full-sized avatar

Ben Hagen benhagen

View GitHub Profile
@benhagen
benhagen / python_template_cli.py
Created December 16, 2014 17:38
Quick and dirty template for a Python CLI app.
#!/usr/bin/env python
"""template
Usage:
template.py list [--allregions|-r <region>...] [-v]
Options:
-h --help Show this screen
--version Show version
@benhagen
benhagen / redis_do_benchmarks.md
Last active August 29, 2015 14:02
Redis Benchmarks on DigitalOcean

Redis Benchmarks on DigitalOcean

Disclaimer: I am a total Redis newb. I'm sure this could be done better.

TL;DR The 4GB droplet is oddly almost 2x faster than smaller and bigger droplets (which are otherwise pretty consistent).

Some quick benchmarks for running Redis on DigitalOcean. All tests were run on the same "Ubuntu 14.04 x64" provisioned instance resized between the different droplet sizes. The benchmark was run twice (once in the afternoon PST, and once in the morning PST). Benchmark executed as:

> redis-benchmark -q -n 100000
@benhagen
benhagen / keybase.md
Created April 2, 2014 19:00
keybase.md

Keybase proof

I hereby claim:

  • I am benhagen on github.
  • I am benhagen (https://keybase.io/benhagen) on keybase.
  • I have a public key whose fingerprint is 235F D020 F869 F7F4 F808 76B2 509B 9465 7663 AF33

To claim this, I am signing this object:

@benhagen
benhagen / aws-policy-s3_referer.json
Created December 3, 2013 22:35
S3 bucket policy to restrict access by referer.
{
"Id": "Restrict access to S3 keys by HTTP referer header",
"Statement": [
{
"Sid": "S3 Referer Header Check",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObject",
@benhagen
benhagen / refcheck.py
Created December 3, 2013 22:28
Super simple script to check referer header restrictions on a URL.
#!/usr/bin/env python
import requests
url = "http://testurl/"
referer = "https://refererurl/"
print "URL: {}\nREFERER: {}\n".format(url, referer)
request = requests.get(url, headers={"Referer": referer})
@benhagen
benhagen / awscreds_encrypt.sh
Last active January 6, 2023 19:05
BASH script to take your two AWS environment vars, and encrypt them via AES-256. Store these values in a generated shell script which can be sourced to apply the variables when the correct password is given.
#!/bin/bash
read -sp "Enter encryption password: " PASSWORD
echo ""
read -sp "Confirm encryption password: " PASSWORD_CONFIRM
echo ""
if [[ "$PASSWORD" != "$PASSWORD_CONFIRM" ]]; then
echo "ERROR: Passwords do not match!"
exit 1
@benhagen
benhagen / is_ipv4.py
Last active March 19, 2020 19:23
Python function to determine if a string is like an IPv4 address. Its lame but works; to be improved at a later date.
def is_ipv4(ip):
match = re.match("^(\d{0,3})\.(\d{0,3})\.(\d{0,3})\.(\d{0,3})$", ip)
if not match:
return False
quad = []
for number in match.groups():
quad.append(int(number))
if quad[0] < 1:
return False
for number in quad:
@benhagen
benhagen / libdnet_python.rb
Last active March 6, 2017 08:11
Install Scapy on OSX through Homebrew
require 'formula'
class LibdnetPython <Formula
depends_on 'libdnet'
url 'http://libdnet.googlecode.com/files/libdnet-1.12.tgz'
homepage 'http://code.google.com/p/libdnet/'
sha1 '71302be302e84fc19b559e811951b5d600d976f8'
def install
ENV["CFLAGS"] = "-O3 -w -pipe"
@benhagen
benhagen / ssl_ciphers.py
Created March 12, 2013 22:25
Enumerate locally supported SSL/TLS ciphers in Python / M2Crypto
#!/usr/bin/env python
from M2Crypto import SSL
versions = ["sslv2", "sslv23", "sslv3", "tlsv1"]
ciphers = []
for version in versions:
ctx = SSL.Context(version, weak_crypto=True)
conn = SSL.Connection(ctx)