Skip to content

Instantly share code, notes, and snippets.

View truetug's full-sized avatar
:octocat:
I am just trying to do my best!

Sergey Trofimov truetug

:octocat:
I am just trying to do my best!
View GitHub Profile
@truetug
truetug / .zshrc
Created August 27, 2023 11:02
Fast and simple function to automagicaly find and activate python virtual environment with venv
# virtualenv
virtualenv_find_and_activate() {
local ENV_DIR="env"
[ ! -z "${1}" ] && ENV_DIR=$1
local CURRENT=$(pwd)
local ROOT=${CURRENT}
local RESULT=0
while [ "${ROOT}" != "/" ] && [[ "${RESULT}" == 0 ]]; do
local DIRS=( "${ROOT}/${ENV_DIR}" "${ROOT}_${ENV_DIR}" )
@truetug
truetug / Makefile
Last active September 7, 2023 13:55
Async Sqlalchemy for FastAPI in 2023
SHELL=/bin/bash
.PHONY: lint-yml
lint-yml: ## Lints all yaml files with yamllint docker image
@echo "* Lint YAML"
@yamllint -f parsable -c .yamllint .
@echo "done"
.PHONY: check-isort
check-isort: ## Check isort
@truetug
truetug / poetry2pip.py
Created November 29, 2021 12:01
Simple script to convert raw poetry dependencies to requirements.txt format
import re
import toml
def convert():
data = toml.load("pyproject.toml")
result = []
for package_name, params in data["tool"]["poetry"]["dependencies"].items():
if package_name == "python":
@truetug
truetug / block_convert.py
Created October 22, 2021 09:04
That command is for django and wagtail based sites would help if you need to convert all your old blocks to new on every page
import json
import logging
import os
import uuid
from copy import deepcopy
from django.conf import settings
from django.core.management import BaseCommand
from wagtail.core.models import Page
@truetug
truetug / pylint.rc
Created June 30, 2016 08:43
pylint config for our django projects
[MASTER]
profile=no
persistent=yes
ignore=migrations
cache-size=500
[MESSAGES CONTROL]
# C0111 Missing docstring
# E1120 No value passed for parameter 'cls' infunction call
# I0011 Warning locally suppressed using disable-msg
@truetug
truetug / merge_sorted_arrays.py
Last active June 27, 2016 10:42
Task for ezhome.com
#!/usr/bin/env python
# encoding: utf-8
# Write a function that accepts 2 arrays.
# The arrays contain numbers and each input array is already sorted in increasing order.
# The function should create and return another array
# which contains all of the numbers that are in the 2 input arrays.
# The numbers in the returned array should also be sorted in increasing order.
# The goal is to write code that executes as fast as possible for large arrays.
# Implement without using any third party libraries.
#
@truetug
truetug / habraproxy.py
Last active March 21, 2016 21:08
Тестовая задачка от ivelum.com
#!/usr/bin/env python
# encoding: utf-8
# habraproxy.py — это простейший http-прокси-сервер, запускаемый локально (порт на ваше
# усмотрение), который показывает содержимое страниц Хабра. С одним исключением: после
# каждого слова из шести букв должен стоять значок «™». Примерно так:
#
# http://habrahabr.ru/company/yandex/blog/258673/
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# Сейчас на фоне уязвимости Logjam все в индустрии в очередной раз обсуждают проблемы и
@truetug
truetug / tornado_multiasynchttpclient_example.py
Created May 31, 2013 08:53
MD5 hash calculation of multiple simultaneous requests
#!/usr/bin/env python
# encoding: utf-8
import functools
import hashlib
import logging
import tornado.web
import tornado.gen
import tornado.httpclient
import tornado.ioloop