Skip to content

Instantly share code, notes, and snippets.

View kkirsanov's full-sized avatar

Kirill Kirsanov kkirsanov

  • EY
  • Moscow, russia
View GitHub Profile
@kkirsanov
kkirsanov / ey.tex
Created April 26, 2019 11:06
EY 2019 color scheme in LaTex
\definecolor{EYYellow}{RGB}{255,230,0}
\definecolor{EYBlack}{RGB}{46,46,56}
\definecolor{EYGray1}{RGB}{116,116,128}
\definecolor{EYGray2}{RGB}{196,196,205}
\definecolor{EYWhite}{RGB}{246,246,250}
@kkirsanov
kkirsanov / test.py
Last active April 25, 2019 06:22
dataframe serialization perfomance
import os
import time
import numpy as np
import pandas as pd
import pandavro
def size(size, precision=2):
suffixes = ['B', 'KB', 'MB', 'GB', 'TB']
class DynamicFieldsModelSerializer(serializers.ModelSerializer):
"""
A ModelSerializer that takes an additional `fields` argument that
controls which fields should be displayed.
based on https://bit.ly/2TnW0ZJ
Usage: api_endpoint/?fields=uid,name,alias,parent
api_endpoint/?fields!=parent
"""
@kkirsanov
kkirsanov / maybe_enum.py
Created February 7, 2019 10:25
maybe enum in AVRO
from io import BytesIO
import fastavro
schema = {
"fields": [
{
"name": "maybe_enum",
"type": ["null", {
"type": "enum",
"name": "methods",
@kkirsanov
kkirsanov / migration
Created November 26, 2018 12:13
Как доавить UUID PK
# -*- coding: utf-8 -*-
# Generated by Django 1.11 on 2017-05-31 11:05
from __future__ import unicode_literals
from django.db import migrations
def load_stores_from_fixture(apps, schema_editor):
from django.core.management import call_command
call_command("loaddata", "dump.json")
@kkirsanov
kkirsanov / grafana-telegram-bot.md
Last active March 4, 2022 00:32
Как подключить telegram-бота к графане
  1. Cоздаем своего бота: Ищем в телеграмме бота @BotFather и говорим /newbot. В процессе создания получаем api-key для бота
  2. Добавляем в интересующий нас чат этого бота
  3. В этот же чат добавляем бота @myidbot и говорим ему /getgroupid@myidbot. Эта команда даст нам id чата
  4. В настройках Notification Channel графаны выбираем telegram и пишем туда полученные ранее api-key и id чата
@kkirsanov
kkirsanov / prometheus.py
Created November 22, 2018 09:20
write prometheus metrics to string
from prometheus_client import CollectorRegistry, Gauge, generate_latest
registry = CollectorRegistry()
g = Gauge('reg_cnt', '1-2 per day is ok', registry=registry)
g.set(2)
print(generate_latest(registry))
@kkirsanov
kkirsanov / pfx.py
Created August 1, 2018 14:42
Работа с сертификатами
from OpenSSL import crypto
def createKeyPair():
pkey = crypto.PKey()
pkey.generate_key(crypto.TYPE_DSA, 2048)
pubKeyString = crypto.dump_publickey(crypto.FILETYPE_PEM, pkey).decode('latin1')
privateKeyString = crypto.dump_privatekey(crypto.FILETYPE_PEM, pkey).decode('latin1')
return pubKeyString, privateKeyString
--{-# OPTIONS_GHC -Wall -Werror #-}
module Scheduler
( someFunc,
) where
import Data.Maybe (isJust, isNothing)
import qualified Data.Map as M
data SchedulerState = SchedulerState
@kkirsanov
kkirsanov / disable.py
Created November 23, 2017 15:26
Disable logical reader in fastavro
import datetime
from io import BytesIO
from pprint import pprint
from uuid import uuid4
import fastavro
fastavro._reader.LOGICAL_READERS['long-timestamp-millis'] = lambda d, w, r: d
schema = {