Skip to content

Instantly share code, notes, and snippets.

@hyzyla
hyzyla / ukrposhta.py
Created January 3, 2024 16:52
Дістати поштові відділення по КАТОТТГ за допомогою API Укрпошти
from typing import List, Optional
import requests
from pydantic import BaseModel, Field
class GetPostOfficeEntry(BaseModel):
# Basic information
lock_en: str = Field(alias="LOCK_EN")
lock_ua: str = Field(alias="LOCK_UA")
@hyzyla
hyzyla / action.service.ts
Last active December 15, 2023 20:24
Controller + Service + Repository pattern with DrizzleORM
export class ActionService {
constructor(private actionReposiory: ActionReposiory) {
this.actionReposiory = actionReposiory;
}
async createAction(dto: any) {
return await this.actionReposiory.createAction(dto);
}
}
@hyzyla
hyzyla / upgrade.py
Created April 3, 2023 10:23
PostgreSQL change type of primary key using alembic
from dataclasses import dataclass
from alembic import op
@dataclass
class ForeignKeyConstraint:
name: str
table: str
column: str
sql: str
@hyzyla
hyzyla / error_reporting.py
Created December 30, 2022 10:03
Thin wrapper around Sentry SDK
"""
Thin wrapper around Sentry SDK, to hide details and do not depend on one product
"""
import logging
from contextlib import contextmanager
from typing import Any, Iterator
import sentry_sdk
from sentry_sdk.integrations.celery import CeleryIntegration
from sentry_sdk.integrations.logging import LoggingIntegration, ignore_logger
@hyzyla
hyzyla / get_unwrapped_messages.py
Created December 1, 2022 18:27
Script that allows to find unwrapped strings in Ukrainian langauge for translation
#!/usr/bin/env python3
# flake8: noqa
"""
Script that allows to find unwrapped strings in Ukrainian langauge for translation
"""
import ast
import re
import textwrap
from pathlib import Path
@hyzyla
hyzyla / docker-compose.yaml
Created July 19, 2022 17:06
maildev in docker-compose
version: "3.7"
services:
maildev:
image: maildev/maildev:1.1.1
environment:
MAILDEV_INCOMING_USER: user
MAILDEV_INCOMING_PASS: pass
ports:
@hyzyla
hyzyla / app.py
Last active September 29, 2020 12:50
aiohttp + tartiflette + aiodataloader ( DOESN'T WORKS!)
from aiohttp import web
import tartiflette
from tartiflette_aiohttp import register_graphql_handlers
import loader
sdl = """
type Query {
books: [Book]
}
@hyzyla
hyzyla / app.py
Created August 27, 2020 09:44
aiohttp + strawberry + aiodataloader example
from __future__ import annotations
from aiohttp import web
from strawberry.http import process_result
import loader
import graph
routes = web.RouteTableDef()
@hyzyla
hyzyla / pdf_fixer.py
Last active February 16, 2019 23:35
Function that removes any trash in PDF after last %%EOF marker
import io
import os
EOF_REVERSED = b'%%EOF'[::-1]
def fix_PDF_EOF(content: io.BytesIO) -> io.BytesIO:
""" Truncate data from last %%EOF in given PDF """
@hyzyla
hyzyla / index.js
Created February 10, 2019 16:54
Chromium page per handler with Puppeteer and Express.js
const puppeteer = require('puppeteer');
const express = require('express');
const asyncHandler = require('express-async-handler');
(async () => {
// initialise Express.js framework
const app = express();
// start chromium browser
let browser = await puppeteer.launch({headless: true});