Skip to content

Instantly share code, notes, and snippets.

Avatar

Thomas Steinacher thomasst

View GitHub Profile
View test_context.py
# 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
Migrate Redis data on Amazon ElastiCache
View migrate-redis.py
"""
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.
View search6.py
from pyelasticsearch import ElasticSearch, ElasticHttpNotFoundError
from pyparsing import *
import unittest
ELASTICSEARCH_INDEX = 'myindex'
ELASTICSEARCH_URL = 'http://localhost:9200/'
es = ElasticSearch(ELASTICSEARCH_URL)
View search5.py
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))
View search4.py
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))
View search3.py
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
View search2.py
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
View search1.py
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)
You can’t perform that action at this time.