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 / 6.1.2 Model Inheritance.md
Created October 2, 2024 17:38
Two Scoops Django 3.x Best Practices: 6.1.2 Be Careful With Model Inheritance

6.1.2 Be Careful With Model Inheritance

Model inheritance in Django is a tricky subject. Django provides three ways to do model inheritance: abstract base classes, multi-table inheritance, and proxy models.

Warning

Django Abstract Base Classes ≠ Python Abstract Base Classes
Don’t confuse Django abstract base classes with the abstract base classes in the Python standard library’s abc module, as they have very different purposes and behaviors.

Here are the pros and cons of the three model inheritance styles. To give a complete comparison, we also include the option of using no model inheritance to begin with:

@blackrobot
blackrobot / fix-zenhub-csv.py
Created March 3, 2023 19:04
Remove broken quoting in CSV exports from ZenHub
#!/usr/bin/env python3
"""
Read a CSV file from stdin and write a fixed CSV file to stdout.
Example:
$ cat zenhub.csv | ./fix-zenhub-csv.py > fixed.csv
$ fix-zenhub-csv.py zenhub.csv > fixed.csv
"""
@blackrobot
blackrobot / migrate_zenhub_issues.py
Created February 14, 2023 18:27 — forked from m1yag1/migrate_zenhub_issues.py
Migrate Issues from ZenHub to GH Projects
# We first create a spreadsheet with the ZenHub Pipeline and GitHub Project Column mapping
# Then, we moved all the issues manually into an "Unsorted" column in our GitHub Project
# Read through each of the issues that is in the Unsorted column and move them to the correct column
# if it's in the spreadsheet.
# To run:
# pip install python-dotenv ghzh-clients
import csv
import os
@blackrobot
blackrobot / django-example.html
Created December 30, 2020 22:37
Example of OctoLinker mangling the HTML of a django source file
<!-- OctoLinker Enabled -->
<tr>
<td id="L4" class="blob-num js-line-number" data-line-number="4"></td>
<td id="LC4" class="blob-code blob-code-inner js-file-line highlighted">
<span class="pl-k">from</span>
<a data-pjax="true" class="octolinker-link" href="https://www.djangoproject.com">
<span class="pl-s1">django</span>.
<span class="pl-s1">apps</span>
<span class="pl-s1">
<span class="pl-token" data-hydro-click="{&quot;event_type&quot;:&quot;code_navigation.click_on_symbol&quot;,&quot;payload&quot;:{&quot;action&quot;:&quot;click_on_symbol&quot;,&quot;repository_id&quot;:4164482,&quot;ref&quot;:&quot;a9a7421ab83361746549d574ca13438ba93c95fe&quot;,&quot;language&quot;:&quot;Python&quot;,&quot;originating_url&quot;:&quot;https://github.com/django/django/blob/a9a7421ab83361746549d574ca13438ba93c95fe/django/contrib/auth/checks.py&quot;,&quot;user_id&quot;:85895}}" data-hydro-click-hmac="a987f9b6fad47553f0ed81d9247442e2c673144f316ce4e8b99e506dae4ab0f5">apps</span>
'''
put this in $PROJECT/.tmp/home/.config/ptpython/config.py
'''
from __future__ import unicode_literals
from prompt_toolkit.keys import Keys
from ptpython.layout import CompletionVisualisation
@blackrobot
blackrobot / 01-readme.md
Created April 22, 2020 16:16
Debugging info for lichess.org Stockfish WASM error

Redirect To File Download

To use this, replace all of the placeholder content in 01.template.html with the actual file path and name.

Then save the resulting html file as index.html to be used as the S3 bucket index as well as the error page for redirects.

Example

@blackrobot
blackrobot / .bashrc
Created February 3, 2020 17:36
Simplified remote dotfiles
# shellcheck shell=bash disable=SC2164,SC1117
# ~/.bashrc: executed by bash(1) for non-login shells.
# Note: PS1 and umask are already set in /etc/profile. You should not
# need this unless you want different defaults for root.
# PS1='${debian_chroot:+($debian_chroot)}\h:\w\$ '
# umask 022
export TERM='xterm-256color'
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
FROM python:3.7
# Install the dependencies for R
RUN apt-get update && apt-get install -y r-base r-base-dev r-recommended
# Add all of the scripts to the /opt/app/ path inside of the image
ADD . /opt/app/
# Change the working directory inside of the image to /opt/app/
WORKDIR /opt/app/