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
""" | |
One To One field that does not rise an Exception | |
In your models you now can write: | |
class Profile(models.Model): | |
user = AdvancedOneToOneField(User, related_name="profile") | |
And using in code like this: |
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
var intcomma = function(value, delimiter) { | |
/* | |
Original script found here https://gist.github.com/559757 | |
Added optional argument delimiter to choose witch symbol | |
to use for thousand delimiter | |
*/ | |
var origValue = String(value); | |
if (typeof(delimiter) == 'undefined') delimiter = ','; | |
var newValue = origValue.replace(/^(-?\d+)(\d{3})/, '$1'+delimiter+'$2'); | |
if (origValue == newValue){ |
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
export GIT_PS1_SHOWDIRTYSTATE=true | |
export GIT_PS1_SHOWUNTRACKEDFILES=true | |
if [ "$color_prompt" = yes ]; then | |
PS1='${debian_chroot:+($debian_chroot)} `if [ $? = 0 ]; then echo "\[\e[32m\]✔"; else echo "\[\e[31m\]✘"; fi` \[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\] `__git_ps1 "(%s)"`\n \[\033[01;34m\]\$\[\033[00m\] ' | |
else | |
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(__git_ps1 " (%s) ")\$ ' | |
fi |
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/env python | |
# coding: utf-8 | |
""" | |
Program that convert text files from one encoding to another. | |
By default it is used to convert windows-1251 encoded subtitles | |
into ISO-8859-5 ecoded because this is encoding for cyrilic | |
characters in Panasonic Viera TV | |
Tested on Python 2.7+ and Python 3.2+ |
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
<html> | |
<head> | |
<style type="text/css"> | |
html, body { width: 100%; height: 100%; overflow: hidden; padding: 0; margin: 0; border: 0;} | |
.bg-white { background: #FFFFFF; } | |
.bg-red { background: #FF0000; } | |
.bg-green { background: #00FF00; } | |
.bg-blue { background: #0000FF; } | |
.bg-cyan { background: #00FFFF; } | |
.bg-yellow { background: #FFFF00; } |
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/env python | |
# -*- coding: utf-8 -*- | |
# | |
# eik_checker.py | |
# | |
# Copyright 2012 Venelin Stoykov <[email protected]> | |
# | |
# This program is free software; you can redistribute it and/or modify | |
# it under the terms of the GNU General Public License as published by | |
# the Free Software Foundation; either version 2 of the License, or |
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 string import letters | |
def calc_excel_column_number(string): | |
""" | |
Return number representing the column index in MS excel | |
A is the first column - return 1 | |
B is the second column - return 2 | |
... | |
Z is the 26th column - return 26 |
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 time import time | |
class TimeIt: | |
""" | |
Simple class for easy measuring time for code execution | |
Usage: | |
with TimeIt('Simple description of my code'): | |
do something... |
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 XUACompatibleMiddleware(object): | |
""" | |
Add a X-UA-Compatible header to the response | |
This header tells to Internet Explorer to render page with latest | |
possible version or to use chrome frame if it is installed. | |
""" | |
def process_response(self, request, response): | |
response['X-UA-Compatible'] = 'IE=edge,chrome=1' | |
return response |
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 re | |
from time import time | |
from django.core.exceptions import MiddlewareNotUsed | |
from django.conf import settings | |
from django.db import connection | |
PATH_INFO_RE = re.compile(r'^(/favicon\.ico|%s|%s)' % (settings.STATIC_URL, settings.MEDIA_URL)) | |