Skip to content

Instantly share code, notes, and snippets.

from __future__ import print_function
import StringIO
import gzip
from boto.s3.connection import S3Connection
conn = S3Connection("<key_id>", "<secret>")
bucket = conn.get_bucket('<bucket>')
#!/usr/bin/env python
'''
Send memory usage metrics to Amazon CloudWatch
This is intended to run on an Amazon EC2 instance and requires an IAM
role allowing to write CloudWatch metrics. Alternatively, you can create
a boto credentials file and rely on it instead.
Original idea based on https://github.com/colinbjohnson/aws-missing-tools
'''
@hltbra
hltbra / get-inbound-and-egress-sg-rules.py
Last active November 15, 2018 12:04
Get AWS ingress and egress rules for a given security group
import boto
ec2 = boto.connect_ec2()
groups = ec2.get_all_security_groups()
def get_groups_that_have_ingress_rules_to(groups, group_id):
result = []
for group in groups:
for rule in group.rules:
for grant in rule.grants:
# WRONG
def test_open_and_delete_file():
f = open(FILEPATH)
content = f.read()
assert content == "hello world"
content.close()
# RIGHT
def test_open_and_delete_file():
@hltbra
hltbra / Dockerfile
Last active December 26, 2015 09:09
FROM base
MAINTAINER Hugo Lopes Tavares <hugo@yipit.com>
RUN apt-get update
RUN apt-get install -y python3 expect-dev
EXPOSES 8000
CMD ["unbuffer", "python3", "-m", "http.server"]
@hltbra
hltbra / logstash_crash
Created October 10, 2013 20:42
logstash crashes if you have an invalid ruby regex as grok pattern
# /usr/bin/java -jar /usr/share/logstash/logstash-1.1.13-monolithic.jar agent -f /etc/logstash/conf.d -w 1
Exception in thread "LogStash::Runner" org.jruby.exceptions.RaiseException: (RegexpError) premature end of char-class: /^\\[/
at org.jruby.RubyRegexp.initialize(org/jruby/RubyRegexp.java:1267)
at org.jruby.RubyRegexp.new(org/jruby/RubyRegexp.java:729)
at RUBY.compile(jar:file:/usr/share/logstash/logstash-1.1.13-monolithic.jar!/gems/jls-grok-0.10.11/lib/grok-pure.rb:137)
at RUBY.register(file:/usr/share/logstash/logstash-1.1.13-monolithic.jar!/logstash/filters/multiline.rb:146)
at RUBY.run_with_config(file:/usr/share/logstash/logstash-1.1.13-monolithic.jar!/logstash/agent.rb:472)
at org.jruby.ext.thread.Mutex.synchronize(org/jruby/ext/thread/Mutex.java:149)
at RUBY.run_with_config(file:/usr/share/logstash/logstash-1.1.13-monolithic.jar!/logstash/agent.rb:471)
at org.jruby.RubyArray.each(org/jruby/RubyArray.java:1613)
class Context
def self.path(fname)
puts "Creating file #{fname}"
end
end
def template(filename, &block)
context = Class.new(Context)
context.class_eval(&block)
context
@hltbra
hltbra / output_dicts.txt
Last active December 21, 2015 15:09
pytest output for assertion on dicts and lists
============================= test session starts ==============================
platform darwin -- Python 2.7.5 -- pytest-2.3.5
plugins: growl
collected 2 items
test_equals_with_dicts.py FF
=================================== FAILURES ===================================
____________ test_assert_equals_with_dicts_and_all_values_different ____________
@hltbra
hltbra / after-pull-request-483.txt
Created March 30, 2013 19:55
develop branch after ptone/threaded-page-getting
$ pip --version
pip 1.4.dev1 from /private/tmp/venv-test2/lib/python2.7/site-packages/pip-1.4.dev1-py2.7.egg (python 2.7)
$ time pip install --no-install coverage -vvvvv
Downloading/unpacking coverage
Getting page https://pypi.python.org/simple/coverage/
URLs to search for versions for coverage:
* https://pypi.python.org/simple/coverage/
Getting page http://nedbatchelder.com/code/modules/coverage.html
Getting page http://nedbatchelder.com/code/coverage
Getting page http://nedbatchelder.com/code/coverage/3.5.1b1
@hltbra
hltbra / before-pull-request-483.txt
Created March 30, 2013 19:54
develop branch before ptone/threaded-page-getting
$ pip --version
pip 1.4.dev1 from /private/tmp/venv-test/lib/python2.7/site-packages (python 2.7)
$ time pip install --no-install coverage -vvvvv
Downloading/unpacking coverage
Getting page https://pypi.python.org/simple/coverage/
URLs to search for versions for coverage:
* https://pypi.python.org/simple/coverage/
Getting page http://nedbatchelder.com/code/modules/coverage.html
Skipping page http://nedbatchelder.com/code/modules/coverage-2.85.tar.gz (from https://pypi.python.org/simple/coverage/) because of Content-Type: application/x-tar
Skipping page http://nedbatchelder.com/code/modules/coverage-2.8.tar.gz (from https://pypi.python.org/simple/coverage/) because of Content-Type: application/x-tar