Skip to content

Instantly share code, notes, and snippets.

@DM-
DM- / ayy
Created April 25, 2017 22:42
0x72575B18AF7e47E2264ab55D90B6960a29673968
@DM-
DM- / gen
Created August 31, 2012 18:05
import random
def avg(x):
if type(x) != int:
return sum(x)/float(len(x))
else:
return x
class liver(object):
"""containes genes and probability of life"""
def __init__(self, genes=0):
self.genes = genes
@DM-
DM- / grdesc.py
Created June 3, 2012 23:37
Gradient descent
#gradient ascent test
def linear(theta0,theta1,x):
return theta0+theta1*x
def cost(theta0,theta1,xm):
L=0
for i in xm:
Z=0
Z= linear(theta0,theta1,i[0])-i[1]
Z*=Z
@DM-
DM- / Basic map.py
Created May 26, 2012 19:56
Game code layout
#remember top left is 0,0 left right is X is first,up down is Y is second
# whitespaces, dataflow, and DRY, also use a vector class for positions
# newpos = simulateMovement(char, dir); if gmap[newpos.x][newpos.y] = stone
import sys,pygame
pygame.init()
Grass = pygame.image.load("grass.png")
Person = pygame.image.load("person.png")
class Vector:
def __init__(self, x, y):
@DM-
DM- / game.py
Created May 18, 2012 20:41 — forked from darkf/game.py
Terrible text-based RPG
import random
def say(msg):
print ":", msg
def rnd(min, max):
return random.randint(min, max)
def dice(Xd,Y):
l=[]
for i in range(Xd):
@DM-
DM- / build_index.py
Created April 24, 2012 03:02 — forked from darkf/build_index.py
Very basic text indexer/searcher in Python
import sys, os, glob, re, pickle
if len(sys.argv) != 2:
print "USAGE: %s DIR" % sys.argv[0]
sys.exit(1)
DIR = sys.argv[1]
INDEX = {}
FILES = []