Skip to content

Instantly share code, notes, and snippets.

from django.core.management.commands.makemigrations import Command as BaseCommand
from django.db.migrations.autodetector import MigrationAutodetector
def monkeypatch(patient, key):
original = getattr(patient, key)
def foo(func):
def inner(*args, **kwargs):
return func(original, *args, **kwargs)
@strokirk
strokirk / bitbucket-pr-title.user.js
Last active February 20, 2023 09:37
UserScript to make Bitbucket PR tab titles more information dense
// ==UserScript==
// @name Bitbucket PR Title
// @namespace https://gist.github.com/strokirk
// @version 1.0
// @description Make Bitbucket PR tab titles more information dense
// @author Dan Strokirk
// @match https://bitbucket.org/*/pull-requests/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=bitbucket.org
// @grant none
// ==/UserScript==
@strokirk
strokirk / svg-viewbox.js
Created November 23, 2020 11:03
Calculate the viewBox of an SVG element
function calculateViewBox(svgString) {
// Get the bounding-box of a SVG element, formatted to use as it's viewBox
let d = document.createElement("div")
d.innerHTML = s
document.body.appendChild(d)
let r = d.firstElementChild.getBBox()
return `${r.x} ${r.y} ${r.width} ${r.height}`
}
@strokirk
strokirk / README.md
Last active November 18, 2020 11:37
Movie API

Introduction

Add the mine counts to a completed Minesweeper board.

Minesweeper is a popular game where the user has to find the mines using numeric hints that indicate how many mines are directly adjacent (horizontally, vertically, diagonally) to a square.

In this exercise you have to create some code that counts the number of mines adjacent to a given empty square and replaces

# Install xcode command line tools, required by brew and pyenv
echo "Performing xcode installation. A prompt will open."
echo 'NOTE: You must select "install", the right-most alternative!'
xcode-select --install
echo
echo
if [ ! -f ~/.ssh/id_rsa.pub ]; then
echo "Creating a SSH key you can use with Github"
usage: pytest [options] [file_or_dir] [file_or_dir] [...]
positional arguments:
file_or_dir
-s, --show-output Show print and stdio output as it happens.
-x, --exitfirst Exit instantly on first error or failed test.
-k EXPRESSION Only run tests matching the [substring EXPRESSION]. example: -k 'bla and not bla2'
-m MARKEXPR Only run tests matching the [mark EXPRESSION]. example: -m 'mark1 and not mark2'.
--maxfail=num Exit after first num failures or errors.
@strokirk
strokirk / git-add-labels.bash
Last active April 30, 2020 05:45
CLI script to add GitHub labels to the currently checked out PR
#!/usr/bin/env bash
# git-add-labels
#
# Adds labels to the PR of the currently checked out branch.
#
# Usage:
#
# git-set-label Label "Label with Spaces" "Label 3"
@strokirk
strokirk / queries.mysql
Last active May 29, 2018 08:20
Database Information
SELECT * FROM INFORMATION_SCHEMA.PROCESSLIST WHERE `INFO` IS NOT NULL;
SELECT id, user, host, db, command, time, state, SUBSTRING(info, 1, 119) FROM INFORMATION_SCHEMA.PROCESSLIST WHERE `INFO` IS NOT NULL;
def pretty(html):
from bs4 import BeautifulSoup
print(BeautifulSoup(html).prettify())
def box(s):
print()
print()
print("┌" + ("─" * (len(s) + 2)) + "┐")
print("│ " + s + " │")