Skip to content

Instantly share code, notes, and snippets.

@benburry
benburry / record_ses_stats.py
Created May 17, 2013 12:11
Use boto to pull the latest Amazon SES statistic values and report them to Graphite
#!/usr/bin/env python
import dateutil.parser
import socket
from time import mktime
import boto
GRAPHITE_KEY_TMPL='services.email.ses.%s.last15minutes'
GRAPHITE_HOST=('graphite.example.com', 2003)
def build_graphite_message_list(stats):
@benburry
benburry / try_airbnb.py
Created January 16, 2014 18:24
Try to work out if AirBnB listings still exists from its url
#!/usr/bin/env python
import requests
import sys
import time
import re
PAT = re.compile(r'^https?://(?:w{3}\.)?airbnb\..*/([^/]+)/?$')
@benburry
benburry / echo.py
Last active October 7, 2019 05:05
Python 2 - mock & unittest example for Popen
from subprocess import Popen, PIPE
def shell_out(command):
return Popen(command.split(' '), stdout=PIPE,stderr=PIPE).communicate()[0].strip('\n').split('\n')
def main():
return shell_out('echo one\ntwo\nthree\n')
irb(main):006:0> roles = ['one', 'two']
=> ["one", "two"]
irb(main):007:0> roles.include? 'one' && true
=> false
irb(main):008:0> roles.include?('one') && true
=> true
irb(main):009:0> roles.include? 'one' and true
=> true
irb(main):008:0> roles = ['one', 'two']
=> ["one", "two"]
irb(main):009:0> roles.include? 'one' && true
=> false
irb(main):010:0> roles.include? 'one' and true
=> true
irb(main):011:0> roles.include?('one') && true
=> true
irb(main):012:0> roles.include? true && 'one'
=> true