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
s = """ | |
73167176531330624919225119674426574742355349194934 | |
96983520312774506326239578318016984801869478851843 | |
85861560789112949495459501737958331952853208805511 | |
12540698747158523863050715693290963295227443043557 | |
66896648950445244523161731856403098711121722383113 | |
62229893423380308135336276614282806444486645238749 | |
30358907296290491560440772390713810515859307960866 | |
70172427121883998797908792274921901699720888093776 | |
65727333001053367881220235421809751254540594752243 |
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 time | |
from wsgiref.util import setup_testing_defaults | |
from wsgiref.simple_server import make_server | |
def timeit(func): | |
def wrapper(*a, **k): | |
t1 = time.time() | |
it = iter(func(*a, **k)) |
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
SELECT i.route_id, min(t.cost) m | |
FROM (SELECT DISTINCT route_id FROM tickets) AS i, tickets t | |
WHERE i.route_id = t.route_id AND | |
city_from='ABC' AND | |
city_to='ABC' AND | |
date_direct='2012-05-24' AND | |
date_back='2012-05-25' AND | |
expires > NOW() | |
GROUP BY t.route_id | |
ORDER BY m; |
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
--Задача: есть таблица | |
fish | |
name CHAR(20) | |
price INT(5) | |
date DATE | |
--В таблице есть данные: | |
forel 2012-01-01 10 | |
forel 2012-01-03 6 |
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 decimal import Decimal, ROUND_HALF_UP | |
import logging | |
logging.basicConfig(level=logging.DEBUG) | |
# Constants for rounding | |
TWO_DIGITS_ROUND = Decimal("0.01") | |
SIX_DIGITS_ROUND = Decimal("0.000001") | |
result_lst = [] |
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
--Есть 2 таблицы: | |
--users | |
--UID Name | |
--1 «Александр» | |
--2 «Семён» | |
--messages | |
--UID msg | |
--1 “A” | |
--1 “B” |
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 A: | |
def __init__(self): | |
# self = B instance, when mangled, __value is replaced | |
# by _CurrentClass__value , so self.__dict__['_A__value'] = 1 | |
self.__value = 1 | |
self.__a = 123 | |
def getvalue(self): | |
print self.__a # OK | |
return self.__value # Error - because of assignment in B.__init__ |
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
# What's wrong in the code? | |
# A: No call to parent __init__. To call, uncomment the code | |
class A: | |
def __init__(self): | |
self._greeting = 'hello' | |
def greet(self): | |
print self._greeting | |
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 random | |
import MySQLdb | |
db=MySQLdb.connect(db="task", user='root') | |
def get_query(): | |
def get_date(): | |
year = str(random.randint(2011, 2012)) | |
month = str(random.randint(1, 12)) |
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
(package-initialize) | |
(require 'whitespace) | |
;; (setq whitespace-style '(face empty tabs lines-tail trailing)) | |
(setq whitespace-style '(face empty tabs trailing)) | |
(global-whitespace-mode t) | |
(setq whitespace-line-column 300) | |
(setq org-directory "~/Dropbox/org/") | |
(setq next-line-add-newlines nil) |