Skip to content

Instantly share code, notes, and snippets.

View anatoly-scherbakov's full-sized avatar

Anatoly Scherbakov anatoly-scherbakov

View GitHub Profile
@anatoly-scherbakov
anatoly-scherbakov / test_parse.py
Created August 26, 2019 17:51
Parse UNRAR output with pyparsing
#!/bin/env python3
import json
from pyparsing import (
ParserElement, Literal, Group, restOfLine,
ZeroOrMore, LineEnd, CharsNotIn
)
TEXT = """UNRAR 5.71 freeware Copyright (c) 1993-2019 Alexander Roshal
@anatoly-scherbakov
anatoly-scherbakov / keybase.md
Created December 15, 2019 15:50
keybase.md

Keybase proof

I hereby claim:

  • I am anatoly-scherbakov on github.
  • I am homo_yetiensis (https://keybase.io/homo_yetiensis) on keybase.
  • I have a public key ASBsAsof7Lc8L9y_3XGt8gxpA9Z8iSepWgQOu0fhav-jTQo

To claim this, I am signing this object:

@anatoly-scherbakov
anatoly-scherbakov / dataclass_as_exception.py
Created February 22, 2020 16:03
Use dataclass as exception to communicate between different layers of an application
import dataclasses
@dataclasses.dataclass(frozen=True)
class AgeError(Exception):
name: str
age: int
def __str__(self):
return f'{self.name}, your age {self.age} is below minimum. Go play.'
@anatoly-scherbakov
anatoly-scherbakov / setup.cfg
Last active March 18, 2020 08:10
My custom setup.cfg file for wemake-python-styleguide
# Source:
# https://github.com/wemake-services/wemake-python-styleguide/blob/master/setup.cfg
# All configuration for plugins and other utils is defined here.
# Read more about `setup.cfg`:
# https://docs.python.org/3/distutils/configfile.html
# === Linter configuration ===
# You can reuse this configuration in your own projects.
@anatoly-scherbakov
anatoly-scherbakov / data.gql
Created March 30, 2020 20:02
Star Wars expressed in grakn.ai
insert
$jedi isa order, has name "Jedi";
$sith isa order, has name "Sith";
# Okay, let's start with some Jedi masters we know of.
$obi-wan isa human, has name "Obi-Wan Kenobi", has gender "male";
$obi-wan-is-jedi (member: $obi-wan, member-of: $jedi) isa membership;
# What do we know about Anakin?
import itertools
import functools
from typing import Iterator
import datetime
from dateutil.relativedelta import relativedelta
def month_range(
start: datetime.date,
import dataclasses
from datetime import datetime
from typing import Optional, Dict, Iterable
@dataclasses.dataclass(frozen=True)
class Memento:
original_url: str
time: datetime
archived_headers_cid: str
@anatoly-scherbakov
anatoly-scherbakov / reserved-concurrency.sh
Created May 11, 2020 07:15
Reserved concurrency per AWS Lambda function
#!/usr/bin/env bash
get_concurrency="aws lambda get-function-concurrency --function-name {} | jq -r '\"{.},\( .ReservedConcurrentExecutions )\"'"
tmpfile=$(tempfile) || exit
aws lambda list-functions \
| jq -r '.Functions[] .FunctionName' \
| parallel "$get_concurrency" > ${tmpfile}
from typing import Generic, TypeVar
from pydantic import ValidationError
from pydantic.fields import ModelField
T = TypeVar('T')
class CommaSeparatedList(Generic[T]):
"""Parse and validate a list of comma separated values."""
"""
Test JSON-LD expand operation in PyLD.
Supplementary code for https://github.com/digitalbazaar/pyld/issues/143
"""
import json
from pyld import jsonld