Skip to content

Instantly share code, notes, and snippets.

View blackrobot's full-sized avatar
🖖
coffee

Damon Jablons blackrobot

🖖
coffee
View GitHub Profile
@blackrobot
blackrobot / iina-input.conf
Last active August 30, 2018 21:37
Custom keybinding config for IINA
# ###
# damon.conf - IINA keybindings
# ###
# Copied from the default input config for IINA
#
# Documentation can be found here:
# * https://github.com/lhc70000/iina/wiki/Manage-Key-Bindings
# * https://mpv.io/manual/stable/#command-interface
#@iina Shift+Meta+v video-panel
import contextlib
@contextlib.contextmanager
def managed_records(shelve_db_names, file_names):
try:
shelve_dbs = []
for name in shelve_db_names:
db = shelve.open(name, protocol=pickle.HIGHEST_PROTOCOL)
shelve_dbs.append(db)
@blackrobot
blackrobot / github-refined.css
Last active July 12, 2018 22:01
Github Refined Extra CSS
.blob-code-inner,
.blob-num,
.highlight pre,
.files > tbody > tr > td.content a {
font-family: "Operator Mono" !important;
}
.files > tbody > tr > td.content a {
font-size: 13.3px;
}
.pl-c, .pl-e {
@blackrobot
blackrobot / devdocs.json
Last active December 27, 2021 20:02
preferences from devdocs.io
{
"analyticsConsentAsked": "1",
"analyticsConsent": "1",
"autoInstall": "1",
"docs": "css/html/http/javascript/dom/bootstrap~5/django~4.0/django_rest_framework/docker~19/git/nginx/pandas~1/postgresql~14/postgresql~11/python~3.10/react/redis/redux/redux~3/typescript/webpack~5/werkzeug~2.0",
"tips": "KeyNav",
"theme": "auto"
}
@blackrobot
blackrobot / how-to-set-up-stress-free-ssl-on-os-x.md
Created January 31, 2018 01:03 — forked from jed/how-to-set-up-stress-free-ssl-on-os-x.md
How to set up stress-free SSL on an OS X development machine

How to set up stress-free SSL on an OS X development machine

One of the best ways to reduce complexity (read: stress) in web development is to minimize the differences between your development and production environments. After being frustrated by attempts to unify the approach to SSL on my local machine and in production, I searched for a workflow that would make the protocol invisible to me between all environments.

Most workflows make the following compromises:

  • Use HTTPS in production but HTTP locally. This is annoying because it makes the environments inconsistent, and the protocol choices leak up into the stack. For example, your web application needs to understand the underlying protocol when using the secure flag for cookies. If you don't get this right, your HTTP development server won't be able to read the cookies it writes, or worse, your HTTPS production server could pass sensitive cookies over an insecure connection.

  • Use production SSL certificates locally. This is annoying

@blackrobot
blackrobot / csv_utils.py
Created January 23, 2018 21:40
Mixins for working with CSV files in Python
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
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:
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]
@blackrobot
blackrobot / batch.py
Last active December 29, 2017 22:46
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 December 20, 2017 22:42
Elasticsearch python dsl search query load all outline
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)