Skip to content

Instantly share code, notes, and snippets.

View jasonbartz's full-sized avatar

Jason Bartz jasonbartz

View GitHub Profile
@jasonbartz
jasonbartz / recycler.py
Created October 22, 2018 14:28
lambda recycler
"""
Waiter Lambda
This lambda waits indefinitely for an action, sleeping every n seconds
until it succeeds, fails or times out.
"""
import json
import os
import time
import boto3
@jasonbartz
jasonbartz / keybase.md
Created August 15, 2018 11:37
Keybase proof

Keybase proof

I hereby claim:

  • I am jasonbartz on github.
  • I am jasonbartz (https://keybase.io/jasonbartz) on keybase.
  • I have a public key ASDeA2DP_ksxd-RWZjq1xADBcsbZXdaJ70ctNh7so2KevQo

To claim this, I am signing this object:

@jasonbartz
jasonbartz / kms.sh
Last active November 7, 2018 00:09
simple kms cli
#!/bin/bash
PROFILE=""
if [ -z "$AWS_PROFILE" ]; then
PROFILE="--profile $AWS_PROFILE"
fi
case $1 in
encrypt)
aws kms encrypt ${PROFILE} --key-id $2 --plaintext $3 --output text --query CiphertextBlob
@jasonbartz
jasonbartz / recover_shards.py
Created November 24, 2015 23:09
How to recover elastic search shards
"""
Inspired by https://t37.net/how-to-fix-your-elasticsearch-cluster-stuck-in-initializing-shards-mode.html
3 node cluster, when 2 nodes have been terminated simultaneously
Not guaranteed to prevent data loss or fully recover lost data
"""
import requests
import json
@jasonbartz
jasonbartz / redirect_stdout.py
Created January 17, 2014 19:38
A simple decorator to redirect stdout somewhere else
"""
A simple decorator to redirect stdout somewhere else
# Example usage
```
def my_write_func(text, **kwargs):
// do something with text
pass
function objectIdWithTimestamp(timestamp) {
// Convert string date to Date object (otherwise assume timestamp is a date)
if (typeof(timestamp) == 'string') {
timestamp = new Date(timestamp);
}
// Convert date object to hex seconds since Unix epoch
var hexSeconds = Math.floor(timestamp/1000).toString(16);
// Create an ObjectId with that hex timestamp
@jasonbartz
jasonbartz / uwsgi_on_pypy.md
Last active August 16, 2017 11:02
uwsgi and pypy

Deploying pypy on uwsgi

Instructions are kind of sporadic around the internet, so I thought I would gather them all in one place. The following example uses a Flask app as the thing deployed. You should only have to this once, and then you can pass the bin around.

Requirements

  • pypy 2.x (tested)
  • uwsgi 1.9.11+ (trunk as of this gist)

Build translated pypy binary and pypy lib.

@jasonbartz
jasonbartz / bright.py
Created April 22, 2013 12:39
For posting lots of things really fast.
import datetime
import tornado.ioloop
import tornado.web
import motor
from tornado import gen
db = motor.MotorClient().open_sync().test
@jasonbartz
jasonbartz / geo_no_db.py
Created April 1, 2013 20:34
Geo without a database
from django.contrib.gis.gdal import DataSource
from django.contrib.gis.gdal.geometries import Point
# Get the DC voting districts shape (from the Census Bureau)
ds = DataSource('/path/to/my/shapefiles/tl_2012_11_vtd10/tl_2012_11_vtd10.shp')
# Grab the layer that contains all of the shape data
layer = ds[0]
def get_shape_contains(layer, geometry):
# Iterate over every shape
@jasonbartz
jasonbartz / Raising the roof
Created September 20, 2011 19:04
Bowers Bonanza
<html>
<head>
<title>raising the roof!</title>
<style type="text/css">
body {
background:url('http://28.media.tumblr.com/tumblr_lr4652g4zX1qhuxd0o1_250.gif') repeat;
}
</style>
</head>