This file contains 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
""" | |
Небольшая шпаргалка по библиотечке respx. Все это есть в документации https://lundberg.github.io/respx/guide/, | |
но местами написано очень коротко и не очевидно. | |
Зависимости: python > 3.10, httpx, respx, pytest-asyncio | |
""" | |
from typing import Any | |
import httpx | |
import pytest |
This file contains 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 datetime | |
import ssl | |
import sys | |
import warnings | |
from requests.adapters import HTTPAdapter | |
from requests.packages import urllib3 | |
from requests.packages.urllib3.util import ssl_ | |
from requests.packages.urllib3.exceptions import ( |
This file contains 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
# Alternatively don't use slog but something else. I just like that more. | |
[aliases] | |
slog = log --pretty=format:"%C(auto,yellow)%h%C(auto)%d\\ %C(auto,reset)%s\\ \\ [%C(auto,blue)%cn%C(auto,reset),\\ %C(auto,cyan)%ar%C(auto,reset)]" | |
addprx = "!f() { b=`git symbolic-ref -q --short HEAD` && \ | |
git fetch origin pull/$1/head:pr/$1 && \ | |
git fetch -f origin pull/$1/merge:PR_MERGE_HEAD && \ | |
git rebase --onto $b PR_MERGE_HEAD^ pr/$1 && \ | |
git branch -D PR_MERGE_HEAD && \ | |
git checkout $b && echo && \ | |
git diff --stat $b..pr/$1 && echo && \ |
This file contains 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 pkg_resources, pprint | |
requires = {p.key: [r.key for r in p.requires()] for p in pkg_resources.working_set} | |
def graph(pkg): | |
if not requires[pkg]: | |
return {pkg: {}} | |
return {pkg: {k: v for p in requires[pkg] for k, v in graph(p).items() }} |
This file contains 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
class InvalidStringHandler(object): | |
"""Custom handler for invalid string in templates.""" | |
def __call__(self): | |
"""Force crashes in {{ foo|sth }}, without breaking __str__.""" | |
import ipdb; ipdb.set_trace() | |
raise ValueError() | |
def __nonzero__(self): | |
"""So that '{% if foo %}' doesn't break.""" |
This file contains 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.conf import settings | |
from django.core.files.storage import Storage | |
from django.utils import importlib | |
def load_class(class_string): | |
class_module, class_name = class_string.rsplit('.', 1) | |
class_module = importlib.import_module(class_module) | |
return getattr(class_module, class_name) |
This file contains 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
** Find commmonly accessed tables and their use of indexes: | |
SELECT relname,seq_tup_read,idx_tup_fetch,cast(idx_tup_fetch AS numeric) / (idx_tup_fetch + seq_tup_read) AS idx_tup_pct FROM pg_stat_user_tables WHERE (idx_tup_fetch + seq_tup_read)>0 ORDER BY idx_tup_pct; | |
Returns output like: | |
relname | seq_tup_read | idx_tup_fetch | idx_tup_pct | |
----------------------+--------------+---------------+------------------------ | |
schema_migrations | 817 | 0 | 0.00000000000000000000 | |
user_device_photos | 349 | 0 | 0.00000000000000000000 |
This file contains 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
# force HTTP to HTTPS - /etc/nginx/conf.d/nonssl.conf | |
server { | |
listen 80; | |
server_name jira.example.com; | |
access_log off; | |
return 301 https://$server_name$request_uri; | |
} | |
# /etc/nginx/conf.d/jira.conf | |
server { |
This file contains 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
requests.put('http://localhost:9200/site/', data=json.dumps({ | |
'settings': { | |
'analysis': { | |
'analyzer': { | |
'ru': { | |
'type': 'custom', | |
'tokenizer': 'standard', | |
"filter": ['lowercase', 'russian_morphology', 'english_morphology', 'ru_stopwords'], | |
}, | |
}, |
This file contains 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
# GITOLITE 3 | |
sudo -u git -H sed -i "s/\(GIT_CONFIG_KEYS\s*=>*\s*\).\{2\}/\1'\.\*'/g" /home/git/.gitolite.rc | |
# GITOLITE 2 | |
sudo -u git -H sed -i 's/\(GL_GITCONFIG_KEYS\s*=>*\s*\).\{2\}/\1"\.\*"/g' /home/git/.gitolite.rc |
NewerOlder