Skip to content

Instantly share code, notes, and snippets.

View otykhonruk's full-sized avatar

Oleksandr Tykhonruk otykhonruk

View GitHub Profile
import sys
import os.path
import glob
# Get input and output folders as parameters
try:
dir_in = sys.argv[1]
dir_out = sys.argv[2]
except IndexError:
print('======================================================\n' +
import sys
import os.path
import glob
# Get input and output folders as parameters
# if __name__ == '__main__':
# if len(sys.argv) < 3:
# pass
# else:
from django.db.models import F
from django.core.files.uploadedfile import SimpleUploadedFile
from django.test import TestCase
from Core.models import Picture
class RaceConditionDemo(TestCase):
def setUp(self):
fakepic = SimpleUploadedFile('sample_pic.jpg', b'__content__')
import this
from random import choice
from django.conf import settings
from django.conf.urls import url
from django.core.management import execute_from_command_line
from django.http import HttpResponse
text = ''.join(this.d.get(c, c) for c in this.s)
@otykhonruk
otykhonruk / dkd.py
Last active November 10, 2017 16:47
import json
import math
import re
import urllib.parse
from collections import Counter
from difflib import SequenceMatcher
from pprint import pprint
from tldextract import extract as tldextract
from unidecode import unidecode
@otykhonruk
otykhonruk / rgb.py
Last active November 5, 2018 22:49
from collections import namedtuple
from operator import itemgetter, sub
class rgb:
# https://www.w3.org/TR/REC-html40/types.html#h-6.5
_NAMED_COLORS = {
'black': 0x000000,
'green': 0x008000,
'silver': 0xC0C0C0,
def spiral(m, n):
""" Spiral matrix traversal (counterclockwise). """
m -= 1
dx, dy = 0, 1
x, y = 0, -1
while m >= 0 and n >= 0:
for _ in range(m if dx else n):
x += dx
y += dy
def reverse_bits(n):
assert 1 <= n <= 1000000000,\
'argument must be in range [1, 1000000000]'
r = 0
while n:
r <<= 1
r |= n & 1
n >>= 1
return r
# Cellular automata
# https://natureofcode.com/book/chapter-7-cellular-automata/
def ca(rule, ncells):
def _next_cell(a, b, c):
a <<= 1
a |= b
a <<= 1
a |= c
return (rule & (1 << a)) >> a
KBD_LAYOUT = {
'en': 'abcdefghijklmnopqrstuvwxyz[];\',.ABCDEFGHIJKLMNOPQRSTUVWXYZ{}:"<>`~@#$^&',
'ru': 'фисвуапршолдьтщзйкыегмцчняхъжэбюФИСВУАПРШОЛДЬТЩЗЙКЫЕГМЦЧНЯХЪЖЭБЮёЁ"№;:?',
'uk': 'фисвуапршолдьтщзйкіегмцчняхїжєбюФИСВУАПРШОЛДЬТЩЗЙКІЕГМЦЧНЯХЇЖЄБЮ\'₴"№;:?'
}