This file contains 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
class IndexedList(list): | |
""" | |
Class that combines a list and a dict into a single class | |
- Written by Hugh Bothwell (http://stackoverflow.com/users/33258/hugh-bothwell) | |
- Original source available at: | |
http://stackoverflow.com/questions/5332841/python-list-dict-property-best-practice/5334686#5334686 | |
- Modifications by Jeff Terrace | |
Given an object, obj, that has a property x, this allows you to create an IndexedList like so: | |
L = IndexedList([], ('x')) | |
o = obj() |
This file contains 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
import collada | |
import sys | |
import os.path | |
from itertools import chain | |
import numpy | |
def uniqify_multidim_indexes(sourcedata, indices, return_map=False): | |
"""Just like numpy.unique except that it works with multi-dimensional arrays. | |
Given a source array and indexes into the source array, will keep only unique | |
indices into the source array, rewriting the indices to point to the new |
This file contains 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
import numpy as np | |
def remove_duplicates(array_data, return_index=False, return_inverse=False): | |
"""Removes duplicate rows of a multi-dimensional array. Returns the | |
array with the duplicates removed. If return_index is True, also | |
returns the indices of array_data that result in the unique array. | |
If return_inverse is True, also returns the indices of the unique | |
array that can be used to reconstruct array_data.""" | |
unique_array_data, index_map, inverse_map = np.unique( | |
array_data.view([('', array_data.dtype)] * \ |
This file contains 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 registration.signals import user_activated | |
from django.contrib.auth import login, authenticate | |
def login_on_activation(sender, user, request, **kwargs): | |
"""Logs in the user after activation""" | |
user.backend = 'django.contrib.auth.backends.ModelBackend' | |
login(request, user) | |
# Registers the function with the django-registration user_activated signal | |
user_activated.connect(login_on_activation) |
This file contains 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
import math | |
def almostEqual(a, b, rtol=1.0000000000000001e-05, atol=1e-08): | |
"""Checks if the given floats are almost equal. Uses the algorithm | |
from numpy.allclose.""" | |
return math.fabs(a - b) <= (atol + rtol * math.fabs(b)) | |
def floor(v): | |
"""Returns the floor of the given number, unless it is equal to its | |
ceiling (within floating point error).""" |
This file contains 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
#!/bin/bash | |
# | |
# shaper.sh | |
# --------- | |
# A utility script for traffic shaping using tc | |
# | |
# Usage | |
# ----- | |
# shape.sh start - starts the shaper | |
# shape.sh stop - stops the shaper |
This file contains 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
/** | |
* @fileoverview | |
* Registers a language handler for LLVM. | |
* | |
* | |
* To use, include prettify.js and this file in your HTML page. | |
* Then put your code in an HTML tag like | |
* <pre class="prettyprint lang-llvm">(my LLVM code)</pre> | |
* | |
* |
This file contains 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
XVFB=/usr/bin/Xvfb | |
XVFBARGS=":1 -screen 0 1024x768x24 -ac +extension GLX +render -noreset" | |
PIDFILE=/var/run/xvfb.pid | |
case "$1" in | |
start) | |
echo -n "Starting virtual X frame buffer: Xvfb" | |
start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile --background --exec $XVFB -- $XVFBARGS | |
echo "." | |
;; | |
stop) |
This file contains 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
"""Import this module to make python drop to the debugger | |
when an undhandled exception is raised. | |
Original script from: | |
http://code.activestate.com/recipes/65287/ | |
""" | |
import sys | |
__old_excepthook__ = sys.excepthook |
This file contains 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
import matplotlib.pyplot as plt | |
import numpy as np | |
from matplotlib import rc | |
rc('text', usetex=True) | |
rc('font', family='sans-serif') | |
rc('font', size='16') | |
# source: http://download.broadband.gov/plan/fcc-omnibus-broadband-initiative-(obi)-technical-paper-broadband-performance.pdf |
OlderNewer