Skip to content

Instantly share code, notes, and snippets.

"""
How Django generates SECRET_KEYs for new Django projects.
See:
https://github.com/django/django/blob/1.7.1/django/core/management/commands/startproject.py#L27
"""
from django.utils.crypto import get_random_string
# Create a random secret_key
@swinton
swinton / http_sig_example.py
Created February 4, 2015 19:22
Shows example programs written in Python that illustrate how to work with version 4 signing in AWS (via http://docs.aws.amazon.com/general/latest/gr/sigv4-signed-request-examples.html).
# AWS Version 4 signing example
# EC2 API (DescribeRegions)
# See: http://docs.aws.amazon.com/general/latest/gr/sigv4_signing.html
# This version makes a GET request and passes the signature
# in the Authorization header.
import sys, os, base64, datetime, hashlib, hmac
import requests # pip install requests
#!/bin/bash
# For more info: https://help.ubuntu.com/community/UbuntuTime#Time_Synchronization_using_NTP
ntpdate ntp.ubuntu.com

Notes

  • All the examples below assume the user's timezone is US/Central.

Basics

All activities from a device

Activity.objects(device="sausages")

Explain plans for activity queries

For help on interpreting see this reference.

All activities from a device

db.activity.find({"device": "sausages"}).explain()
{
@swinton
swinton / notes.md
Last active August 29, 2015 14:13
Notes on using the samples supplied with the Amazon Kinesis Client Library for Python

Host

git clone https://github.com/awslabs/amazon-kinesis-client-python.git
cd amazon-kinesis-client-python/
mkdir vm
cd vm
vagrant init ubuntu/trusty64
# Include in Vagrantfile:
# config.vm.synced_folder "..", "/home/vagrant/existence",
@swinton
swinton / journey.geojson
Last active October 9, 2015 19:28
Journey home, via Iceland!
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@swinton
swinton / receipt.xml
Created November 21, 2014 21:36
A receipt, as seen by Evernote
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<!DOCTYPE recoIndex PUBLIC "SYSTEM"
"http://xml.evernote.com/pub/recoIndex.dtd">
<recoIndex docType="unknown" objType="image"
objID="5f5306f6cda9364ef734165ecaa43d31" engineVersion="6.5.17.7"
recoType="service" lang="en" objWidth="534" objHeight="778">
<item x="173" y="133" w="80" h="22">
<t w="78">Welcome</t>
<t w="46">Wei come</t>
<t w="42">Wei came</t>
@swinton
swinton / stunnel.md
Created November 12, 2014 19:26
Stunnel HOWTO

Basically:

Install stunnel

brew install stunnel

Create /usr/local/etc/stunnel/stunnel.pem

openssl genrsa -out key.pem 2048
var _ = require("underscore");
// A 2-dimensional array of jokes
var jokes = _.shuffle(
[
[
"Why did Santa's helper see the doctor?",
"Because he had a low \"elf\" esteem!\n"
],
[