Skip to content

Instantly share code, notes, and snippets.

View masci's full-sized avatar

Massimiliano Pippi masci

View GitHub Profile
@masci
masci / windowmeta.py
Created February 22, 2011 16:59
Metaclass for automating uic operation when using the "Multiple Inheritance Approach" in Qt Widgets
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.
@masci
masci / mixinutils.py
Created February 22, 2011 17:01
utility functions for mix/unmix classes
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)
@masci
masci / step_1
Created May 16, 2012 21:53
Pygame pong
# 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))
@masci
masci / gist:3143930
Created July 19, 2012 13:33
Django JSONField
# -*- 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
@masci
masci / boundingbox.py
Created September 10, 2012 13:46
Bounding Box
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
function _virtualenv_prompt_info {
[[ -n $(whence virtualenv_prompt_info) ]] && virtualenv_prompt_info
}
function _git_prompt_info {
[[ -n $(whence git_prompt_info) ]] && git_prompt_info
}
function _python_ver {
[[ -n $(/usr/bin/env python --version) ]] && python_ver
@masci
masci / main.py
Created September 4, 2013 13:42
Simple Qt application embedding a PyMol instance.
#!/usr/bin/python
"""
PyMol Widget
Usage:
main.py [input_files]
Options:
-h, --help: print this screen
"""
[user]
name = Massimiliano Pippi
email = [email protected]
signingkey = 22AA96CA
[alias]
co = checkout
ci = commit
st = status
br = branch
@masci
masci / .zshrc
Created November 6, 2013 22:46
# Path to your oh-my-zsh configuration.
ZSH=$HOME/.oh-my-zsh
# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
ZSH_THEME="masci"
# Example aliases
#!/bin/bash
VENV=$1
if [ -z $VENV ]; then
echo "usage: runinenv [virtualenv_path] CMDS"
exit 1
fi
. ${VENV}/bin/activate
if [ -f ${VENV}/bin/postactivate ]; then
. ${VENV}/bin/postactivate