Skip to content

Instantly share code, notes, and snippets.

@paveltyavin
paveltyavin / geohash_list.py
Last active August 16, 2017 13:00
converts polygon to list of geohashes. You can specify precision and tile policy. Different interpretations of geohashes in output.
"""find geohashes inside polygon"""
from __future__ import division
__base32 = '0123456789bcdefghjkmnpqrstuvwxyz'
precision = 8
geohash_corners_inside_polygon_policy = any # or all
def geohash(lon, lat):
result_str = []
from PIL import Image
from PIL import ImageDraw
from math import tanh
import random
Size = 512
im = Image.new("RGB", (Size, Size), "#fff")
draw = ImageDraw.Draw(im)
// go test -run none -bench .
package b
import (
"math/rand"
"sort"
"testing"
)
const M = 8192
@paveltyavin
paveltyavin / benchmark.md
Last active June 7, 2016 20:05
typedict vs schematics benchmark
typeddict_test       1.759s        372 Kb
schematics_test 2.0  3.188s        152 Kb
schematics_test 1.1  3.339s         96 Kb
@paveltyavin
paveltyavin / command.py
Created June 7, 2016 16:37
update bunch of django models using naive implemetation, multiprocessing, multithreading in postgres and sqlite
# coding: utf-8
import threading
import time
import random
import string
from django.db import connection
from multiprocessing import Pool
from django.core.management.base import BaseCommand
@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.
password
123456
12345678
1234
qwerty
12345
dragon
pussy
baseball
football
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)]
@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):
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(),