Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am warlo on github.
  • I am hanswilw (https://keybase.io/hanswilw) on keybase.
  • I have a public key ASD9M0vIYegMp78cEsRGM3N-PRBywka8tB7mO8n_tnR3Dwo

To claim this, I am signing this object:

@warlo
warlo / snake_case_codemod.py
Created October 10, 2019 11:03
Codemod that converts camelCased python testcases to snake_case
import re
import codemod
import inflection
REG = r"(.*)(test\w*[A-Z]\w*)(\(.*)"
test_regex = re.compile(REG)
def snake_patches(list_of_lines):
patches = []
@warlo
warlo / queryset_in_batches.py
Created August 21, 2018 08:26
Batch querysets without slicing them for .update() etc.
def queryset_in_batches_non_slicing(queryset, chunk_size=1000):
"""
Iterate over a Django queryset that is ordered by primary key.
Differs from `queryset_batch_iterator` by not slicing the queryset and filters naively on
upper and lower bounds using pk and chunk size. This allows queryset operations to be performed
such as `.update()` and `.delete()`
"""
pk = 0
@warlo
warlo / trailing-comma-codemod.py
Created August 8, 2018 12:20
Quick and dirty python3 codemod manipulating files to add commas. Requires flake8 with flake8-commas package in env
#!/usr/bin/env python3
import subprocess
FLAKE_COMMA_KEY = 'C812'
def run_flake():
"""
Helper method to run flake8 as bash script
"""

Keybase proof

I hereby claim:

  • I am hanswilw on github.
  • I am hanswilw (https://keybase.io/hanswilw) on keybase.
  • I have a public key ASC29AvW0gDx5i8-oh8Utls2o5fdmTApYrwgF9BNWgvsrQo

To claim this, I am signing this object: