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 subprocess | |
IS_WIN32 = 'win32' in str(sys.platform).lower() | |
def subprocess_call(*args, **kwargs): | |
#also works for Popen. It creates a new *hidden* window, so it will work in frozen apps (.exe). | |
if IS_WIN32: | |
startupinfo = subprocess.STARTUPINFO() | |
startupinfo.dwFlags = subprocess.CREATE_NEW_CONSOLE | subprocess.STARTF_USESHOWWINDOW |
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 Queue | |
#Global queue, import this from anywhere, you will get the same object. | |
#real life example: https://github.com/nitely/ochDownloader/blob/master/core/idle_queue.py | |
idle_loop = Queue.Queue() |
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 weakref | |
class _BoundMethodWeakref: | |
def __init__(self, func): | |
self.func_name = func.__name__ | |
self.wref = weakref.ref(func.__self__) #__self__ returns the class http://docs.python.org/reference/datamodel.html | |
def __call__(self): | |
func_cls = self.wref() |
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 threading | |
#import logging | |
#logger = logging.getLogger(__name__) | |
import idle_queue | |
from weak_ref import weak_ref | |
class Event: | |
def __init__(self, name): |
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 sys | |
import os | |
try: | |
import fcntl | |
except ImportError: | |
fcntl = None | |
LOCK_PATH = os.path.join(os.path.abspath(os.path.dirname(sys.argv[0])), "lock") | |
OS_WIN = False |
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
#-*- coding: utf-8 -*- | |
from django.contrib import messages | |
from django.core.urlresolvers import reverse | |
from django.shortcuts import redirect | |
# https://github.com/jsocol/django-ratelimit | |
from ratelimit.decorators import ratelimit | |
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
#! /usr/bin/python3 | |
from time import time | |
from threading import Lock | |
class TokenBucket: | |
""" | |
An implementation of the token bucket algorithm. | |
""" |
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
#-*- coding: utf-8 -*- | |
""" | |
A subclass of ModelChoiceField which represents the tree level of each node when generating option labels. It's limited to one level of nesting, if you need more, you should consider the django-mptt package. | |
For example, where a form which used a ModelChoiceField: | |
category = ModelChoiceField(queryset=Category.objects.all()) | |
...would result in a select with the following options: |
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
""" | |
Sometimes you just don't want to display every permission django has, | |
you just want a short list showing the permissions for some of your apps (or even django core apps). | |
GROUP_PERMISSIONS_MODELS must be a list of your app models. | |
Dotted path (in lowercase) required, app name + model class name. | |
tested on Django 1.6 (should work on +1.3) | |
""" |
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
#-*- coding: utf-8 -*- | |
# Tested on Markdown 2.3.1 | |
# | |
# Copyright (c) 2014, Esteban Castro Borsani | |
# The MIT License (MIT) | |
# | |
# Permission is hereby granted, free of charge, to any person obtaining a copy | |
# of this software and associated documentation files (the "Software"), to deal | |
# in the Software without restriction, including without limitation the rights |
OlderNewer