Skip to content

Instantly share code, notes, and snippets.

View vstoykov's full-sized avatar
🇧🇬

Venelin Stoykov vstoykov

🇧🇬
View GitHub Profile
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
@vstoykov
vstoykov / eik_checker.py
Created December 20, 2012 10:31
Method for checking validity of bulgarian EIK/BULSTAT codes.
#!/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
@vstoykov
vstoykov / LCD-test.html
Created November 5, 2012 17:30
Simple page that rotate some main colors ('white', 'reg', 'green', 'blue', 'cyan', 'yellow', 'magenta', 'black') to test pixels of the LCD monitor.
<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; }
@vstoykov
vstoykov / convert_encoding.py
Last active October 10, 2015 07:18
Script that convert text files from one encoding to another.
#!/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+
@vstoykov
vstoykov / extra_PS.sh
Last active October 7, 2015 18:27
Add some extra stuffs on BASH prompt
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
@vstoykov
vstoykov / intcomma.js
Created July 30, 2012 11:43
Pretty print numbers with thousand delimiter
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){
@vstoykov
vstoykov / advanced_one_to_one_field.py
Created March 22, 2012 16:04
One To One field that does not rise an Exception
"""
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:
@vstoykov
vstoykov / maxmind_update.sh
Created March 2, 2012 09:56
Download MaxMind free database and place it in default location for pygeoip
#!/bin/bash
if [ `whoami` != 'root' ]; then
echo "You must to be root"
exit
fi
DOWNLOAD_URL="http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz"
TEMPFILE="/tmp/GeoIPCity.dat"
TEMPFILEGZ="$TEMPFILE.gz"
GEOIP_DIR="/usr/local/share/GeoIP"
@vstoykov
vstoykov / ActionForObjectAdmin.py
Created January 23, 2012 12:27
Django Admin class that add some urls wich can call predefined action for given object.
from django.contrib import admin
from django.conf.urls.defaults import patterns, url
from django.shortcuts import redirect, Http404
class ActionForObjectAdmin(admin.ModelAdmin):
"""
Admin that add some urls wich can call an action for given object.
Example:
if url is /admin/myapp/mymodel/object_id/
@vstoykov
vstoykov / django-site.sh
Last active September 29, 2015 15:17
Run fast CGI server for django project
#!/bin/bash
#################################################################
# Startup script for Django server, that will be placed
# in /usr/local/bin for example. It may be symlinked
# in project dir with name "run" like: