Skip to content

Instantly share code, notes, and snippets.

@jsbueno
jsbueno / life.py
Created February 20, 2016 06:47
Game of Life (Python + Pygame)
# coding: utf-8
import pygame
import random
rr = random.randrange
SIZE = 800, 600
cellsize = 20
try:
@jsbueno
jsbueno / piet.py
Created April 2, 2016 04:06
Python Piet interpreter - just some slightly modernized code of the one listed in Piet resources at: http://www.dangermouse.net/esoteric/piet/tools.html
#!/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 April 28, 2016 18:49
"fixed up" Python piet interpreter
"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.
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 20:19
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 00:35
Postscritp wallclock drawing
%! 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
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 October 21, 2016 20:26
Simple Snake Game using Pygame - used in the workshop in Guarulhos at 2016-10-21
# 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 January 22, 2017 23:18
Snippet to have abuuider for a imutable object.
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 January 31, 2017 16:02
Attempt to create a decorator to automatically call super - failled attempt.
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: