Skip to content

Instantly share code, notes, and snippets.

Avatar

Kevin DeLoach kdeloach

View GitHub Profile
@kdeloach
kdeloach / plates.py
Created Jul 19, 2020
Calculate plate orderings for 531 workout
View plates.py
bar = 45
plates = [45, 35, 25, 10, 10, 5, 5, 2.5]
min_weight = bar
max_weight = bar + int(sum(plates) * 2)
def calculate_perms(plates):
result = set()
for i in range(len(plates)):
View plates.py
bar = 45
plates = [55, 45, 35, 25, 10, 10, 5, 5, 2.5]
min_weight = int(bar + min(plates) * 2)
max_weight = int(bar + sum(plates) * 2)
def greedy(goal):
goal -= bar
@kdeloach
kdeloach / renderers.py
Created Nov 18, 2018
CustomJSONRenderer
View renderers.py
class CustomJSONRenderer(rest_framework_json_api.renderers.JSONRenderer):
"""
Replace references to primary key with `uuid` field value.
"""
@classmethod
def extract_attributes(cls, fields, resource):
obj = super(CustomJSONRenderer, cls).extract_attributes(fields, resource)
obj.pop('uuid')
return obj
View keybase.md

Keybase proof

I hereby claim:

  • I am kdeloach on github.
  • I am kdeloach (https://keybase.io/kdeloach) on keybase.
  • I have a public key ASDcqAZlte89ULtWpAjuIZtxhEJpoc5M6UUGOUewXYhuqAo

To claim this, I am signing this object:

View github_watch.py
"""Set all repositories of a given GitHub organization name for a given user
to watching.
"""
import argparse
import json
import requests
import os
@kdeloach
kdeloach / docker_child_images.sh
Created Jan 22, 2018
Inspect intermediate Docker images
View docker_child_images.sh
#!/bin/bash
set -eu
# Usage: ./docker_child_images.sh <image name>
image_name_or_id=$1
sha1=$(docker images -a | grep $image_name_or_id | head -n 1 | column -t | sed 's/ \+/,/g' | cut -d, -f3)
if [ ! -z "$sha1" ]; then
@kdeloach
kdeloach / delete_dag.sh
Created Aug 22, 2017
Delete Airflow DAG
View delete_dag.sh
#!/bin/bash
dag_id=$1
psql -c "delete from xcom where dag_id='$dag_id'"
psql -c "delete from task_instance where dag_id='$dag_id'"
psql -c "delete from sla_miss where dag_id='$dag_id'"
psql -c "delete from log where dag_id='$dag_id'"
psql -c "delete from job where dag_id='$dag_id'"
psql -c "delete from dag_run where dag_id='$dag_id'"
View simpletrie.py
def make_trie(rows):
trie = {}
for row in rows:
key = row[0]
value = row[1]
trie_append(trie, key, value)
return trie
def trie_append(node, key, value):
View find_merged_branches.sh
#!/bin/bash
# Usage:
# ./find_merged_branches.sh 2>/dev/null | tee output.txt
TMPDIR="$PWD/tmp"
while read repo; do
rm -rf $TMPDIR
url="git@github.com:$repo.git"
git clone $url $TMPDIR 1>&2
@kdeloach
kdeloach / utd_test.py
Created Nov 21, 2016
Urban Tree Database analysis
View utd_test.py
import csv
from modeling.run_model.GrowthModelUrbanTreeDatabase import _formulas
w = csv.writer(self.stdout)
results = []
for itree_region, otm_codes in _formulas.iteritems():
for otm_code, fn in otm_codes.iteritems():
key = '{} {}'.format(itree_region, otm_code)