Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / 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 / 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 / stronghold.py
Last active August 29, 2015 14:23
Find a Minecraft stronghold
#Find a minecraft stronghold
#To find a stronghold you need an eye of ender, which you throw into the air.
#Make a note of your current location and the direction in which the eye goes.
#You can find these from the F3 debug screen.
#Move to a second point (it should be reasonably distant from the first)
#Throw the eye again and note the second point and direction. Enter
#the numbers below and run. It outputs the location of the stronghold.
@zeimusu
zeimusu / LoveCalculator.py
Last active December 17, 2015 20:47
Use a numeralogical technique known to teens from the '80s to predict the love percentage from names
#!/usr/bin/env python3
#Use: LoveCalculator.py "Katy Perry" "Justin Bieber"
import sys
import itertools
def pairwise(iterable):
"s -> (s0,s1), (s1,s2), (s2, s3), ..."
a, b = itertools.tee(iterable)
next(b, None)
return zip(a, b)
@zeimusu
zeimusu / Time
Last active December 21, 2015 06:18
This gist provides a web page (time.php) that contains an image that is updated hourly. It is intended to be used with a directory of images with hashed filenames, generated by renameseq.py and shafile.py, and the event server timesse.php to make a "slow movie", rather like xkcd.com/time.
This gist provides a web page (time.php) that contains an image that is updated hourly.
It is intended to be used with a directory of images with hashed filenames, generated by renameseq.py and shafile.py, and the event server timesse.php to make a "slow movie", rather like xkcd.com/time.
The php file are put on the web server, and the python files can be put somewhere that python will find them. They should work ok in python2.
@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")