Skip to content

Instantly share code, notes, and snippets.

@jmoy
jmoy / shapley.py
Last active January 4, 2016 00:29
Simulate the fictitious play dynamic for the game in Shapley (1964).
"""
Simulate the fictitious play dynamic
for the game in section 5.3 of
Shapley, Lloyd S. "Some topics in two-person games."
Advances in game theory 52 (1964): 1-29.
Author: Jyotirmoy Bhattacharya, jyotirmoy@jyotirmoy.net
The author has placed this program in the public domain
@jmoy
jmoy / rwalk.py
Created July 23, 2013 17:03
Visualizing a 2D random walk using Python, Cairo and GTK
#!/usr/bin/python
"""
Random walk on two-dimensional grid
(c) Jyotirmoy Bhattacharya, jyotirmoy@jyotirmoy.net
LICENSE: GPL3
"""
import random
import gtk,gobject,cairo
import math
@jmoy
jmoy / wmedian.py
Created March 5, 2011 06:14
Compute the weighted median
"""
Calculate the weighted median
(c) Jyotirmoy Bhattacharya [jyotirmoy@jyotirmoy.net], 2011
Licence: GPL
"""
import itertools as it
def ecdf(vw):
ans = []
@jmoy
jmoy / pretty-schema.py
Created February 25, 2011 05:00
Create Asciidoc table of MySQL database schema
"""
Create Asciidoc table of MySQL database schema
Usage:
pretty-schema.py <database> <username> [password]
If you have AsciiDoc installed you can use the following to produce a pretty HTML file of your database schema:
pretty-schema.py mydb myusr | asciidoc -a toc - > schema.html
"""
@jmoy
jmoy / centipede.py
Created February 25, 2011 04:57
Keep score for Rosenthal's centipede game
"""
A script to keep score for a version of Rosenthal's centipede game.
The rules are:
1. There are two players.
2. At the beginning of the game the players have 1 point each.
3. The players get turns alternately.
4. On their turn a player can choose to continue (C) or stop (S).
5. If the player chooses C, 1 point is taken from their account
and 2 points are added to the other player's account.
6. If the player chooses S, the game stops.
@jmoy
jmoy / wikiwatch.py
Created February 25, 2011 04:56
Get Wikipedia watchlist as an RSS/ATOM feed
"""Get Wikipedia watchlist as an RSS/ATOM feed
(c) Jyotirmoy Bhattacharya, 2007
Usage: wikiwatch <username> <password> [format]
[format] is either 'rss' or 'atom'
"""
import sys
import xml.sax,xml.sax.handler