This file contains hidden or 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 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' + |
This file contains hidden or 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 sys | |
import os.path | |
import glob | |
# Get input and output folders as parameters | |
# if __name__ == '__main__': | |
# if len(sys.argv) < 3: | |
# pass | |
# else: |
This file contains hidden or 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 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__') |
This file contains hidden or 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 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) |
This file contains hidden or 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 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 |
This file contains hidden or 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 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, |
This file contains hidden or 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
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 |
This file contains hidden or 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
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 |
This file contains hidden or 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
# 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 |
This file contains hidden or 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
KBD_LAYOUT = { | |
'en': 'abcdefghijklmnopqrstuvwxyz[];\',.ABCDEFGHIJKLMNOPQRSTUVWXYZ{}:"<>`~@#$^&', | |
'ru': 'фисвуапршолдьтщзйкыегмцчняхъжэбюФИСВУАПРШОЛДЬТЩЗЙКЫЕГМЦЧНЯХЪЖЭБЮёЁ"№;:?', | |
'uk': 'фисвуапршолдьтщзйкіегмцчняхїжєбюФИСВУАПРШОЛДЬТЩЗЙКІЕГМЦЧНЯХЇЖЄБЮ\'₴"№;:?' | |
} |