Skip to content

Instantly share code, notes, and snippets.

View kevinlondon's full-sized avatar

Kevin London kevinlondon

View GitHub Profile
#
# Google I/O 2014 secret invite code finder
#
# Blake Caldwell, 2014
#
# Blog Post: http://blakecaldwell.net/blog/2014/4/23/solving-a-2014-google-io-secret-invite-puzzle.html
#
# Repeatedly hit https://developers.google.com looking two-colored "I/O" on the page,
# with a secret code in comments below it. Using the color codes of the "I" and "O",
# calculate the 6-character Google URL-shortened link code, and print the code out.
@kevinlondon
kevinlondon / uuid_benchmarks.py
Last active August 29, 2015 14:04
MySQL UUID Field Benchmarks
#!/usr/bin/env python
import MySQLdb
import logging
import uuid
import time
import random
from contextlib import contextmanager
from binascii import unhexlify, hexlify
@kevinlondon
kevinlondon / uuid_benchmark.py
Last active August 29, 2015 14:04
UUID Byte Benchmark Test for Cpython
import uuid
import time
import sys
from binascii import unhexlify
N = int(sys.argv[1])
class UpdatedUUID(uuid.UUID):
@kevinlondon
kevinlondon / migration.md
Created January 12, 2016 22:04 — forked from booherbg/migration.md
Migrating from Elixir to SQLAlchemy declarative

I have a project that's a few years old, but needs some maintenance. Since I last worked on the project, two major things have happened. First, Elixir -- a declarative layer on top of SQLAlchemy -- has not been maintained. Secondly, SQLAlchemy now has its own declarative layer.

Rather than continue using Elixir, I decided to migrate my data models to use the new SQLAlchemy declarative layer, which interestingly enough appear to be relatively compatible with Elixir's philosophy.

The first thing I did was do a direct mapping in my model columns and update the import statements.

# from Elixir import Entity, Field, DateTime, Unicode, Integer, Boolean, setup_all, create_all, session, metadata
from sqlalchemy import Column, DateTime, String, Integer, ForeignKey, Boolean
from sqlalchemy.ext.declarative import declarative_base
#!/usr/bin/env python
"""
Plot histogram from list of dates
Usage
=====
Feed newline separated unix time via STDIN.
Ex.1: plot repository activity::
from sqlalchemy.orm import declarative_base, scoped_session, sessionmaker
from sqlalchemy.ext.declarative.base import _declarative_constructor
from sqlalchemy import Column, Integer, ForeignKey, create_engine
engine = create_engine(# engine init code here)
session = scoped_session(sessionmaker(bind=engine))
class CustomBase(object):
@kevinlondon
kevinlondon / site.yml
Last active September 15, 2016 20:18
Initial site.yml
- name: Configure application
hosts: all
become: true
become_method: sudo
vars:
repository_url: https://github.com/kevinlondon/flask-hello-world.git
repository_path: /home/vagrant/flask-hello-world
tasks:
- name: Install packages
@kevinlondon
kevinlondon / Vagrantfile
Created April 21, 2016 20:07
Initial Vagrantfile for Devops From Scratch article
# -*- 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|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
server {
listen 80;
location / {
include proxy_params;
proxy_pass http://unix:/tmp/hello_world.sock;
}
}
description "hello-world"
start on (filesystem)
stop on runlevel [016]
respawn
setuid nobody
setgid nogroup
chdir {{ repository_path }}