Skip to content

Instantly share code, notes, and snippets.

View deybhayden's full-sized avatar
🧠
Thinking

Ben Hayden deybhayden

🧠
Thinking
View GitHub Profile
@deybhayden
deybhayden / kms.sh
Created December 21, 2016 15:38
kms encrypt/decrypt bash functions
# kms encrypt/decrypt for macOS
function kms-encrypt {
# encrypts the passed key & plain text, and adds the base64 encoded string to your clipboard
aws kms encrypt --key-id "$1" --plaintext "$2" --query CiphertextBlob --output text | pbcopy
}
function kms-decrypt {
# decrypts the passed argument and adds it to your clipboard
aws kms decrypt --ciphertext-blob fileb://<(echo "$1" | base64 -D) --query Plaintext --output text | base64 -D | pbcopy
}
@deybhayden
deybhayden / jqfilter.sh
Created May 27, 2016 16:15
jq filter a list of objects' values
aws elasticbeanstalk describe-configuration-settings --application-name foo --environment-name foo-staging | jq '.ConfigurationSettings[0].OptionSettings[] | select(.OptionName=="Notification Topic ARN")'
@deybhayden
deybhayden / slack_to_trello.py
Last active May 6, 2016 16:00
Slack to Trello Slash Command - Lambda Function Template
'''
A function that handles a Slack "/trello" command and creates trello items in a board's "Inbox" list.
We use API Gateway to act as an AWS Proxy to call a lambda function asyncronously, along with an immediate response back to slack.
Once Lambda has created the card, and it then posts the new card url back to slack.
'''
import boto3
import json
import urllib
@deybhayden
deybhayden / podcast_download_analyzer.py
Last active March 23, 2016 16:39
You can use this python script (plus pandas) to analyze file download counts
#!/usr/bin/env python
from __future__ import print_function
import os
import xml.etree.ElementTree as ET
from multiprocessing.dummy import Pool
import boto3
import requests
import pandas as pd
@deybhayden
deybhayden / update_ssh_config.py
Created February 25, 2016 21:15
Python Script for dynamic SSH Hosts (for use on a bastion box)
#!/usr/bin/env python
import os
import boto.ec2
from collections import Counter
with open(os.path.join(os.environ['HOME'], '.ssh', 'config'), 'w') as sc:
new_sc = "Host example\n User bill\n HostName 123.456.789.1\n"
templ = "Host {0}-{1}\n HostName {2}\n"
ec2 = boto.ec2.connect_to_region('us-east-1')
counter_dict = Counter(['red',
@deybhayden
deybhayden / topnames.py
Created February 23, 2014 04:57
Top 10 Last Names in MLB History
# coding: utf-8
import pandas as pd
df = pd.read_csv('lahman-csv_2014-01-31/Master.csv')
count_series = df.nameLast.value_counts()
top_10_names = count_series[:10]
plt.figure()
top_10_names.plot(kind='bar').set_title('Most Popular Last Names in MLB'
@deybhayden
deybhayden / rediswebpy.py
Created September 14, 2012 20:42 — forked from pokstad/rediswebpy.py
Redis session store backend for web.py
import redis
import web
SESSION = 'SESSION:'
class RedisStore(web.session.Store):
"""Store for saving a session in redis:
import rediswebpy
session = web.session.Session(app, rediswebpy.RedisStore(), initializer={'count': 0})
@deybhayden
deybhayden / baby.py
Created April 5, 2012 04:00
A Baby's First Python
#!/usr/bin/env python
import random
from datetime import date
class BabyHayden(object):
"""A class of baby only a Dad could love."""
def __init__(self, due_date):
self.due_date = due_date
self.gender = None
self.name = None
@deybhayden
deybhayden / convert_ics_timezone.py
Created March 5, 2012 19:45
Convert iCalendar File (.ics) to new Timezone
#!/usr/bin/env python
"""
Simple script that updates all events in an ical file to a new timezone.
Requires icalendar package (which pulls in pytz as a dependency).
By: @beardedprojamz (Ben Hayden)
"""
import argparse
import sys
@deybhayden
deybhayden / customserializer.py
Created September 4, 2011 04:21
Custom JSON Serialization for Date and Decimal Objects
from datetime import date, datetime, time
from decimal import Decimal
def to_json(python_object):
"""
Adding in custom serialization for Date & Decimal objects.
>>> import json
>>> from datetime import date, datetime, time
>>> from decimal import Decimal