Skip to content

Instantly share code, notes, and snippets.

@thomasst
thomasst / test_context.py
Created March 16, 2016 23:06
Context for tests
# Inspired by http://stackoverflow.com/a/13875412
class ContextMixin(object):
def setup_context(self):
self._ctxs = []
for cls in reversed(self.__class__.mro()):
context_method = cls.__dict__.get('context')
if context_method:
ctx = context_method(self)
self._ctxs.append(ctx)
@thomasst
thomasst / migrate-redis.py
Created May 14, 2015 18:26
Migrate Redis data on Amazon ElastiCache
"""
Copies all keys from the source Redis host to the destination Redis host.
Useful to migrate Redis instances where commands like SLAVEOF and MIGRATE are
restricted (e.g. on Amazon ElastiCache).
The script scans through the keyspace of the given database number and uses
a pipeline of DUMP and RESTORE commands to migrate the keys.
Requires Redis 2.8.0 or higher.
from pyelasticsearch import ElasticSearch, ElasticHttpNotFoundError
from pyparsing import *
import unittest
ELASTICSEARCH_INDEX = 'myindex'
ELASTICSEARCH_URL = 'http://localhost:9200/'
es = ElasticSearch(ELASTICSEARCH_URL)
from pyparsing import *
import unittest
class Node(list):
def __eq__(self, other):
return list.__eq__(self, other) and self.__class__ == other.__class__
def __repr__(self):
return '%s(%s)' % (self.__class__.__name__, list.__repr__(self))
from pyparsing import *
import unittest
class Node(list):
def __eq__(self, other):
return list.__eq__(self, other) and self.__class__ == other.__class__
def __repr__(self):
return '%s(%s)' % (self.__class__.__name__, list.__repr__(self))
from pyparsing import *
import unittest
unicode_printables = u''.join(unichr(c) for c in xrange(65536)
if not unichr(c).isspace())
word = Word(unicode_printables)
exact = QuotedString('"', unquoteResults=True, escChar='\\')
term = exact | word
from pyparsing import *
import unittest
unicode_printables = u''.join(unichr(c) for c in xrange(65536)
if not unichr(c).isspace())
word = Word(unicode_printables)
exact = QuotedString('"', unquoteResults=True, escChar='\\')
term = exact | word
from pyparsing import *
import unittest
unicode_printables = u''.join(unichr(c) for c in xrange(65536)
if not unichr(c).isspace())
word = Word(unicode_printables)