Skip to content

Instantly share code, notes, and snippets.

# -*- coding: utf-8 -*-
from django import forms
from django.utils.html import escape, conditional_escape
from django.utils.encoding import force_unicode
def get_attr(obj, attr):
if hasattr(obj, attr):
res = getattr(obj, attr)
@paveltyavin
paveltyavin / er.py
Last active August 29, 2015 14:16
euler504
# coding=utf-8
from itertools import product
import time
m = 10
squares = set([x * x for x in range(2 * m)])
delimeters = {1: set({})} # Словарь делителей чисел
for x, y in product(xrange(2, m + 1), repeat=2):
# coding=utf-8
from django.test import LiveServerTestCase
from selenium import webdriver
from selenium.common.exceptions import WebDriverException
from django.contrib.auth import get_user_model
User = get_user_model()
class AdminTestCase(LiveServerTestCase):
def setUp(self):
@paveltyavin
paveltyavin / select2 paginate without ajax.coffee
Last active August 29, 2015 14:17
Select2 paginate without ajax using query method. You can fetch data from server first or from localstorage and then paginate it in select2.
city_list = [{name: 'Moscow', id: 1},{name: 'Saint Petersburg', id: 2}]
$('.city').select2
query: (options) ->
term = options.term.toLowerCase()
results = []
output = {}
paginate_by = 50
i = 0
j = 0
upstream dr-tg.tyavin.name {
server localhost:8019 fail_timeout=0;
}
server {
listen 80;
client_max_body_size 4G;
server_name dr-tg.tyavin.name;
access_log /var/log/dr-tg.log;
error_log /home/vinograd19/dr-tg/log/nginx_error.log;
class ShopTest(TestCase):
def setUp(self):
self.network = Network.objects.create()
self.region1 = Region.objects.create()
self.region2 = Region.objects.create()
self.city1 = City.objects.create(region=self.region1)
self.city2 = City.objects.create(region=self.region2)
self.shop1 = Shop.objects.create(
code='0001',
cluster=Cluster.objects.create(),
@paveltyavin
paveltyavin / views.py
Created December 28, 2015 15:49
наследование
class Mixin(object):
def get_queryset(self):
raise self.get_object().products.all()
class WrongListView(ListCreateAPIView, Mixin):
pass
class RightListView(Mixin, ListCreateAPIView):
module.exports = class Base
edge: (which) ->
if which == 'start'
return 'left'
else if which == 'end'
return 'right'
throw new TypeError('What kind of an edge is ' + which)
edgeProp: (edge, prop) ->
o = @$el[prop]()
o[@edge(edge)]
password
123456
12345678
1234
qwerty
12345
dragon
pussy
baseball
football
@paveltyavin
paveltyavin / test.py
Created May 29, 2016 20:41
python hash tables chaining experiment
import time
import math
N = 1000 # any number greater than 1000
class B(object):
"""
Hash always returns the same value.
Then any hash table based on instances of this class will always contain one chain.