Skip to content

Instantly share code, notes, and snippets.

@michaelhelmick
michaelhelmick / celery-health.sh
Last active July 28, 2020 00:50
Celery ECS Health Check
#!/bin/bash
celery inspect ping -A project -d celery@$HOSTNAME
if [ $? -eq 0 ]; then \
echo "OK"; \
exit 0; \
else \
exit 1; \
fi
@michaelhelmick
michaelhelmick / travis.yml
Created February 4, 2020 17:34
Django Migration Conflicts
sudo: required
language: bash
script:
- make $SCRIPT
jobs:
fast_finish: true
include:
- stage: conflicts
env:
- TEST_SUITE=backend
@michaelhelmick
michaelhelmick / Makefile
Last active February 4, 2020 17:33
Django Migration Conflicts
MIGRATION_CONFLICTS=$(shell find . -name "*.py" | grep -o ".*migrations/[0-9]\+" | sort | uniq -c | awk '$$1 > 1 {print $$0}')
migration-conflicts:
@if [ "${MIGRATION_CONFLICTS}" = "" ]; then \
echo "No migration conflicts found."; \
else \
echo "The following migration conflicts found:" && \
echo "${MIGRATION_CONFLICTS}" && exit 1; \
fi
{
"id": 1,
"thumbnails": {
"small": "https://example.com/image_small.jpg",
"medium": "https://example.com/image_medium.jpg",
"large": "https://example.com/image_large.jpg"
}
}
class Photo(models.Model):
thumbnail = models.ImageField(...)
...
def get_small_thumbnail(self):
return get_thumbnail(size='small')
def get_medium_thumbnail(self):
return get_thumbnail(size='medium')
class DynamicMethodField(serializers.Field):
"""Field that accepts instance methods and method kwargs."""
def __init__(self, *args, **kwargs):
"""Extend DynamicMethodCharField.__init__.
Args:
method (str): Method on the instance to call.
method_args (list): List of arguments to pass to the
instance method.
class Photo(models.Model):
thumbnail = models.ImageField(...)
def get_thumbnail(self, size='medium'):
"""Get an appropriate size thumbnail.
https://example.com/image.jpg would now be
https://example.com/image_medium.jpg
"""
url_parts = self.thumbnail.url.rsplit('.')
@michaelhelmick
michaelhelmick / style.css
Created December 27, 2018 17:56
Facebook Recent Share/Star Style
body {
background-color: transparent;
margin: 0px auto;
overflow: hidden;
}
._4-u2 {
border: none;
}
class MyModel(models.Model):
can_connect_twitter = models.BooleanField(default=False)
can_connect_facebook = models.BooleanField(default=False)
class PermissionSerializer(serializers.ModelSerializer):
class Meta:
fields = ('can_connect_twitter', 'can_connect_facebook',)
class SerializerMethodKwargField(serializers.SerializerMethodField):
def __init__(self, *args, **kwargs):
default_args = [
'read_only', 'write_only', 'required', 'default', 'initial', 'source', 'label',
'help_text', 'style', 'error_messages', 'validators', 'allow_null']
kwargs_to_del = []
self.method_kwargs = {}
for kwarg in kwargs:
if kwarg not in default_args: