Skip to content

Instantly share code, notes, and snippets.

#!/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
@masci
masci / gist:1d9fa450c72089a29c2e
Created September 25, 2014 09:23
git rewrite path
PREFIX=projectA #adjust this
TAB=$'\t'
git filter-branch --index-filter '
git ls-files -s |
sed "s,${TAB},&"$PREFIX"/," |
GIT_INDEX_FILE=$GIT_INDEX_FILE.new git update-index --index-info &&
mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE
' HEAD
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
" Plugins begin
call vundle#begin()
Plugin 'gmarik/Vundle.vim'
Plugin 'tpope/vim-fugitive'
# subcommunities.py
import sys
sys.modules['__main__'].__dict__.update({
'PyCon': type('PyCon', (object,), {}),
'numpy': type('numpy', (object,), {'infty': 'foo'}),
'pythonistas': type('Foo', (object,), {'enjoy': lambda x: x, 'fun': 'foo'})
})
sys.modules['subcommunities'] = list()
sys.modules['numpy.nifty'] = 'foo'
@masci
masci / foo
Created April 22, 2015 20:22
Foo
import time
import random
# fill the input list
a = [random.randrange(0,130) for x in range(10**6)]
# std sort, keep a unsorted
t = time.time()
b = sorted(a)
print(time.time() - t)
@masci
masci / README.md
Last active August 29, 2015 14:28 — forked from haggen/README.md
boot2docker on nfs

Get boot2docker working with nfs instead of vboxsf.

Tested on:

- Boot2Docker-cli version: v1.6.0
  Git commit: 9894ae9
- Boot2Docker-cli version: v1.6.2
  Git commit: cb2c3bc
@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