Skip to content

Instantly share code, notes, and snippets.

View hatarist's full-sized avatar

Igor Hatarist hatarist

View GitHub Profile
from telegram import TelegramApi
from flask import Flask, request, jsonify
import settings
tg = TelegramApi(settings.API_TOKEN)
app = Flask(__name__)
tg.set_webhook(url=settings.BASE_URL + settings.WEBHOOK_URL)
#!/usr/bin/env python3
import asyncio
import aiohttp
import ujson
async def get(semaphore, session, url):
async with semaphore as sem:
return await session.get(url)
@hatarist
hatarist / pg_get_table_sizes.sql
Created September 8, 2017 15:48
PostgreSQL: get table size (data & index & toast)
SELECT
*,
pg_size_pretty(table_bytes) AS table,
pg_size_pretty(index_bytes) AS index,
pg_size_pretty(total_bytes) AS total
FROM (
SELECT
*, total_bytes - index_bytes - COALESCE(toast_bytes, 0) AS table_bytes
FROM (
SELECT

Copy this URL and paste it into the address bar to import it in the Karabiner Elements:

karabiner://karabiner/assets/complex_modifications/import?url=https://gist.githubusercontent.com/hatarist/f2888c1940e7ebccfeea184181c7726b/raw/karabiner-fn-to-ctrl.json)
:) CREATE TABLE my_table (date Date DEFAULT today(), s String) ENGINE = MergeTree(date, (date), 8192);
:) INSERT INTO my_table (s) VALUES ('1. foo');
:) ALTER TABLE my_table ADD COLUMN f Float64;
:) INSERT INTO my_table (s) VALUES ('2. bar');
:) SELECT * FROM my_table;
@hatarist
hatarist / ipv6gen.py
Created May 2, 2018 13:11
I'm a lazy ass who didn't think it's worth to bother with the standard ipaddress library
import random
import sys
from netaddr import IPNetwork, IPAddress
def generate_random_ipv6(subnet):
network = IPNetwork(subnet)
return str(IPAddress(random.randrange(network.first, network.last)))
#!/bin/bash
export threads=10
export src="/home/local/stuff/"
export dest="scp@govno:/home/remote/stuff/"
rsync -aL -f"+ */" -f"- *" $src $dest && (cd $src && find . -type f | xargs -n1 -P$threads -I% rsync -av % $dest/% )
@hatarist
hatarist / clean_json.py
Last active August 9, 2018 21:09
this 100% mature and tested function strips C-style comments and trailing commas from a (not-so-valid) JSON
import re
def clean_json(payload):
# remove C-style comments
payload = re.sub(re.compile("/\*.*?\*/",re.DOTALL), '', payload)
payload = re.sub(re.compile("//.*?\n" ), '', payload)
# remove trailing commas
payload = re.sub(re.compile(r',\s*?([\]\}])'), r'\1', payload)
return payload
@hatarist
hatarist / pppretty.py
Last active June 9, 2019 22:53
Formats a list of dictionaries as a fancy psqlish-style table.
def ppprint(data, fields=None, precision=2):
"""
P-P-PRETTY PRINTER!
>>> ppprint([{"foo": 1.2, "bar": "beer"}, {"foo": "bazzzzz", "bar": "bad"}])
"""
if fields is None:
fields = list(data[0].keys())
formatted_fields = []
@hatarist
hatarist / karabiner-fn-to-ctrl.json
Last active October 23, 2021 00:03
Karabiner Elements: Convenient `fn` to `ctrl` replacement.
{
"title": "Fn improvements (gist.github.com/hatarist)",
"rules": [
{
"description": "Change Fn+key to Ctrl+key",
"manipulators": [
{
"from": {
"key_code": "spacebar",
"modifiers": {