This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Point = namedtuple('Point', 'x, y, z') | |
class BoundingBox(object): | |
def __init__(self,bottom,top): | |
self.top = Point._make(top) | |
self.bot = Point._make(bottom) | |
def _point_contained(self, other_point): | |
over_bot = all(map(lambda x: x[0]<=x[1], zip(self.bot,other_point))) | |
under_top = all(map(lambda x: x[0]>=x[1], zip(self.top,other_point))) | |
return over_bot and under_top |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
from django.db import models | |
from django.core.serializers.json import DjangoJSONEncoder | |
from django.utils import simplejson as json | |
class JSONField(models.TextField): | |
""" | |
JSONField is a generic textfield that neatly serializes/unserializes | |
JSON objects seamlessly. | |
Django snippet #1478 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Per funzionare il programma ha bisogno della libreria pygame | |
# | |
# Le istruzioni per installare pygame sono a questo indirizzo: | |
# http://pygame.org/download.shtml | |
# | |
import pygame, random | |
pygame.init() | |
random.seed() | |
screen = pygame.display.set_mode((400, 400)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def mixIn (base, addition): | |
"""Mixes in place, i.e. the base class is modified. | |
Tags the class with a list of names of mixed members. | |
""" | |
assert not hasattr(base, '_mixed_') | |
mixed = [] | |
for item, val in addition.__dict__.items(): | |
if not hasattr(base, item): | |
setattr(base, item, val) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PyQt4 import uic | |
from PyQt4.QtCore import pyqtWrapperType | |
UI_DIR='path_to_ui_files' | |
class WindowMeta (pyqtWrapperType, type): | |
"""This is the metaclass of all Qt-Windows. It automatically | |
sets the correct base classes, so they do not have to be set | |
by the programmer. | |
@attention: The class has to have the same name as the .ui-file. |
NewerOlder