Skip to content

Instantly share code, notes, and snippets.

@jsbueno
jsbueno / life.py
Created Feb 20, 2016
Game of Life (Python + Pygame)
View life.py
# coding: utf-8
import pygame
import random
rr = random.randrange
SIZE = 800, 600
cellsize = 20
try:
@jsbueno
jsbueno / piet.py
Created Apr 2, 2016
Python Piet interpreter - just some slightly modernized code of the one listed in Piet resources at: http://www.dangermouse.net/esoteric/piet/tools.html
View piet.py
#!/usr/bin/env python
from __future__ import print_function
version = __version__ = '1.1'
# Author- Ross Tucker
# Thanks to Marc Majcher for his project, Piet.pl
from PIL import Image # Python Imaging Library
from operator import itemgetter
@jsbueno
jsbueno / piet.py
Created Apr 28, 2016
"fixed up" Python piet interpreter
View piet.py
"fixed up" Python Piet interpreter -
Piet is an esoteric programing language, which defines a programatic behavior to raster images and a fixed set of colors.
It is mostly defined and demonstrated at http://www.dangermouse.net/esoteric/piet
On that site, on the "resources" page there is a link to a piet interpreter written in Python -
this is that code, with some fixes to Python in 2016, and able to take an image file name as
a parameter from the command line (which the original interpreter didn't do).
There is no attempt to optmize or restile the code besides fixes to run it in Python2.7 and Python 3.4.
View dancinha.py
import sys, random, time
def h():
positions = "\\o| \\o/ |o/ /o/ |o| \\o\\".split()
x=10
for i in range(50):
print (" " * x + positions[i % len(positions)] + " ", end="")
sys.stdout.flush()
time.sleep(0.2)
print("\b" * 80, end="")
@jsbueno
jsbueno / bolderificator.py
Last active May 19, 2016
bolderificator.py
View bolderificator.py
#! /usr/bin/env python3
from urllib.request import urlopen
import re
import unicodedata
def fetch():
data = urlopen("https://www.w3.org/TR/MathML2/double-struck.html").read()
dcontent = re.findall(r"<td.*?>\s*?(.*?)</td", data.decode("utf-8"))
@jsbueno
jsbueno / clock.ps
Created May 18, 2016
Postscritp wallclock drawing
View clock.ps
%! PS
(Sans Bold) findfont 40 scalefont setfont 350 350 translate /i 0 def /step 360 12 div neg def 12 {step rotate 0 200 moveto i 1 add ( ) cvs dup stringwidth pop 2 div neg 0 rmoveto show /i i 1 add def } repeat 0 0 moveto 5 setlinewidth 0 150 rlineto stroke 0 0 moveto 10 setlinewidth 255 0 0 setrgbcolor 100 0 rlineto stroke showpage
View historyturtle.py
from turtle import Turtle
"""
Python Turtle with logging and replay capabilities
Author: João S. O. Bueno <gwidion@gmail.com>
License: LGPL 3.0+
This implements HistoryTurtle - a subclass of
Python's turtle.Turtle wich features a simple
@jsbueno
jsbueno / snake.py
Created Oct 21, 2016
Simple Snake Game using Pygame - used in the workshop in Guarulhos at 2016-10-21
View snake.py
# coding: utf-8
import pygame
import random
# jsobueno@gmail.com
TAMANHO = (640, 480)
T = 640 / 32
TX = 640 / T
TY = 480 / T
@jsbueno
jsbueno / imutable_builder.py
Created Jan 22, 2017
Snippet to have abuuider for a imutable object.
View imutable_builder.py
class Immutable:
__slots__ = ()
def __hash__(self):
return hash(tuple(getattr(self, v) for v in self.__slots__))
def __setattr__(self, attr, value):
raise TypeError('Attributes here are imutable')
@jsbueno
jsbueno / super_decorator.py
Created Jan 31, 2017
Attempt to create a decorator to automatically call super - failled attempt.
View super_decorator.py
def pre_super(func):
values = {}
try:
class Mutant:
def wrapper(*args, **kw):
getattr(__class__, func.__name__)(*args, **kw)
return func(*args, **kw)
values["w"] = wrapper
raise ValueError # Abort the filling up of wrapper's __class__ cell
except ValueError: