Skip to content

Instantly share code, notes, and snippets.

View wkta's full-sized avatar

moonbak wkta

View GitHub Profile
@wkta
wkta / day_25.py
Created March 31, 2014 16:59
#MonthOfCode day 25 - cursor
import pygame
DISP_WIDTH = 640
DISP_HEIGHT = 480
def refreshScreen():
window.fill( pygame.Color('black') )
pygame.display.flip()
# init. pygame libr; create the screen and diplays a help message in the console
@wkta
wkta / day_26.py
Created March 31, 2014 17:00
#MonthOfCode day 26 - malicious
# this code is awesome, you will see it everywhere!
import sys
import random
import os
alphabet = [chr(i) for i in range(ord('a'),ord('z') + 1) ]
def genRandomName():
name_length = random.randint(2,8)
lchar = list()
for i in xrange(name_length):
@wkta
wkta / day_27.py
Created March 31, 2014 17:01
#MonthOfCode day 27 - pattern
import re
print "Testing your knowledge on regular expressions"
partterns = [
"a{4,}b", "Y.*g", "ro..c..ter", "[a,m,k]{5,8}" ]
for pat in partterns:
print "Try to type a string that matches the REGULAR EXPRESSION",pat
success = False
while True:
user_str = raw_input()
@wkta
wkta / day_28.py
Created March 31, 2014 17:01
#MonthOfCode day 28 - race
import random
import time
def detPrecision( candidate, model):
chars_cand = list( candidate)
chars_model = list(model)
while( len(chars_cand)<len(chars_model) ):
chars_cand.append(' ')
while( len(chars_cand)>len(chars_model) ):
chars_cand.pop()
@wkta
wkta / day_23.py
Created March 30, 2014 15:54
#MonthOfCode day 23 - meta
# This shows how we can define and use a META-function in python
def produce_incrementor( step):
''' it produces various increment functions'''
return lambda u:u+step
print "three by three"
increm_three = produce_incrementor(3)
k=0
while k < 34:
@wkta
wkta / day_22.py
Created March 30, 2014 15:36
#MonthOfCode day 22 - whirlpool
import pygame
from time import sleep
import random
import math
DISP_WIDTH = 640
DISP_HEIGHT = 480
DIST_THRESHOLD = 256
class MovingPix():
def __init__(self , x,y):
@wkta
wkta / day_21.py
Created March 30, 2014 12:53
#MonthOfCode day 21 - wave
import pygame
import math
from time import sleep
SCREEN_W = 640
SCREEN_H = 480
class MovingPix():
def __init__(self , x,y ):
self.x = x
self.y = y
@wkta
wkta / day_20.py
Created March 30, 2014 10:54
#MonthOfCode day 20 - play
import random
import pygame
from pygame.locals import *
SCREEN_W = 640
SCREEN_H = 480
def refeshFunction():
DISPLAYSURF.fill( pygame.Color('antiquewhite3') )
# draws the paddle
rect_rep_paddle =\
@wkta
wkta / day_19.py
Created March 28, 2014 15:54
#MonthOfCode day 19 - tree
# this program draws a random TREE-LIKE shape, inspired by L-Systems
import pygame
from time import sleep
import random
import sys
DISP_WIDTH = 640
DISP_HEIGHT = 480
def randPeriod():
return random.choice((1, 16, 64) ) #determines the slope with wich the emerging branch grows
@wkta
wkta / day_18.py
Created March 28, 2014 12:19
#MonthOfCode day 18 - search
import random
# This code implements the so-called "descent method" which is a kind of NEIGHBOR SEARCH METHOD
# often used in optimization.
# I apply it to the simple problem of finding the minimum value in a huge random matrix
# I count the nb of values tested to show how this kind of search is efficient in practice
# I initiale a random matrix and compute the global min. value on-the-fly to know
# if the descent method eventually succeeds in finding it.
N = 128 ; M = 128
MAX_VAL = 255