Skip to content

Instantly share code, notes, and snippets.

# -*- coding: UTF-8 -*-
from __future__ import absolute_import
from __future__ import unicode_literals
from django.db import models
from django.db.models.query import QuerySet
from django.core.urlresolvers import reverse
from django.utils.timezone import now
from django.utils.encoding import python_2_unicode_compatible
@brutus
brutus / tasks.py
Created October 12, 2014 23:19
A collection of tasks for *Invoke* to set up a Django project with Gunicorn on Uberspace.
# -*- coding: UTF-8 -*-
"""
A collection of tasks for `Invoke`_ to help setting up a `Django`_ project
with `Gunicorn`_ on `Uberspace`_ accounts.
All information for this script has to be set in a JSON file
called ``settings.json`` in the same directory like this::
{
@brutus
brutus / invoke.yaml
Last active August 29, 2015 14:20
Invoke YAML loading trouble
deployments:
testing:
host: xyz.domain.tld
user: username
destination: /home/username/html/misc/path/
sources:
- index.html
- img
@brutus
brutus / validators.py
Last active August 29, 2015 14:20
Django DateTime Validator
from django.core.exceptions import ValidationError
from django.utils.deconstruct import deconstructible
@deconstructible
class DateValidator():
"""
Überprüft ob *ein Datum* vor oder nach einem gegebenen anderen Datum liegt.
@brutus
brutus / add.py
Created October 1, 2015 15:15
Mutagen MP3 Image Error
def add_image(
filenames, image_path, description='Cover', img_type=3, encoding=3
):
"""
Adds an image to MP3 from *filenames*.
Args:
filenames (lits): paths to the MP3
image_path (string): path to image file
@brutus
brutus / servbench.py
Created July 24, 2012 13:23
Very basic test server to try some stuff.
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""Serv Bench
Very basic test server to try some stuff.
"""
import sys
``ab -r -n 200 -c 200 http://localhost:8080/``
* pure sockets (max 5 connections, sleeptime=0.25ms)
Time taken for tests: 16.932 seconds
Requests per second: 11.81 [#/sec] (mean)
Failed requests: 507
* pure sockets (max 500 connections, sleeptime=0.25ms)
Time taken for tests: 50.088 seconds
Requests per second: 3.99 [#/sec] (mean)
Failed requests: 0
* threads (max 500 connections, sleeptime=0.25ms)
@brutus
brutus / decode_13.py
Created August 6, 2012 13:28
tsw decode
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
import sys
import string
trans = string.maketrans(
string.lowercase,
string.lowercase[13:] + string.lowercase[:13]
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
lvm2
0 upgraded, 1 newly installed, 0 to remove and 1 not upgraded.
Need to get 584 kB of archives.
After this operation, 1182 kB of additional disk space will be used.
Get:1 http://archive.raspbian.org/raspbian/ wheezy/main lvm2 armhf 2.02.95-7+rpi1 [584 kB]
Fetched 584 kB in 1s (577 kB/s)
Selecting previously unselected package lvm2.
DPI scale: 1
startup, version: 3047 linux x64 channel: stable
executable: /opt/sublime_text/sublime_text
working dir: /home/brutus
packages path: /home/brutus/Dokumente/.config/sublime-text-3/Packages
state path: /home/brutus/Dokumente/.config/sublime-text-3/Local
hardware concurrency: 4
zip path: /opt/sublime_text/Packages
zip path: /home/brutus/Dokumente/.config/sublime-text-3/Installed Packages
found 7 files for base name Default.sublime-keymap