This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Author: Kris Dorosz <[email protected]> | |
# This git pre commit hook will apply black formatting before any commit and make sure all tracked files are reformatted | |
echo "Using" `black --version` | |
black --check . 2>/dev/null | |
if [ $? -ne 0 ]; then | |
echo "Reformatting:" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import statsd | |
from django.conf import settings | |
statsd_client = statsd.StatsClient( | |
settings.METRICS_STATSD_HOST, settings.METRICS_STATSD_PORT | |
) | |
def metric_counter(key, value=1): | |
if settings.METRICS_ENABLED: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Author: Kris Dorosz | |
# Enter the root directory of your project and type `squash` | |
# This should squash all not tracked by git migrations and remove the old files | |
import delegator | |
from collections import defaultdict | |
import sys | |
from subprocess import call |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import datetime | |
class MeasureDuration: | |
def __init__(self, title: str = "Total time taken %s"): | |
self.start = None | |
self.end = None | |
self.title = title |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
def zstd_readline(filename, chunksize=zstd.DECOMPRESSION_RECOMMENDED_OUTPUT_SIZE): | |
with open(filename, 'rb') as fh: | |
with zstd.ZstdDecompressor().stream_reader(fh) as reader: | |
leftovers = '' | |
while True: | |
chunk = reader.read(chunksize).decode('utf-8') | |
if not chunk: | |
break |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
def calculate_initial_compass_bearing(pointA, pointB): | |
""" | |
Calculates the bearing between two points. | |
The formulae used is the following: | |
θ = atan2(sin(Δlong).cos(lat2), | |
cos(lat1).sin(lat2) − sin(lat1).cos(lat2).cos(Δlong)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example usage: | |
# class Car(models.Model): | |
# class Colors(ChoiceEnum): | |
# RED = 'red' | |
# WHITE = 'white' | |
# BLUE = 'blue' | |
# | |
# color = models.CharField(max_length=5, choices=Colors.choices(), default=Colors.RED) | |
# | |
# Querying requires an extra word to type though... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import re | |
import sys | |
from functools import wraps | |
import logging | |
logger = logging.getLogger(__name__) | |
WARN_ON_MISSING = True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def pprint(data, ident=2, start_ident=0, ident_char=' ', inside_dict=False, inside_list=False, line_length=80, | |
line_context=0): | |
if not inside_dict: | |
print(ident_char * start_ident, end='') | |
if len(repr(data)) + start_ident + line_context < line_length: | |
print(repr(data) + (',' if inside_dict or inside_list else '')) | |
return | |
elif isinstance(data, dict): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DisableMigrations(object): | |
def __contains__(self, item): | |
return True | |
def __getitem__(self, item): | |
return None |
NewerOlder