Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/python
import numpy as np
# Schulze Condorcet voting method:
# http://en.wikipedia.org/wiki/Schulze_method
def schulze(votes):
"""Input: An array of votes. In each row are the candidates' rankings. The
index of each entry in the row corresponds to a single candidate.
Only the relative rankings of candidates matter.
Lower numbers are better."""
@xvedejas
xvedejas / dfs_calc.py
Created February 4, 2015 08:07
Distributed FS calculator
#!/usr/bin/python
# RAID/Distributed FS calculator
# Some notes on designing a distributed FS cluster:
# - The total space on each machine (each OSD) should be nearly equal.
# - Larger drives for the same space means more redundancy but also slower
# rebuild times.
# - Entire RAID arrays are allowed to fail if the replication policy is > 1.
# Just don't let multiple RAID arrays fail at once.
#!/usr/bin/python3
class TicTacToeGame():
def __init__(self):
# Our game state is defined by a list of 3 lists, each containing 3
# characters, which can be either ' ' (blank), an 'X', or an 'O'.
self.state = [[' ', ' ', ' '], [' ', ' ', ' '], [' ', ' ', ' ']]
self.next_turn_player = 'X'
def do_move(self, index):
#!/usr/bin/python3
# This is a sample bit of code that shows how to draw arbitrary axis-aligned
# boxes in 3D space.
# based on: https://gist.github.com/binarycrusader/5823716a1da5f0273504
import ctypes
import numpy as np
import time
from OpenGL import GL, GLU, GLUT
from OpenGL.GL import shaders