Skip to content

Instantly share code, notes, and snippets.

View iAnanich's full-sized avatar

Illia Ananich iAnanich

  • Ukraine
View GitHub Profile
@iAnanich
iAnanich / set-bash-history-time-format.sh
Last active June 15, 2023 09:19
Enable recording datetime in bash history
#!/bin/bash
# This bash script configures the bash history to include timestamps in a human-readable format.
# It first checks if the user's .bashrc file exists and contains the HISTTIMEFORMAT configuration.
# If the .bashrc file doesn't exist, it creates it and adds the HISTTIMEFORMAT configuration.
# If the .bashrc file exists but doesn't contain the HISTTIMEFORMAT configuration, it adds the configuration.
# It then applies the changes immediately by sourcing the .bashrc file.
# Define the time format for ease of modification and reuse
TIME_FORMAT="%y-%m-%d %T | "
@iAnanich
iAnanich / swarmpit_api.py
Created April 15, 2023 18:12
Simple SwarmPit API adapter example
from dataclasses import dataclass, field
from typing import Optional
from urllib.parse import urljoin
import httpx
@dataclass
class Swarmpit:
"""
@iAnanich
iAnanich / do.sh
Last active April 2, 2023 08:30
Shell script that helps to simplify Docker Compose usage
#!/bin/bash
### ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ###
### Generated with the help of ChatGPT ###
### ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ###
# Usage:
# ./do.sh dc ps
# ./do.sh dc down
# ./do.sh dc up -d service
@iAnanich
iAnanich / dataclass_from_dict.py
Created May 23, 2021 21:50 — forked from gatopeich/dataclass_from_dict.py
Python 3.7 dataclass to/from dict/json
from dataclasses import dataclass, fields as datafields
from ujson import dumps, loads
# Note: ujson seamlessly serializes dataclasses, unlike stdlib's json
@dataclass
class Point:
x: float
y: float
# Shallow dataclass can be rebuilt from dict/json:
@iAnanich
iAnanich / gauth.py
Created October 22, 2020 07:11
Google's ID token verification module
"""
https://developers.google.com/identity/sign-in/android/backend-auth#verify-the-integrity-of-the-id-token
"""
import json
from typing import Optional, List
import yarl
from google.oauth2 import id_token
from google.auth.transport import requests as google_requests
@iAnanich
iAnanich / pipeline.py
Created October 25, 2019 23:59
AsyncIO Pipeline
import typing
import asyncio
class Layer:
class STATES:
IDLE = 1
RUNNING = 2
GOING_TO_STOP = 3
STOPPED = 4

Keybase proof

I hereby claim:

  • I am iananich on github.
  • I am iananich (https://keybase.io/iananich) on keybase.
  • I have a public key ASBYPJtCfPWT52GR3ljVWuOcyiqu2KubKlaUvofCPiJ2zAo

To claim this, I am signing this object:

@iAnanich
iAnanich / install-postgres-10-ubuntu.md
Created August 5, 2018 19:48 — forked from alistairewj/install-postgres-10-ubuntu.md
Install PostgreSQL 10 on Ubuntu

Install PostgreSQL 10 on Ubuntu

This is a quick guide to install PostgreSQL 10 - tested on Ubuntu 16.04 but likely can be used for Ubuntu 14.04 and 17.04 as well, with one minor modification detailed below.

(Optional) Uninstall other versions of postgres

To make life simple, remove all other versions of Postgres. Obviously not required, but again, makes life simple.

dpkg -l | grep postgres
@iAnanich
iAnanich / async_scraper.py
Created July 23, 2018 22:04 — forked from carlosmcevilly/async_scraper.py
asyncio scraper
import asyncio
import aiofiles
import aiohttp
import logging
import re
import sys
import os
import lxml.html
@iAnanich
iAnanich / common.py
Last active April 27, 2018 13:02
Scrapy httpbin.org/anything spider for benchmarking purposes
# put it with settings.py and spiders folder
from urllib.parse import urlparse, urlencode, urlunparse
def update_query(url: str, query_dict: dict) -> str:
QUERY_INDEX = 4
components = urlparse(url)
query = components[QUERY_INDEX]