Skip to content

Instantly share code, notes, and snippets.

View klenwell's full-sized avatar

klenwell klenwell

View GitHub Profile
@klenwell
klenwell / stateful_model.py
Last active December 17, 2015 06:18
Stateful Model (2 files): stateful_model.py: a subclass of Google App Engine db.Model class that functions as a state machine. test_stateful_model.py: unit test for StatefulModel.
# -*- coding: utf-8 -*-
"""
Google App Engine Stateful Model
Subclass App Engine db.Model class so that it may function as a flexible
state machine.
REFERENCES
http://blog.notdot.net/2010/04/Pre--and-post--put-hooks-for-Datastore-models
"""
@klenwell
klenwell / djia.py
Created June 25, 2015 13:44
Simple Scraper for Dow Jones Industrial Average
#
# Simple Scraper for Dow Jones Industrial Average
# With Python 3
#
# INSTALLATION (with pyenv)
# pyenv local 3.4.1
# pip install requests
# pip install beautifulsoup4
# pip install https://github.com/syabro/soupselect/archive/master.zip
#
@klenwell
klenwell / Python-Coin-Flip-Problem.md
Last active August 29, 2015 14:16
Coin Flip Problem

From a comment by aws17576 on MetaFilter:

By the way, I wholeheartedly endorse Persi Diaconis's comment that probability is one area where even experts can easily be fooled. This was demonstrated to me in grad school when my advisor, addressing a roomful of mathematicians, posed this problem:

Person A flips a coin repeatedly, stopping the first time two heads in a row appear. Person B flips a coin repeatedly, stopping the first time a head and then a tail appear in a row. Who will flip the coin more times on average -- A, B, or is there no difference?

He let everyone think for a moment, then took a show of hands. Almost everyone got it wrong.

@klenwell
klenwell / natural_date.py
Last active August 29, 2015 14:04
Python parsedatetime library: enforce current year
#
# Natural Language Date Parsing
# http://stackoverflow.com/q/25089784/1093087
#
import parsedatetime as pdt
from datetime import datetime, date, timedelta
from time import mktime
import pdb
@klenwell
klenwell / stack-search.py
Created July 20, 2014 04:44
Python script to search Stack Overflow by tags for questions still worth answering using API
"""
Search Stack Overflow by tags for questions still worth answering
References:
search API: http://api.stackexchange.com/docs/advanced-search
"""
import stackexchange
import pdb
from datetime import datetime, timedelta
import time
@klenwell
klenwell / Ansible-Wikka-Install.md
Last active August 29, 2015 13:57
Sets up Wikka repository locally to test fresh installation

This playbook automates local installation of a Wikka wiki webserver:

ansible-playbook -v -i .dev/deploy/dev .dev/deploy/dev_install.yml --connection=local