This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def beats(a, b): | |
""" Rock paper scisors. Rock = 0, Paper = 1, Scisors = 2 | |
(but any three consecutive numbers work). | |
Returns 1 if `a` beats `b`, 2 if `a` looses to `b`, and 0 if | |
`a` and `b` are equal. | |
The idea is that if `a` is one more than `b`, `a` wins. | |
Scisors beats paper: 2 - 1 = +1. But it also must wrap around: | |
Rock beats scisors: 0 - 2 = -2. In modulo 3, where you only have | |
0, 1, 2, that is 1. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" A little bayesian updating example. | |
Shows adding points one by one, or all at once. | |
Jason Mansour <jd.mansour@gmail.com>, 2015""" | |
from itertools import izip | |
from math import exp, pow, sqrt | |
import math | |
import random | |
import operator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script> | |
function tick() { | |
var dyn = document.getElementById("dyn"); | |
var value = parseInt(dyn.innerHTML); | |
dyn.innerHTML = value + 1; | |
} | |
window.setInterval(tick, 1000); | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
A little program to show rubberbanding with pygtk. | |
Click and drag the rubberband to select points. | |
""" | |
import gtk | |
import random | |
from math import pi | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
A little program to show how a gtk gui gets unresponsive when using | |
gtk2reactor and downloading a file with twisted.web.client.HTTPDownloader. | |
Enter the url (HTTP) of a large file into the textbox and press start. | |
The progress bar becomes visibly jerky, while I'd expect that it stays | |
smooth. Apparently twisted doesn't return control to GTK fast enough. | |
To set up a mini web server, you can use: |