Skip to content

Instantly share code, notes, and snippets.

@zeimusu
zeimusu / mentalist.py
Last active August 29, 2015 14:15
A little guessing game, "Mentalist poker" http://www.benefactum.ca/?p=274
#!/usr/bin/env python3
import random
import os
import sys
"""
Mentalist Poker http://www.benefactum.ca/?p=274
1. Each player starts with 20 chips or counters of some sort, a screen to hide
them, and a “betting line,” perhaps a piece of string or a pencil, placed
horizontally in front of him (but behind the screen). Chips placed in front of
@zeimusu
zeimusu / gantt.py
Last active August 29, 2015 14:14 — forked from t2ru/gantt
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import datetime as dt
import numpy
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.dates as md
import locale
from functools import reduce
locale.setlocale(locale.LC_ALL, "")
@zeimusu
zeimusu / logisticmap.py
Created December 23, 2014 11:26
Bifurcation diagram for the logistic map n-> r n (n-1). Also called Feigenbaum diagram
import turtle as t
xstart = 3.2
ystart = 0
xend = 4
yend = 1
xstep = 0.5*(xend-xstart)/t.screensize()[0]
convergesteps = 100
@zeimusu
zeimusu / moonlander.py
Created November 1, 2014 10:24
Usbourne Computer Space Games was a type-in computer games book from the 1980s. This is a version of "Moonlander" game. Original BASIC by Daniel Isaaman and Jenny Tyler
#!/usr/bin/env python3
# Usbourne Computer Space Games was a type-in computer games book
# from the 1980s. This is a version of "Moonlander" game.
# Original BASIC by Daniel Isaaman and Jenny Tyler
from time import sleep
print(chr(27) + "[2J") # Clear screen
print("Moonlander")
#Set the starting values
@zeimusu
zeimusu / traitor.py
Created November 1, 2014 10:17
Usbourne Computer Battlegames was a type-in computer games book from the 1980s. This is a version of "Battle at Traitors Castle" game. Original BASIC by Daniel Isaaman and Jenny Tyler
#!/usr/bin/env python3
#Usbourne Computer Battlegames was a type-in computer games book
#from the 1980s.
#This is a version of "Battle at Traitors Castle" game.
#Original BASIC by Daniel Isaaman and Jenny Tyler
import curses
@zeimusu
zeimusu / gravity.py
Last active August 29, 2015 13:56
A gravity simulator. There are several choices for the integration method. I've found verlet to be most stable
#!/usr/bin/env python3
import tkinter as tk
import numpy as np
from numpy import sin, cos, sqrt
G = 6.67384e-11 # m^3 kg-1 s-2
DEG = np.pi / 180
AU = 1.49597871e11 # for converting to meters
METRE = 1 / 1.49597871e11 # for converting to AU
@zeimusu
zeimusu / battle.kv
Last active January 3, 2016 12:39
Fighting Fantasy are a series of "choose your own adventure" books. This is a kivy app that implements the fighting protocol.
#:kivy 1.0.0
<Battle>:
hp_player: player_stam
hp_monster: monster_stam
sk_player: player_skill
sk_monster: monster_skill
GridLayout:
@zeimusu
zeimusu / changes.py
Last active December 31, 2015 14:49
Simulate church bell changes ringing. It requires six .wav files representing six bells. They should be less than five seconds long. You might try for bells pitched at C,D,E,G,A,C. The output is written to changes.wav
#!/usr/bin/env python3
# Simulate church bell changes ringing.
# It requires six .wav files representing six bells.
# They should be less than five seconds long.
# You might try for bells pitched at C,D,E,G,A,C.
#
# The output is written to changes.wav
import random
@zeimusu
zeimusu / quote.py
Created October 9, 2013 20:18
UDP server and client for the port 17 "Quote of the day" service Sits on UDP 17 and serves a quote in response to any request.
#!/usr/bin/env python3
from socket import *
import sys
s = socket(AF_INET,SOCK_DGRAM)
try:
port = int(sys.argv[2])
except ValueError:
@zeimusu
zeimusu / mathsquizcgi.py
Last active December 23, 2015 15:59
Simple python framework for multiple choice quizzes. It has interfaces for running the quiz on the console or as a cgi script. The cgi interface can be used with jqmath.
#!/usr/bin/env python3
## Example of using the jqmath library.
import cgi
from multipletest import Quiz
mathsq= Quiz("Trig quiz")