Skip to content

Instantly share code, notes, and snippets.

View ildus's full-sized avatar

Ildus Kurbangaliev ildus

View GitHub Profile
#Newbie programmer
def factorial(x):
if x == 0:
return 1
else:
return x * factorial(x - 1)
print factorial(6)
#First year programmer, studied Pascal
@ildus
ildus / json_sample.py
Created June 21, 2011 19:10
http response json
def view_vote(request, aid = 0):
result = {'success': False}
cookie_set = False
try:
interview = Interview.objects.latest()
answer = Answer.objects.get(id = aid)
except:
result['message'] = 'Answer or interview not founded'
else:
if answer.interview.id != interview.id or interview.on == False:
@ildus
ildus / runner.py
Created July 8, 2011 03:44 — forked from NetAngels/runner.py
Extremely fast Django test runner
# -*- coding: utf-8 -*-
"""
Extremely fast Django test runner, based on the idea that your database schema
and fixtures are changed much more seldom that your code and tests. All you
need is to make sure that your "quickstart.sqlite" database file is always up
to date.
BEWARE: Don't run this test runner on production server. It assumes that you
use only one database configured as "default", and its db engine is SQLite.
Otherwise your tests can eat your data!
@ildus
ildus / pgsql_change_template_1.sql
Created August 3, 2011 08:45 — forked from EmmanuelOga/pgsql_change_template_1.sql
change postgresql template1 db encoding to utf8 (unicode) by dropping it and recreating from template0
# change postgresql template1 db encoding to utf8 (unicode) by dropping it and recreating from template0
UPDATE pg_database SET datistemplate=false WHERE datname='template1';
drop database template1;
create database template1 with template = template0 encoding = 'UTF8';
@ildus
ildus / gist:1126946
Created August 5, 2011 05:07 — forked from hunterloftis/gist:973973
Zepto + Mustache + KnockoutJS starting point
ko.mustacheTemplateEngine = function () {
this['getTemplateNode'] = function (template) {
var templateNode = document.getElementById(template);
if (templateNode == null)
throw new Error("Cannot find template with ID=" + template);
return templateNode;
}
this['renderTemplate'] = function (templateId, data, options) {
@ildus
ildus / pg_backup.py
Created November 27, 2012 09:32
script for backuping of postgresql databases
#!/usr/bin/env python
#coding: utf-8
from optparse import OptionParser
from datetime import date, datetime
from pwd import getpwnam
import unidecode
from libs.script_utils import get_email_logger
import getpass
@ildus
ildus / email_logger.py
Created December 7, 2012 10:52
Returns logging handler that sends email
#coding: utf-8
def get_email_logger(addrs, subject, email_settings):
''' Returns logger that send email '''
import logging
import logging.handlers
assert 'host' in email_settings, "email settings, host needed"
@ildus
ildus / affini.py
Last active December 14, 2015 05:08
#coding: utf-8
import enchant
LAT = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
a_list = [1, 3, 5, 7, 9, 11, 15, 17, 19, 21, 23, 25]
m = len(LAT)
CODE = """
#coding: utf-8
LAT = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
CODE = """
FUBSWRJUDSKLF NHBV DUH DQDORJRXV WR WKH KRXVH DQG FDU NHBV ZH FDUUB LQ RXU
GDLOB OLYHV DQG VHUYH D VLPLODU SXUSRVH
"""
@ildus
ildus / converter.py
Last active December 17, 2015 08:28
Wavefront .obj to .json converter for webgl
#!/usr/bin/env python
#coding: utf-8
import os
import json
from optparse import OptionParser
INPUT_REQ = """
Input filename. Requirements:
1) Wavefront format (.obj)
2) One object in one file