Skip to content

Instantly share code, notes, and snippets.

@stantonk
stantonk / django_orm_query_stacktrace.py
Created May 4, 2013 00:49
Django logging config to dump a stack trace for every ORM query, so you can find the code that is producing queries that are icky.
DEBUG=True
LOG_FILE_SIZE=1024*1000
LOGGING = {
'version' : 1,
'disable_existing_loggers':True,
'formatters' : {
'simple' : {
'format' : '%(levelname)s %(name)s %(message)s'
},
apiVersion: v1
kind: Pod
metadata:
name: gpu-test-vector-add
spec:
runtimeClassName: nvidia
restartPolicy: Never
containers:
- name: cuda-container
image: nvcr.io/nvidia/k8s/cuda-sample:vectoradd-cuda10.2
@stantonk
stantonk / get_valid_tlds.py
Last active July 11, 2022 22:36
Updated list of valid TLDs (Top Level Domains). Python script grabs the IANA database and formats it into a set datatype.
# requirements.txt
# pip install requests
# pip install BeautifulSoup4
import codecs
import requests
from bs4 import BeautifulSoup
PER_LINE = 12
@stantonk
stantonk / JDBIjOOQ.java
Last active July 8, 2022 15:06
JDBI + jOOQ. Combine SQL Builder of jOOQ with all the awesomeness of JDBI, but avoid using jOOQ's codegen, having to keep it up to date with schema changes (just update the single query that's changed) or overcomplicating your build process. jOOQ never touches the database.
// see:
// http://jdbi.org/fluent_queries/
// http://www.jooq.org/doc/3.7/manual/getting-started/use-cases/jooq-as-a-standalone-sql-builder/
// Your Java Bean
public static class Reminder {
private long id;
private long customerId;
public Reminder(long id, long customerId) {
@stantonk
stantonk / multitail.sh
Created February 27, 2013 21:43
Unified tail -f of a log file across multiple hosts via ssh.
#!/bin/bash
HOSTS=(PUT, YOUR, HOSTS, HERE)
CMD="tail -f logs/api.log"
echo "Hit CTRL-C to stop"
sleep 0.5
PIDS=""
for host in ${HOSTS[*]}
do
@stantonk
stantonk / scalaforpy
Last active August 28, 2021 10:13
Scala for Python Programmers, examples
/*
Notes:
Despite Scala's appearances, it is, in fact, a Statically Typed language.
It has just eliminated a great deal of the "type vomit" people are used
to seeing in Statically Typed languages (e.g. C, C++, Java). It often
can infer the type on its own. It also combines functional and
object-oriented programming paradigms in a fashion that feels similar
to Python.
*/
@stantonk
stantonk / diff-repos.py
Last active June 30, 2020 18:21
Diff two repositories, file by file, to verify they're the same. Output all diffs if there are any. Written out of our mutual distrust of destructive, history-modifying mercurial extensions.
#!/usr/bin/env python
# authors: @stantonk, @salubriousdave
import os
import sys
import subprocess
def is_hg_repo(path):
hgchkpath = os.path.join(path, '.hg')
return os.path.exists(hgchkpath)
@stantonk
stantonk / Dockerfile
Last active May 6, 2020 21:40
example of using docker container to package a python application
FROM python:3.7
RUN mkdir -p /data
COPY p.py /p.py
RUN pip install click
WORKDIR /
ENTRYPOINT ["python", "p.py"]
@stantonk
stantonk / ConfigLoader.java
Created October 7, 2015 16:43
Using Jackson + Hibernate Validation to load YAML or Java config files and validate configuration key/val pairs are valid.
package default;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.google.common.base.Objects;
import com.google.common.collect.Lists;
import org.hibernate.validator.constraints.NotEmpty;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import re
import sys
# note, currently doesn't handle:
# Jun 29 00:00:03 host tag: message repeated 3 times: [ 192.168.1.1 - - "POST /api/someendpoint/
r = re.compile(r'(\w{3,}\s+\d{2,}\s+\d{2,}:\d{2,}:\d{2,})\s+([\w-]+)\s+([\w-]+):\s+((\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3},?\s?)+)\s+-\s+-\s+\"(GET|POST|PUT|PATCH|HEAD|DELETE) ((\/[\w_]+)+)\/\??(.*) HTTP\/\d\.\d" (\d{3,}) (\d+|-)')
anonymizers = (
(re.compile(r'(\d+,?)+'), 'id'), # one or more optionally csv separated ids