Skip to content

Instantly share code, notes, and snippets.

View jdmansour's full-sized avatar

Jason Mansour jdmansour

View GitHub Profile
@jdmansour
jdmansour / rps.py
Last active August 23, 2021 16:58
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.
""" 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
@jdmansour
jdmansour / test.html
Created May 14, 2013 18:03
Test if the browser caches the current state of the document, or just the initial state. Open test.html, wait a few seconds, and click on the link. Then click the back button. The counter should be at the value it had when you left the page.
<html>
<head>
<script>
function tick() {
var dyn = document.getElementById("dyn");
var value = parseInt(dyn.innerHTML);
dyn.innerHTML = value + 1;
}
window.setInterval(tick, 1000);
</script>
@jdmansour
jdmansour / rubberband.py
Created April 18, 2013 16:38
A little program to show rubberbanding with pygtk. Click and drag the rubberband to select points.
"""
A little program to show rubberbanding with pygtk.
Click and drag the rubberband to select points.
"""
import gtk
import random
from math import pi
@jdmansour
jdmansour / gui_slowdown.py
Created March 31, 2013 10:51
A little program to show how a gtk gui gets unresponsive when using gtk2reactor and downloading a file with twisted.web.client.HTTPDownloader.
"""
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: