Skip to content

Instantly share code, notes, and snippets.

@shauns
shauns / explicit_orm.py
Created November 8, 2014 09:52
Explicit ORM
# Explicit
query = self.session.query(Book)
book = yield from query.get(1)
@shauns
shauns / implicit_orm.py
Created November 8, 2014 09:51
Implicit ORM
# Implicit
query = self.session.query(Book)
book = query.get(1) # implicit switch here
@shauns
shauns / explicit_rpc.py
Last active August 29, 2015 14:08
Explicit RPC
# Explicit
result = yield from self.make_rpc_call()
@shauns
shauns / implicit_rpc.py
Created November 8, 2014 09:49
Implicit RPC
# Implicit
result = self.make_rpc_call() # implicit switch here
@shauns
shauns / gist:0571b75ae0098517fb92
Created November 8, 2014 09:47
Asyncio example
@asyncio.coroutine
def slow_method():
yield from perform_a_blocking_call()
return 'Done'
loop = asyncio.get_event_loop()
loop.run_until_complete(slow_method())
loop.close()
@shauns
shauns / example.py
Created September 4, 2014 10:18
Tracking pytest errors
import pytest
def track_test_fails():
@pytest.mark.tryfirst
def pytest_runtest_makereport(item, call, __multicall__):
# execute all other hooks to obtain the report object
rep = __multicall__.execute()
# `when` is setup, call, teardown
setattr(item, "rep_" + rep.when, rep)
@shauns
shauns / entrypoint_platform.py
Created July 28, 2014 16:41
Entrypoints with two functions
# rpc_factory is what used to be rpc
@entrypoint
def rpc_factory(expected_exceptions=None):
return DependencyFactory(NovaRpcProvider, expected_exceptions)
def rpc(service_fn=None, expected_exceptions=None):
if service_fn is None:
return partial(rpc, expected_exceptions=expected_exceptions)
@shauns
shauns / entrypoint.py
Created July 28, 2014 11:32
Nameko entrypoint sketch
# re: nameko entrypoints
def wrapt_entrypoint(entrypoint_fn=None, provider=None):
""" Transform a callable into a decorator that can be used to declare
entrypoints.
The callable should indicate a EntrypointProvider class. Usages of the
callable will have their kwargs combined with the provider to produce a
DependencyFactory for the given wrapped service function.
@shauns
shauns / 73-Managing-Amazon-EC2-SSH-login-and-protecting-your-instances.html
Created August 14, 2013 10:08
Managing Amazon EC2 - SSH login and protecting your instances
NB: Originally courtesy of http://blog.taggesell.de/index.php?/archives/73-Managing-Amazon-EC2-SSH-login-and-protecting-your-instances.html
Managing Amazon EC2 - SSH login and protecting your instances
How to log into your freshly fired-up instances and how to secure ssh access
(works under Linux and Mac OS, under Windows with Cygwin)
First time you want to log into a newly started instance you appear to have the chicken-and-egg problem: how to log in when you do not know the root password? Luckily Amazon devised a comfortable way to circumvent this: your Key Pairs. these are not to be confused with the „Access Key IDs“ on the Access Identifier web page and they are neither the X509 certificates. These Key pairs are automatically generated the first time you log into the web console and you can only download its private part. Store it in your ~/.ssh directory. In case you missed the download or don't know where you've put it AND you don't have any instances running, just generate and download a new one.
@shauns
shauns / requirements.txt
Last active December 20, 2015 20:09
Sample requirements for salt test
Django>=1.2
South
psycopg2