Skip to content

Instantly share code, notes, and snippets.

@zeimusu
zeimusu / Fleishman.py
Last active June 26, 2023 08:03
Generate data with given mean, standard deviation, skew, and kurtosis. Intended for monte carlo simulations with non normal distributions
import numpy as np
from numpy.linalg import solve
import logging
logging.basicConfig(level = logging.DEBUG)
from scipy.stats import moment,norm
def fleishman(b, c, d):
"""calculate the variance, skew and kurtois of a Fleishman distribution
F = -c + bZ + cZ^2 + dZ^3, where Z ~ N(0,1)
"""
@zeimusu
zeimusu / isqrt.go
Created December 30, 2022 23:26
Calculate integer square root and base 2 log
package main
import (
"fmt"
)
func Iblog(n uint) uint {
i := uint(0)
for n > 1 {
n = n / 2
@zeimusu
zeimusu / exoplanets.csv
Last active April 7, 2022 15:37
named exoplanets and their standard names
Identification Proper name
14 Andromedae b Spe
18 Delphini b Arion
41 Lyncis b Arkas
42 Draconis b Orbitar
47 Ursae Majoris b Taphao Thong
47 Ursae Majoris c Taphao Kaew
51 Pegasi b Dimidium
55 Cancri b Galileo
55 Cancri c Brahe
\documentclass[12pt,a4paper]{exam}
\pointsmarginright
\begin{document}
\begin{questions}
\question
\part[2]
Show that $371 \times 83 = 30\,793$
\part[1]
Write down the answer to $3.71 \times 0.83$
@zeimusu
zeimusu / kepler.py
Created March 29, 2016 17:24
Models orbits using keplers equations, then tries to makes sounds from them.
import math
#import sys
#import sunau
#import array
"""
ecc=0.5
P=1
p=1
if len(sys.argv)>1:
ecc=float(sys.argv[1])
@zeimusu
zeimusu / mollweide.py
Last active August 28, 2017 02:14
The mollweide equal area map projection. Convert longitude and latitude to and from 2d, flat cartiesian coordinates
#!/usr/bin/env python3
from math import sin, cos, pi, sqrt, asin, log
sqrt2 = sqrt(2)
def solveNR(lat, epsilon=1e-6):
"""Solve the equation $2\theta\sin(2\theta)=\pi\sin(\mathrm{lat})$
using Newtons method"""
if abs(lat) == pi / 2:
@zeimusu
zeimusu / league.py
Last active September 11, 2016 21:04
Produce a league table from a list of match results.
"""
Module that processes a list of results, and produces a sorted league table.
The list of results is a pandas data frame with format
"Home" "Home Score" "Away" "Away Score"
0 "Chelsea" 4 "Man U" 2
1 ... ... ... ...
Result is a Data frame representing the league table
@zeimusu
zeimusu / tictactoe.py
Created February 1, 2016 21:08
A game of noughts and crosses,
#!/usr/bin/env python3
"""Usage:
tictactoe : Play the graphical game
tictactoe t(ext) : play the text game, using the keypad
"""
import logging as log
import random, sys
import tkinter as tk
log.basicConfig(level=log.WARNING)
@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