Skip to content

Instantly share code, notes, and snippets.

@jsbueno
jsbueno / super_mixin.py
Created January 31, 2017 16:41
Mixin class (Python 3.6+) for enabling automatic calls to "super" on all methods
from functools import wraps
values = 'pre', 'post', 'manual'
def pre_super(func):
func.auto_super = 'pre'
return func
import pygame
from math import sin, cos, radians
linefunc = pygame.draw.line
color = 255,255,255
class Turtle:
def __init__(self, surf, pos=(0,0)):
self.surf = surf
self.x = pos[0]; self.y = pos[1]
self.drawing = True
@jsbueno
jsbueno / generic_json.py
Last active March 29, 2018 08:11
Helpers to serialize/de-serialize generic Python objects as JSON
"""Custom JSON encoder and Decoder classes to work with general Python classes
Pass these as the `cls` argument to json.dump and json.load to enable
the serialization of most Python defined "well behaved" objects
directly as JSON.
Ref.: http://stackoverflow.com/questions/43092113/create-a-class-that-support-json-serialization-for-use-with-celery/43093361#43093361
"""
import json
@jsbueno
jsbueno / disjoint.py
Created April 16, 2017 18:03
Python3 Disjoint Set imlementation
from collections.abc import MutableMapping
class DisjointSet(MutableMapping):
"""Working disjoint set implementatin in Python -
check https://en.wikipedia.org/wiki/Disjoint-set_data_structure
"""
def __init__(self, initial):
self.data = dict()
@jsbueno
jsbueno / gist:fb064883dae672d4b7743b114a3ba56f
Created June 6, 2017 16:17
Simple game of life implementation - Python3 + pygame
import pygame
W, H = 32, 24
width, height = 800, 600
def init():
screen = pygame.display.set_mode((width, height))
return screen
@jsbueno
jsbueno / lissageous.py
Created July 28, 2017 01:57
Simple lissageous curves with pygame
from math import cos, sin
import pygame
tela = pygame.display.set_mode((640, 480))
CX, CY = 320, 240
@jsbueno
jsbueno / jogo.py
Created July 29, 2017 16:16
space invaders da oficina
import pygame
LARG = 640
ALT = 480
# alterar os numeros para mudar a cor:
cor_da_nave = (0, 255, 0)
fundo = (0, 0, 0)
TAM = LARG / 20
### Keybase proof
I hereby claim:
* I am jsbueno on github.
* I am jsbueno (https://keybase.io/jsbueno) on keybase.
* I have a public key ASAHhBRh4WxwCe7SxMl2eq3-6UnWO-bKv0R6U0J-msuDwQo
To claim this, I am signing this object:
@jsbueno
jsbueno / bouncing.py
Created October 13, 2017 02:22
Example of bauncing random balls with Pygame.
import random
import pygame
WIDTH, HEIGHT = 800, 600
class Ball(pygame.sprite.Sprite):
def __init__(self, diameter, color=None):
super().__init__()
self.diameter = diameter
@jsbueno
jsbueno / colors.py
Created October 22, 2017 14:27
Terminal colors and gradients in Python
import io
import sys
ANSI_SEQ = "\x1b[{}m"
FG_RGB = "38;2;{};{};{}"
BG_RGB = "48;2;{};{};{}"
RESET="0"
FRAMED="51"
ATTRS = {key:code for key, code in [line.strip().split() for line in """\