Skip to content

Instantly share code, notes, and snippets.

View corbinbs's full-sized avatar
💭
🚜💻📈

Brian S. Corbin corbinbs

💭
🚜💻📈
View GitHub Profile
@corbinbs
corbinbs / countrules.py
Created January 14, 2011 22:51
Python snippet to scan a directory for Drools rule files and report on the total number of rules found. Probably could expand this to count other things...
import re
import os
def count_rules(dir, exts=['.drl', '.dslr']):
rulecount = 0
for root, dirs, files in os.walk(dir):
for file in files:
if len([file for ext in exts if file.endswith(ext)]) > 0:
filename = os.path.join(root, file)
f = open(filename, "r")
#!/usr/bin/env python
"""
A script to query the Amazon Web Services usage reports programmatically.
Ideally this wouldn't exist, and Amazon would provide an API we can use
instead, but hey - that's life.
Basically takes your AWS account username and password, logs into the
website as you, and grabs the data out. Always gets the 'All Usage Types'
@corbinbs
corbinbs / alert_demo.py
Created July 15, 2011 02:19
Example Python Alert Dialogs using PyObjC (alternative to EasyDialogs?)
import objc
from AppKit import *
from Foundation import *
class Alert(object):
def __init__(self, messageText):
super(Alert, self).__init__()
self.messageText = messageText
self.informativeText = ""
@corbinbs
corbinbs / scrub_it.py
Created July 18, 2011 13:05
Simple XML file scrubber in Python
from xml.sax.saxutils import XMLGenerator
import xml
def mask_field(field):
return 'X'*len(field)
class ScrubHandler(XMLGenerator, object):
def __init__(self, scrub_map={}, out=None):
super(ScrubHandler, self).__init__(out=out)
@corbinbs
corbinbs / hack.sh
Created March 31, 2012 18:35 — forked from erikh/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@corbinbs
corbinbs / json_required_demo.py
Created September 26, 2012 22:57
Flask JSON required decorator
"""
Demo of json_required decorator for API input validation/error handling
"""
import inspect
import functools
import json
from traceback import format_exception
from flask import jsonify, request
import sys
@corbinbs
corbinbs / json_required_example.json
Created October 2, 2012 18:11
Flask JSON Required Example Input
{
"date_of_birth": "01/01/1970",
"email": "corbinbs@example.com",
"first_name": "Brian",
"last_name": "Corbin"
}
@corbinbs
corbinbs / json_required_example.py
Created October 2, 2012 18:12
Flask JSON Required Example
@app.route("/do/something", methods=['POST'])
@json_required(
required_fields={
'first_name':"Please enter your first name.",
'last_name':"Please enter your last name.",
'email':'Please specify a valid email address',
'date_of_birth':'Please enter your date of birth'
},
validations=[
('email', 'Please specify a valid email address', lambda email: email is not None and EMAIL_REGEX.match(email)),
#!/usr/bin/env bash
#
# superpack.sh:
#
# Define components you need to do work.
# Quickly.
# Superpack downloads/installs stuff so you don't have to.
# Blast new developers into productivity on their first day.
#
# Usage:
@corbinbs
corbinbs / keybase.md
Created August 14, 2014 14:19
Keybase proof

Keybase proof

I hereby claim:

  • I am corbinbs on github.
  • I am corbinbs (https://keybase.io/corbinbs) on keybase.
  • I have a public key whose fingerprint is A16F FFC6 0789 FCBA ABA8 CB51 9128 64D8 41D1 4FD9

To claim this, I am signing this object: