Skip to content

Instantly share code, notes, and snippets.

@gennad
gennad / euler8
Created May 14, 2012 10:03
Project Euler 8 problem
s = """
73167176531330624919225119674426574742355349194934
96983520312774506326239578318016984801869478851843
85861560789112949495459501737958331952853208805511
12540698747158523863050715693290963295227443043557
66896648950445244523161731856403098711121722383113
62229893423380308135336276614282806444486645238749
30358907296290491560440772390713810515859307960866
70172427121883998797908792274921901699720888093776
65727333001053367881220235421809751254540594752243
@gennad
gennad / gist:2836618
Created May 30, 2012 14:18
Python task
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))
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;
@gennad
gennad / gist:2842869
Created May 31, 2012 11:45
Задача на SQL
--Задача: есть таблица
fish
name CHAR(20)
price INT(5)
date DATE
--В таблице есть данные:
forel 2012-01-01 10
forel 2012-01-03 6
@gennad
gennad / gist:2842895
Created May 31, 2012 11:49
Еще одна старая задача, не помню условие, но есть решение на Python
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 = []
@gennad
gennad / gist:2850881
Created June 1, 2012 09:56
Задача на SQL
--Есть 2 таблицы:
--users
--UID Name
--1 «Александр»
--2 «Семён»
--messages
--UID msg
--1 “A”
--1 “B”
@gennad
gennad / gist:2851103
Created June 1, 2012 10:43
Tricky question Python
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__
@gennad
gennad / gist:2851140
Created June 1, 2012 10:52
Simple interview question Python
# 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
@gennad
gennad / gist:2894234
Created June 8, 2012 07:32
Python database populate
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))
@gennad
gennad / gist:3396504
Last active October 8, 2015 22:17
latest .emacs
(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)