Skip to content

Instantly share code, notes, and snippets.

@gentimouton
gentimouton / battle.py
Created June 2, 2019 05:37
simple battle simulator
class Battler:
def __init__(self, p, a, m, h):
self.power = p
self.armor = a
self.mhp = m
self.hp = h
def __repr__(self):
# return '{}/{}:{}/{}'.format(self.power, self.armor, self.hp, self.mhp)
@gentimouton
gentimouton / itemgen.py
Created May 26, 2019 19:59
generate items for an RPG
import math, random
# constants
STATS = ['int','str','vit']
RARITY_MULT = {
'common': 1,
'rare': 1.25,
'epic': 1.5,
'legendary': 2
}
@gentimouton
gentimouton / shell_snipets.sh
Created March 1, 2015 20:00
Windows Shell snippets
REM recursively list mp4 files in current dir
DIR /s /b | FINDSTR ".mp4"
@gentimouton
gentimouton / unique_combinations.py
Last active December 18, 2015 11:49
How to decompose a number in a sum of smaller numbers that are provided. Without duplicates (ie order does not matter). Example: decompose 3 in a sum of numbers from [1,2,4]: 1+2 and 1+1+1
sep = '-'
results = []
def decompose(num, operands, path):
""" Append a valid path to results if it's possible to decompose the num.
num = number to decompose,
operands = list of operands allowed to use in the decomposition,
path = current chain of operands, string,
"""
@gentimouton
gentimouton / viewforwarder.py
Created October 26, 2012 22:59
Using pygame and MVC, the view forwards events to its subcomponents.
from clock import Clock
from collections import defaultdict, deque
from constants import RESOLUTION, FONT_SIZE
from events import QuitEvent, EventManager, VTickEvent
from input import InputController
from pygame.rect import Rect
from pygame.sprite import LayeredDirty
from pygame.surface import Surface
from view import PygameDisplay
from widgets import MenuWidget
@gentimouton
gentimouton / em_mvc.py
Created September 8, 2012 18:20
Example of an event manager aware of MVC for games
from collections import defaultdict
from time import sleep
import logging
class TickEvent:
pass
# components subscribed to TickEvent as "input" will be notified first,
@gentimouton
gentimouton / passive-bots.r
Created March 14, 2012 19:24
R plot of frame duration against number of passive sockets
bots = c(0,20,40,60,80,100,120,140,160,180,200,250,300,350,400)
millis = c(0.08,0.19,0.45,0.55,0.68,0.79,0.95,1.05,1.24,1.22,1.38,1.7,1.8,2.2,2.4)
linfit = lm(millis ~ bots)
#attributes(linfit) # view the attrs of the fit
coeff = signif(linfit$coefficients[2], digits=3) # how many millis per bot
offset = signif(linfit$coefficients[1], digits=3)
rsquared = signif(summary(linfit)$r.squared, digits=3)
pval = signif(summary(linfit)$coefficients[2,4], digits=3)
@gentimouton
gentimouton / gist:1673848
Created January 25, 2012 00:50
Note in Reader bookmark from google reader
javascript:var%20b=document.body;var%20GR________bookmarklet_domain='http://www.google.com';if(b&&!document.xmlVersion){void(z=document.createElement('script'));void(z.src='http://www.google.com/reader/ui/link-bookmarklet.js');void(b.appendChild(z));}else{}
@gentimouton
gentimouton / gridwalk.py
Created January 6, 2012 20:09
Mediator and MVC using pygame
#! /usr/bin/env python3
'''
Example ported to python3
Original from Shandy Brown: https://github.com/sjbrown/writing_games_tutorial/blob/example1/code_examples/example.py
'''
def Debug(msg):
print (msg)
@gentimouton
gentimouton / noun generator.html
Created November 15, 2011 00:39
Crappy Noun generator
<html>
<script type="text/javascript">
var consonants = ['b','c','d','f'];
var vowels = ['a','e','i','o','u','y'];
var consBeg = ['b','c','f','g','k','p','q'];
var consEnd = ['j','l','r','s','z'];
var consAloneNoH = ['d','m','n','t','v','w','x'];
var consAlone = ['chr','shr','str','sr', 'sl', 'sj', 'sm', 'sn', 'dr','dj'];