Skip to content

Instantly share code, notes, and snippets.

@w495
w495 / complex_validation_for_pydantic_1.py
Last active July 25, 2024 12:52
Validation example with connected fields
import logging
from typing import TypeVar, Literal
from pydantic import BaseModel, root_validator
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.DEBUG)
class TestMarkup(BaseModel):
@w495
w495 / manjaro-dolphin-shortcut.shortcuts
Last active November 15, 2020 02:54
Manjaro KDE shortcuts for Dolphin that is compatible with Konsole shortcuts. The problem was described here: https://unix.stackexchange.com/questions/605671/key-sequence-ambiguous-in-konsole
[Shortcuts]
activate_last_tab=Alt+0
activate_next_tab=Ctrl+PgDown; Ctrl+]; Ctrl+Tab
activate_prev_tab=Ctrl+PgUp; Ctrl+[; Ctrl+Shift+Tab
activate_tab_0=Alt+1
activate_tab_1=Alt+2
activate_tab_2=Alt+3
activate_tab_3=Alt+4
activate_tab_4=Alt+5
activate_tab_5=Alt+6
@w495
w495 / base_function.py
Last active March 5, 2020 19:17
Простой пример добавление атрибута через метакласс
# coding: utf-8
import logging
class AddLoggerMeta(type):
def __new__(mcs, class_name, bases, attr_dict):
attr_dict[f'_{class_name}__logger'] = logging.getLogger(class_name)
return super().__new__(mcs, class_name, bases, attr_dict)
@w495
w495 / base_function.py
Created March 5, 2020 18:48
Пример использования приватных методов модуля в классе
# coding: utf-8
import logging
__logger = logging.getLogger(__name__)
def global_function():
__logger.error('global_function')
@w495
w495 / non-trivial-reverse.c
Created January 16, 2019 18:34
Non-trivial reverse with offset and limit
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef unsigned char byte_t;
static const byte_t offset = 1;
static const byte_t limit = 4;
@w495
w495 / hls-checker.py
Created October 22, 2018 22:32
Micro chunk HLS checker
# -*- coding: utf8 -*-
from __future__ import absolute_import, division, print_function
import logging
import sys
import requests
MIN_CHUNK_SIZE = 1.0
@w495
w495 / encoding.py
Last active March 26, 2018 01:39
Почему «Билл Гейтс» превратился в `«Р‘илл Гейтс»` или проблема с кодировками cp1251 и utf8
## РОДНОЕ ПРЕДСТАВЛЕНИЕ UTF8-СТРОКИ:
>>> [ord(i) for i in 'Бил Гейтс']
[208, 145, 208, 184, 208, 187,
32,
208, 147, 208, 181, 208, 185, 209, 130, 209, 129]
# Что тут происходит:
# * Я перебираю все символы строки через цикл FOR.
import sys
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split,GridSearchCV, cross_val_score,StratifiedKFold,validation_curve,learning_curve
from sklearn.metrics import confusion_matrix, f1_score, matthews_corrcoef, precision_recall_curve, auc, classification_report, roc_curve, cohen_kappa_score, make_scorer,accuracy_score,roc_auc_score,precision_score,recall_score, brier_score_loss
from imblearn.ensemble import BalancedBaggingClassifier
from sklearn.tree import DecisionTreeClassifier
from xgboost.sklearn import XGBClassifier
from sklearn.ensemble import RandomForestClassifier, AdaBoostClassifier
@w495
w495 / telesport-vod-example
Created February 2, 2018 14:11
Требования по VOD API
[
{
"content_id": "87fc1328-cde3-40b0-9b9b-ced0498747c4",
"content_url": "https://h2.silatv.ru/highlight/12121/1080.mp4",
"thumbnail": "http://cdn.okultureno.ru/medialibrary/87f/87f2341b53596e8ca592a1e885261ccf/khokkey-_1_.jpg"
"type" : "game",
"channel": "telesport1",
"release_timestamp": 1518421201, // не нужно при наличие start_time & finish_time
"start_time": 1518421200,
"finish_time": 1518429600,
# -*- coding: utf8 -*-
from __future__ import absolute_import, print_function
import six
class BaseFieldDao(object):
_value = None
_entity = None