Skip to content

Instantly share code, notes, and snippets.

🖖
coffee

Damon Jablons blackrobot

🖖
coffee
Block or report user

Report or block blackrobot

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@blackrobot
blackrobot / csv_utils.py
Created Jan 23, 2018
Mixins for working with CSV files in Python
View csv_utils.py
from __future__ import absolute_import, print_function, unicode_literals
from collections import namedtuple
import io
import re
# python 3 backport of the stdlib csv module
# https://github.com/ryanhiebert/backports.csv
from backports import csv
View serializer_drf.py
def validate_data(self, data):
ret = OrderedDict()
errors = OrderedDict()
fields = self._writable_fields
for field in fields:
validate_method = getattr(
self, 'validate_' + field.field_name, None)
primitive_value = field.get_value(data)
try:
View serializer_drf.py
def to_internal_value(self, data):
"""
Dict of native values <- Dict of primitive datatypes.
"""
if not isinstance(data, Mapping):
message = self.error_messages['invalid'].format(
datatype=type(data).__name__
)
raise ValidationError({
api_settings.NON_FIELD_ERRORS_KEY: [message]
View batch.py
from __future__ import print_function, unicode_literals
from six import itertools
def batch(iterable, size):
""" Generates slices of items in groups of `size` length.
>>> for group in batch(range(10), size=4):
print(group)
(0, 1, 2, 3)
@blackrobot
blackrobot / search_query.py
Created Dec 20, 2017
Elasticsearch python dsl search query load all outline
View search_query.py
class SearchQuery(...):
# special search methods, like `def for_name(...)`
def load_db_objects(self):
""" Immediately loads all of the database objects in a single
query, and caches them on each result's `object` property.
"""
result_pks = [x.pk for x in self] # maybe self.execute?
object_query_map = self.model.objects.in_bulk(result_pks)
@blackrobot
blackrobot / chrome-flags.md
Created Dec 13, 2017
Google Chrome Flags
View chrome-flags.md
View findbar.css
@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");
@keyframes scale-in {
0% {
transform: scaleY(0);
}
100% {
transform: scaleY(1);
}
}
@blackrobot
blackrobot / ensure-cert-macos.sh
Created Dec 7, 2017 — forked from koop/ensure-cert-macos.sh
Ensures a certificate is in the macOS system keychain.
View ensure-cert-macos.sh
#!/bin/bash
# Usage
# $ ./install-cert-macos.sh "/path/to/cert"
CERT_PATH="$1"
# First, grab the SHA-1 from the provided SSL cert.
CERT_SHA1=$(openssl x509 -in "$CERT_PATH" -sha1 -noout -fingerprint | cut -d "=" -f2 | sed "s/://g")
# Next, grab the SHA-1s of any standard.dev certs in the keychain.
# Don't return an error code if nothing is found.
View wasavi.exrc
" exrc for wasavi
""
" Wasavi: http://appsweets.net/wasavi/
" Github: https://github.com/akahuku/wasavi
""
""
" Themes:
" - blight
View md-here.highlight.css
/*
Railscasts-like style (c) Visoft, Inc. (Damien White)
*/
.hljs {
display: block;
overflow-x: auto;
/* padding: 0.5em; */
You can’t perform that action at this time.