Skip to content

Instantly share code, notes, and snippets.

@b1
b1 / context_processors.py
Created February 27, 2013 11:20
My first context processor
#!/usr/bin/python
# coding: utf-8
""" send dict to templates. Don't forget set """
from django.conf import settings
def sett_to_tpl():
""" send dict to templates """
# todo: is it needhas to be settings.get('SETT_TO_TPL', '')
return {'SETT_TO_TPL': }
import sys
import time
for i in xrange(100):
sys.stdout.flush()
time.sleep(0.5)
sys.stdout.write('\r' + str(i))
@b1
b1 / countries.csv
Created March 7, 2013 18:34
ISO 3166-2 tab separated list contry codes and country names
We can make this file beautiful and searchable if this error is corrected: No commas found in this CSV file in line 0.
Code Country name Year ccTLD ISO 3166-2 Notes
AD Andorra 1974 .ad ISO 3166-2:AD
AE United Arab Emirates 1974 .ae ISO 3166-2:AE
AF Afghanistan 1974 .af ISO 3166-2:AF
AG Antigua and Barbuda 1974 .ag ISO 3166-2:AG
AI Anguilla 1983 .ai ISO 3166-2:AI AI previously represented French Afar and Issas
AL Albania 1974 .al ISO 3166-2:AL
AM Armenia 1992 .am ISO 3166-2:AM
AO Angola 1974 .ao ISO 3166-2:AO
AQ Antarctica 1974 .aq ISO 3166-2:AQ Covers the territories south of 60° south latitude Code taken from name in French: Antarctique
@b1
b1 / google_sitemap_example.py
Last active December 14, 2015 20:09
Test script. parse VS iterparse On google.com/sitemap.xml
#!/usr/bin/python
# coding: utf-8
""" Parsing xml file. Basic example """
from StringIO import StringIO
from datetime import datetime
from lxml import etree
import urllib2
print """
Test script.
@b1
b1 / mediana.py
Last active December 15, 2015 15:49
mediana 50
#!/usr/bin/python
# coding: utf-8
""" """
def mediana(_list=None):
"""
Медиана (50-й перцентиль, квантиль 0,5) — возможное значение признака, которое делит ранжированную совокупность
(вариационный ряд выборки) на две равные части: 50 % «нижних» единиц ряда данных будут иметь значение признака
не больше, чем медиана, а "верхние" 50 % — значения признака не меньше, чем медиана.
@b1
b1 / send.py
Created April 19, 2013 10:34
Basic script for sending excel over smtp
import smtplib, os
from email.MIMEMultipart import MIMEMultipart
from email.MIMEBase import MIMEBase
from email.MIMEText import MIMEText
from email.Utils import COMMASPACE, formatdate
from email import Encoders
def send_mail(send_from, send_to, subject="", text="", files=None, server='smtp.google.ru'):
if files == None:
files = []
server {
listen 80;
server_name localhost;
root /home/website/web;
rewrite ^/app\.php/?(.*)$ /$1 permanent;
try_files $uri @rewriteapp;
location @rewriteapp {
@b1
b1 / media_queries.html
Created September 24, 2013 09:55
Just test MQ
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
body {
margin: 0;
}
var unique = function(array) {
return array.reduce(function(memo, elem) {
if (memo.indexOf(elem) < 0) memo.push(elem);
return memo;
}, []);
};
// Example
//
// var callback = function(error, data) {console.log('Done.', error, data);};
@b1
b1 / slugify.py
Created May 7, 2014 15:01
slugify
#!/bin/env python2
# encoding: utf-8
import re
try:
from unidecode import unidecode
except ImportError:
Exception("pip install unidecode")