Skip to content

Instantly share code, notes, and snippets.

View dmig's full-sized avatar

Dmitriy Geels dmig

View GitHub Profile
@dmig
dmig / pagination.py
Created April 21, 2021 09:46
paged query model
import typing
from cryptography.fernet import Fernet
from pydantic import BaseModel
from lib.conf import config
fernet = Fernet(config.FEED_FERNET_KEY)
@dmig
dmig / array_degree.py
Created March 16, 2021 21:08
"Degree of an Array" test task
'''
Given a non-empty array N, of non-negative integers , the degree of this array is defined as the maximum frequency of any one of its elements. Your task is to find the smallest possible length of a (contiguous) subarray of N, that has the same degree as N. For example, in the array [1 2 2 3 1], integer 2 occurs maximum of twice. Hence the degree is 2.
Input
Test case input contains 2 lines.
First line contains an integer T, representing the number of elements in the array.
The second line contains the array N, list of T integers each separated by space.
Output
@dmig
dmig / trees.py
Created March 16, 2021 15:46
Fractal tree: a solution for a beautiful task from HackerRank (https://www.hackerrank.com/challenges/fractal-trees-all/problem)
# same implemented in python as a POC
N=5
print('_' * 100)
offset = 0
for i in range(5-N):
offset += 2 ** i
for j in range(2 ** i * 2):
print('_' * 100)
@dmig
dmig / binary-tree-traversal.py
Created March 16, 2021 15:43
binary tree traversal: find longest unique paths
from typing import Optional
'''
1
/ \
2 2
/ \ / \
1 2 4 1
1
@dmig
dmig / asyncpg_ph_translator.py
Created July 28, 2020 09:38
Placeholder translator for use with asyncpg
import logging
import re
_ph_catcher = re.compile('\\{(\\w+)\\}')
def translate_placeholders(query: str, params: Dict[str, Any]) -> Tuple[str, List[Any]]:
"""
This is a simple translator designed to allow usage of queries like
`SELECT a, b, c FROM table WHERE d = {d} AND e = {e}` with parameters in
@dmig
dmig / avito.py
Created March 30, 2019 14:23
avito page parser demo
#! /usr/bin/env python3
import csv
import requests
from bs4 import BeautifulSoup
outfile = open('output.csv', 'w')
csvwriter = csv.writer(outfile)
csvwriter.writerow(['name', 'date', 'address', 'price', 'currency', 'photo', 'url'])
session = requests.Session()
@dmig
dmig / temperatures
Last active March 21, 2019 13:33
simple bash script to view hardware temperatures
#! /bin/bash
# ignore sensors by names (this string must contain full sensor names)
IGNORE='INT3400 Thermal acpitz'
RED='\033[1;31m'
GREEN='\033[1;32m'
YELLOW='\033[1;33m'
BLUE='\033[1;34m'
NC='\033[0m' # No Color
@dmig
dmig / .pylintrc
Created November 16, 2018 02:56
testcase
[MASTER]
extension-pkg-whitelist=gimpfu
[VARIABLES]
# List of additional names supposed to be defined in builtins. Remember that
# you should avoid to define new builtins when possible.
additional-builtins=ADDITION_MODE,ADD_ALPHA_MASK,ADD_ALPHA_TRANSFER_MASK,ADD_BLACK_MASK,
ADD_CHANNEL_MASK,ADD_COPY_MASK,ADD_MASK_ALPHA,ADD_MASK_ALPHA_TRANSFER,
ADD_MASK_BLACK,ADD_MASK_CHANNEL,ADD_MASK_COPY,ADD_MASK_SELECTION,
ADD_MASK_WHITE,ADD_SELECTION_MASK,ADD_WHITE_MASK,ALL_HUES,ALPHA_CHANNEL,
@dmig
dmig / ccxt-coins-dump.py
Created June 7, 2018 15:12
Coin collision search tools
#! venv/bin/python3
import ccxt
for cls in ccxt.exchanges:
Exch = ccxt.__dict__[cls]({'timeout': 20000})
if not Exch.has['publicAPI']:
print('# %s: only private API, skipped' % (cls,))
continue
if not Exch.has['fetchCurrencies']:
print('# %s: doesn\'t support fetchCurrencies, skipped' % (cls,))
@dmig
dmig / mongod.json
Created May 13, 2018 06:10
lnav MongoDB log format
{
"mongod_log": {
"title": "MongoDB server log format",
"regex": {
"main": {
"pattern": "^(?<timestamp>\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}[,\\.]\\d+\\+\\d+)\\s+(?<level>\\w)\\s+(?<component>\\w+|-)\\s+\\[?(?<context>-?\\w+)?\\]\\s+(?<body>.*)$"
}
},
"level": {
"critical": "F",