Skip to content

Instantly share code, notes, and snippets.

View sda97ghb's full-sized avatar

Dmitry Smirnov sda97ghb

View GitHub Profile
@sda97ghb
sda97ghb / Инструкция Git.md
Created November 14, 2023 09:32
Инструкция Git

Сообщение коммита

Правила оформления

1. Структура

1.1. Сообщение коммита состоит из двух частей: заголовка (summary) и тела (description), разделенных пустой строкой.

2. Заголовок

@sda97ghb
sda97ghb / try.py
Created August 29, 2023 12:31
Python try-catch-else as context manager
class Try:
err: Exception | None
def __init__(self) -> None:
self.err = None
def __enter__(self) -> "Try":
return self
def __exit__(self, err_t, err, tb) -> bool:
@sda97ghb
sda97ghb / undefined.py
Created August 12, 2023 14:44
Mypy friendly Undefined
import warnings
from enum import Enum
from typing import Literal, Self
class _UndefinedType(Enum):
Undefined = object() # concrete value is not important, since it's never used
@property
def value(self) -> "_UndefinedType":
@sda97ghb
sda97ghb / install-kubernetes.sh
Created February 12, 2022 12:56
install-kubernetes.sh
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl
sudo curl -fsSLo /usr/share/keyrings/kubernetes-archive-keyring.gpg https://packages.cloud.google.com/apt/doc/apt-key.gpg
echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
@sda97ghb
sda97ghb / install-containerd.sh
Created February 12, 2022 12:46
install-containerd.sh
sudo apt-get update
sudo apt-get install \
ca-certificates \
curl \
gnupg \
lsb-release
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

TL;DR;

  1. sort -u and sort | uniq have almost equal performance
  2. both of them are slow and can be replaced with faster python script

Input data

Create a file named generate.py containing the following code:

# generate.py
@sda97ghb
sda97ghb / payload_error.md
Created September 23, 2021 11:47
A sample of GraphQL mutation code returning error in the mutation payload's error field

Schema sample

type APIError {
    code: String
    message: String
    userMessage: String
}

type Mutaton {
@sda97ghb
sda97ghb / top_level_errors.md
Last active September 23, 2021 11:51
A sample of GraphQL mutation code returning errors in the top-level errors field

Schema sample

type Mutaton {
    updateFoo(data: UpdateFooInput!): UpdateFooPayload
}

type UpdateFooPayload {
    newFoo: Foo
}
#include <iostream>
#include <functional>
#include <vector>
using namespace std;
template <class Collection, typename Value, typename Result>
Result filter_map_reduce(
const Collection& collection,
function<bool(const Value&)> filter,
void DigitalChannelParametersListView::saveState(QVariantMap& outState) const
{
;
}
#define this_t std::remove_pointer<decltype(this)>::type
void DigitalChannelParametersListView::restoreState(QVariantMap inState)
{
using Z = void(DigitalChannelParametersListView::*)(QVariantMap);