Skip to content

Instantly share code, notes, and snippets.

klenwell klenwell

Block or report user

Report or block klenwell

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@klenwell
klenwell / stateful_model.py
Last active Dec 17, 2015
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.
View stateful_model.py
# -*- 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 / action.class.php
Last active Dec 17, 2015
Wikkawiki Action Class: An abstract class that can be extended to create cleaner wikkawiki actions. For more information, see http://klenwell.com/is/WikkaBaseActionClass.
View action.class.php
<?php
/**
* Wikka Action Class
*
* An abstract class that can be extended for wikka action classes.
*
*
* @package Action
* @author Tom Atwell <klenwell@gmail.com>
* @copyright Copyright 2010, Tom Atwell <klenwell@gmail.com>
@klenwell
klenwell / dict_object.py
Created May 26, 2013
Converts Python dict to object so that d['some_key'] can be accessed at d.some_key
View dict_object.py
# -*- coding: utf-8 -*-
"""
DictObject
Converts dict to object
"""
from collections import defaultdict
class DictObject(defaultdict):
def __getattr__(self, key):
return self[key]
@klenwell
klenwell / Ansible-Wikka-Install.md
Last active Aug 29, 2015
Sets up Wikka repository locally to test fresh installation
View Ansible-Wikka-Install.md

This playbook automates local installation of a Wikka wiki webserver:

ansible-playbook -v -i .dev/deploy/dev .dev/deploy/dev_install.yml --connection=local
@klenwell
klenwell / stack-search.py
Created Jul 20, 2014
Python script to search Stack Overflow by tags for questions still worth answering using API
View stack-search.py
"""
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 / natural_date.py
Last active Aug 29, 2015
Python parsedatetime library: enforce current year
View natural_date.py
#
# 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 / websphere.yml
Last active Dec 19, 2018
Ansible Playbook to Install WebSphere MQ on Debian Server
View websphere.yml
#
# This playbook assumes the WebSphere MQ file provided by IBM has already been
# downloaded to a specific directory (target.wd) on the server.
#
# ${target.wd} is a variable representing the working directory on the target
# server the MQ client will be installed.
#
# Note: Although this playbook is designed to be able to be run independently,
# it is in fact part of a longer playbook and therefore may have some other
# unexpected dependencies not reflected here.
@klenwell
klenwell / trueskill.py
Last active Aug 29, 2015
Trueskill Prediction Simulation
View trueskill.py
import random
from math import sqrt
from trueskill import TrueSkill, Rating, quality_1vs1, rate_1vs1, BETA
from trueskill.backends import cdf
# From https://github.com/sublee/trueskill/issues/1#issuecomment-10491635
def win_probability(team_rating, opponent_rating):
delta_mu = team_rating.mu - opponent_rating.mu
denom = sqrt(2 * (BETA * BETA) + pow(team_rating.sigma, 2) + pow(opponent_rating.sigma, 2))
win_prob = cdf(delta_mu / denom)
View Python-Coin-Flip-Problem.md

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 / djia.py
Created Jun 25, 2015
Simple Scraper for Dow Jones Industrial Average
View djia.py
#
# 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
#
You can’t perform that action at this time.