Skip to content

Instantly share code, notes, and snippets.

@stantonk
stantonk / date_xrange.py
Created August 19, 2015 18:24
python datetime xrange generator
def date_xrange(s_dt, e_dt, inclusive=False):
ONE_DAY = timedelta(days=1)
days = (e_dt - s_dt).days
days = days + 1 if inclusive else days
return (s_dt + i*ONE_DAY for i in range(0, days))
@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;
@stantonk
stantonk / prove_signed_post_request_fail.py
Created November 9, 2015 19:10
Demonstrate bug in signing of POST requests in instagram/python-instagram
# -*- coding: utf-8 -*-
from instagram.client import InstagramAPI
import time
access_token = "REDACTED"
api = InstagramAPI(access_token=access_token, client_id='REDACTED', client_secret='REDACTED')
media_id = 'REDACTED'
response = api.media(media_id=media_id)
@stantonk
stantonk / 0_reuse_code.js
Created November 15, 2015 21:37
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@stantonk
stantonk / get_stats.py
Last active November 4, 2017 14:29
Get a histogram, mean, median, stddev, and percentiles from a pipe on the command line with numpy
#!/usr/bin/env python
"""
Note: requires numpy. `sudo pip install numpy`
Example:
$ echo -e "1\n2\n5\n10\n20\n" | get-stats
mean=7.6
median=5.0
std=6.94550214167
@stantonk
stantonk / Vagrantfile
Created January 22, 2016 06:17
Provision Jenkins + Docker in Vagrant w/ Oracle JVM Java 8.
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/trusty64"
@stantonk
stantonk / keybase.md
Created May 27, 2016 16:20
keybase.md

Keybase proof

I hereby claim:

  • I am stantonk on github.
  • I am stantonk (https://keybase.io/stantonk) on keybase.
  • I have a public key whose fingerprint is 21AE 63EF 74EC 1D5D C904 98A8 1538 E2F1 20F5 28F9

To claim this, I am signing this object:

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
@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 / pre-push.sh
Created December 5, 2016 20:05
Run unittests as a pre-push hook to avoid merging code that fails tests.
#!/usr/bin/env bash
################################################################################
# Use as a global mercurial/git pre commit or pre push hook to detect the type
# of project and run unittests before allowing a commit or push to a remote
# repository.
#
# Handy so that you don't have to remember to add test running hooks to every
# repo clone/fork you have.
################################################################################
echo "run-test-hooks executing..."