Skip to content

Instantly share code, notes, and snippets.

View dmitry-naumenko's full-sized avatar
🎯
Focusing

Dmitry Naumenko dmitry-naumenko

🎯
Focusing
View GitHub Profile
@dmitry-naumenko
dmitry-naumenko / get_unused_indexes.sql
Last active April 13, 2021 10:28
Для определения неиспользуемых индексов
SELECT
idstat.relname AS TABLE_NAME, -- имя таблицы
indexrelname AS index_name, -- индекс
idstat.idx_scan AS index_scans_count, -- число сканирований по этому индексу
pg_size_pretty(pg_relation_size(indexrelid)) AS index_size, -- размер индекса
tabstat.idx_scan AS table_reads_index_count, -- индексных чтений по таблице
tabstat.seq_scan AS table_reads_seq_count, -- последовательных чтений по таблице
tabstat.seq_scan + tabstat.idx_scan AS table_reads_count, -- чтений по таблице
n_tup_upd + n_tup_ins + n_tup_del AS table_writes_count, -- операций записи
pg_size_pretty(pg_relation_size(idstat.relid)) AS table_size -- размер таблицы
SELECT pg_stat_reset();
@dmitry-naumenko
dmitry-naumenko / get_unused_indexes_en.sql
Created January 10, 2020 10:01
Identify unused indexes.
SELECT
idstat.relname AS TABLE_NAME,
indexrelname AS index_name,
idstat.idx_scan AS index_scans_count,
pg_size_pretty(pg_relation_size(indexrelid)) AS index_size,
tabstat.idx_scan AS table_reads_index_count,
tabstat.seq_scan AS table_reads_seq_count,
tabstat.seq_scan + tabstat.idx_scan AS table_reads_count,
n_tup_upd + n_tup_ins + n_tup_del AS table_writes_count,
pg_size_pretty(pg_relation_size(idstat.relid)) AS table_size
@dmitry-naumenko
dmitry-naumenko / оквэд.json
Last active June 27, 2024 07:12
Все коды ОКВЭД в JSON
[
{
"code": "Раздел A",
"name": "Сельское, лесное хозяйство, охота, рыболовство и рыбоводство",
"items": [
{
"code": "01",
"name": "Растениеводство и животноводство, охота и предоставление соответствующих услуг в этих областях",
"items": [
{
@dmitry-naumenko
dmitry-naumenko / города_и_регионы.json
Created March 17, 2020 11:41
Города и Регионы в JSON
[
{
"id": "113",
"parent_id": null,
"name": "Россия",
"areas": [
{
"id": "1620",
"parent_id": "113",
"name": "Республика Марий Эл",
@dmitry-naumenko
dmitry-naumenko / Sphinx_Setup_for_autodoc.md
Created March 28, 2020 15:21 — forked from GLMeece/Sphinx_Setup_for_autodoc.md
Setting up Sphinx for generating documentation from DocStrings, leveraging the Napoleon extension.

Sphinx Setup for autodoc

Sphinx is a documentation generator that is the de facto standard for Python projects. The official documentation can be a bit daunting as it includes so many options, it's hard to know where to start.

Note: This Gist was updated on 04/04/2019 to accomodate a newer version of Sphinx, as well as Python 3.7. YMMV!

This document is written with the following presuppositions:

from django.http import Http404
def check_user_able_to_see_page(function):
def wrapper(request, *args, **kwargs):
if request.user.groups.filter(name="admin").exists():
return function(request, *args, **kwargs)
raise Http404
return wrapper
from django.http import Http404
def check_user_able_to_see_page(*groups):
def decorator(function):
def wrapper(request, *args, **kwargs):
if request.user.groups.filter(name__in=groups).exists():
return function(request, *args, **kwargs)
raise Http404
from django.http import Http404
from .constants import Group
def check_user_able_to_see_page(*groups: Group):
def decorator(function):
def wrapper(request, *args, **kwargs):
if request.user.groups.filter(
name__in=[group.name for group in groups]
).exists():
@dmitry-naumenko
dmitry-naumenko / test_code.yml
Created August 6, 2021 11:54
Пример github actions. Нужно добавить этот файл в .github/workflows/ и github сам начнет с ним работу
name: test_code
on: [push]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup Python