Skip to content

Instantly share code, notes, and snippets.

#!/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
'''
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>')

[ruby-dev:39421] exception from open-uri

Yusuke ENDOH writes:

Periodically when fetching web pages using open-uri, he notices that many different kinds of exceptions can be raised.

So far, he’s experienced these below:

  • Errno::ETIMEDOUT

import boto
def find_autoscaling_groups_by_instance(instance_id):
asg = boto.connect_autoscale()
groups = []
g = asg.get_all_groups()
groups.extend(g)
while g.next_token:
SELECT table_name AS "Tables",
round(((data_length + index_length) / 1024 / 1024), 2) "Size in MB",
round(((data_length + index_length) / 1024 / 1024 / 1024), 2) "Size in GB"
FROM information_schema.TABLES
WHERE table_schema = "PUT_DATABASE_NAME_HERE"
ORDER BY (data_length + index_length) DESC;
"""
>>> class Example(object):
... @private
... def private_method(self):
... print 'method privated called'
...
... def public_method(self):
... self.private_method()
... print 'method public called'
'''
>>> class Pessoa(object):
... filho_de = None
... filhos = []
...
>>> class Joao(Pessoa):
... pass
>>> Joao.filhos
=====buildout.cfg======
[buildout]
directory = hello_world.py
=======================
=====hello_world.py====
print 'hello world'
=======================
'''
>>> calcular('1')
1
>>> calcular('(+ 1 2)')
3
'''
from pyparsing import Word, White, nums, Literal, OneOrMore, Group
'''
The BNF for this small infix calculator looks like:
<expr> ::= <num>
| (<num>)
| (+ <expr> <expr>)
| (- <expr> <expr>)
| (* <expr> <expr>)
| (/ <expr> <expr>)
| (^ <expr> <expr>)