Skip to content

Instantly share code, notes, and snippets.

View gtors's full-sized avatar

Andrey Torsunov gtors

  • Russian Federation, Kazan
View GitHub Profile
@gtors
gtors / esp.ksy
Last active February 23, 2024 13:42 — forked from igrr/esp.ksy
esp8266 with OTA
# Try it out by opening https://ide.kaitai.io/ and copying this file there
# Based on an article by @angelcarve about ESP8266 binary image parsing with Kaitai Struct:
# https://carvesystems.com/news/parsing-binaries-with-kaitai-struct/
meta:
id: esp8266
file-extension: bin
endian: le
seq:
@gtors
gtors / annuity_payment.py
Created December 14, 2023 10:58
Раcсчет аннуительного платежа
def calculate_monthly_payment(
*,
loan: float | int | str | Decimal,
annual_interest_rate: float | str | Decimal,
years: int | None = None,
months: int | None = None,
):
"""
Calculates the annuity monthly mortgage payment
@gtors
gtors / rate_limiter.py
Last active September 28, 2023 15:49
simple per second rate limiter
def rate_limit_per_second(rate: int):
last_request = time.time()
lock = asyncio.Lock()
@contextlib.asynccontextmanager
async def rate_limiter():
nonlocal last_request, lock
async with lock:
now = time.time()
elapsed = now - last_request
@gtors
gtors / xml2json.py
Created August 6, 2021 11:26
Script for converting xml to json
#!/usr/bin/env python
"""xml2json.py Convert XML to JSON
Relies on ElementTree for the XML parsing. This is based on
pesterfish.py but uses a different XML->JSON mapping.
The XML->JSON mapping is described at
http://www.xml.com/pub/a/2006/05/31/converting-between-xml-and-json.html
Rewritten to a command line utility by Hay Kranen < github.com/hay >
@gtors
gtors / printer_search.txt
Created July 20, 2021 07:40
Printer installation
avahi-browse -rt _ipp._tcp
avahi-browse -rt _uscan._tcp
driverless
lpadmin -p PRINTER_NAME -v "result_of_driverless" -E -m everywhere
@gtors
gtors / .gitlab-ci.yml
Created July 16, 2021 10:47 — forked from aviadlevy/.gitlab-ci.yml
.gitlab-ci.yml with versioning and changelog
image: docker:latest
services:
- docker:dind
stages:
- build
- integration
- dev-release
- prod-release
@gtors
gtors / pg.sql
Created May 17, 2021 14:39
Postgres "lock trees" analysis: the forest of trees of blocked and blocking sessions
-- https://gitlab.com/-/snippets/1890428
-- The query shows "the forest of trees" of blocked and blocking sessions with the corresponding queries. It helps to understand, which session is being blocked by which one, and what is "the depth" of the lock chain.
-- Use it to find the "roots" of trees, then use pg_cancel_backend(pid) or pg_terminate_backend(pid) to get rid of blockers and release the locks.
-- Derived from DataEgret's locktree.sql (https://github.com/dataegret/pg-utils/blob/master/sql/locktree.sql)
\timing on
set statement_timeout to '2s';
with recursive l as (
select
@gtors
gtors / kvazi_pipeline.py
Created March 8, 2021 17:27
draft of coroutine based pipeline
import itertools
NEXT = object()
class new_pipeline:
def __init__(self):
self._coroutines = []
@gtors
gtors / sort_classes.py
Last active January 27, 2021 11:13
Python script for sorting class definitions in file
"""
Script for sorting classes by type in annotation. It may be usefull for code refactoring after code generation.
For example:
```
class C:
a: Optional[A] = None
b: Optional[B] = None
@gtors
gtors / get_payload.py
Created September 7, 2020 09:21 — forked from eybisi/get_payload.py
get decrypted payload from all apk files
#get apks from server? wget -np -e robots=off -m site.com/apk/folder/
#Place all apks in the same dir as py file or change os.listdir parameter
#you can get del.js from my repo https://github.com/eybisi/fridaScripts/blob/master/del.js
import os
from androguard.core.bytecodes import apk
import frida
import time
device = frida.get_usb_device()
files = [f for f in os.listdir("./")]
for f in files: