Skip to content

Instantly share code, notes, and snippets.

View phill-tornroth's full-sized avatar

Phill Tornroth phill-tornroth

  • http://elationhealth.com
  • Encinitas, CA
View GitHub Profile
@phill-tornroth
phill-tornroth / cp-parameter-group.py
Created August 23, 2018 19:19
Copies an rds parameter group with support for cross-region copying. Quick bashed out script because AWS cli doesn't support.
"""
Copies a parameter group in RDS, particularly useful for doing cross-region copies (which AWS documents,
but doesn't actually support at the time of this writing.
Usage: python cp-parameter-group.py us-west-1:lookerdb-56 us-west-2:lookerdb-56
"""
import boto3
import sys
@phill-tornroth
phill-tornroth / elasticsearch_backend.py
Last active November 11, 2015 23:05
A Django-Haystack backend for ElasticSearch 1.x that incorporates the best things I found in the recent master and pull requests, and fixes issues with each
"""
This is the basis for an elasticsearch 1.x backend I've cobbled together and am continuing
to refine and test for use. It's based on haystack master's version as of:
- https://github.com/toastdriven/django-haystack/blob/cbb72b3253404ba21e20860f620774f7b7b691d0/haystack/backends/elasticsearch_backend.py
But with @HonzaKral and @davedash's work to make the backend behave more like an ES user would expect with regard to doc types:
- https://github.com/toastdriven/django-haystack/pull/921
I also made a number of changes:
- I fixed bugs that I found in #921 (mostly related to mapping synchronization issues),
all of which I wrote up as comments on #921
['Fizz' * (not bool(i % 3)) + 'Buzz' * (not bool(i % 5)) for i in xrange(1,101) if i % 3 == 0 or i % 5==0]
@phill-tornroth
phill-tornroth / gist:2877507
Created June 5, 2012 20:10
Playing with class decorators
>>> class my_dec(object):
... def __init__(self, f):
... self.f = f
...
>>> class my_dec(object):
... def __init__(self, f):
... self.f = f
... def __call__(self, *args):
... return self.f(*args)
...
retVal = datetime.strptime( dateTimeStr, "%Y%m%d" )
ImportError: Failed to import _strptime because the import lockis held by another thread.
@phill-tornroth
phill-tornroth / DictShieldToDjango.py
Created April 4, 2012 18:46
Playing with DictShield model creation from Django
from dictshield.document import Document
from dictshield.fields import StringField, IntField
from django.db import models
def _build_client_model(model):
"""
Take a Django model, and return a DictShield Document subclass
which is very representative.
TODO:
import sys
valid_words = set([
'AA', 'AB', 'AD', 'AE', 'AG', 'AH', 'AI', 'AL', 'AM', 'AN', 'AR', 'AS', 'AT', 'AW', 'AX', 'AY',
'BA', 'BE', 'BI', 'BO', 'BY',
'DE', 'DO',
'ED', 'EF', 'EH', 'EL', 'EM', 'EN', 'ER', 'ES', 'ET', 'EX',
'FA', 'FE',
'GO',
'HA', 'HE', 'HI', 'HM', 'HO',
@phill-tornroth
phill-tornroth / update_large_index.py
Created September 7, 2011 17:21
This is my little batched-strategy for updating really large haystack indexes via a Celery task. It's pretty simple... Each task builds a piece of the index, and then puts a task on the queue for building the next batch. I also use my little @bounce_worke
import logging
from celery.signals import task_postrun
from celery.task import task
from haystack import site
def bounce_worker_after(func):
"""
A decorator which will ensure that the celery worker is shutdown (and subsequently restarted by celery)
after this task is executed.
@phill-tornroth
phill-tornroth / gist:979666
Created May 18, 2011 21:56
Thoughts on a nicer choices field.
class Choices(object):
def __getattr__(self, item):
if str(item).isdigit():
try:
return self.__getitem__(item)
except KeyError:
pass
@phill-tornroth
phill-tornroth / gist:948855
Created April 29, 2011 19:23
Django settings_local handler.
# For local dev purposes, allow for importing of add'l settings from
# a settings_local.py file (over-rides any already set above)
if DEBUG:
try:
from settings_local import *
except ImportError:
pass
else:
# Special treatment for symbols in settings_local that begin with 'EXTRA_'.