Skip to content

Instantly share code, notes, and snippets.

View hatarist's full-sized avatar

Igor Hatarist hatarist

View GitHub Profile
@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
@hatarist
hatarist / clickhouse_join_date_range.sql
Last active March 11, 2024 17:42
Clickhouse JOIN date ranges
:) CREATE TABLE ranges (id UInt64, date_start Date, date_end Date) ENGINE = TinyLog;
:) INSERT INTO ranges SELECT rowNumberInAllBlocks() AS id, least(dates[1], dates[2]) AS date_start, greatest(dates[1], dates[2]) AS date_end FROM (SELECT arrayJoin(arrayMap(d -> [today() - d - rand64(d) % 10, yesterday() - d - rand(d) % 10], range(10))) AS dates);
:) CREATE TABLE dates (id UInt64, date Date) ENGINE = TinyLog;
:) INSERT INTO dates SELECT rowNumberInAllBlocks() AS id, date FROM (SELECT arrayJoin(arrayMap(d -> today() - rand64(d) % 10, range(10))) AS date);
@hatarist
hatarist / yandex-music_full-width_no-bloat.css
Created September 30, 2023 13:55
userstyle: yandex music (full-width, no bloat)
/* моя волна */
.rup__animation { display: none; } /* дебильная анимация моей волны */
.rup { display: none; } /* хотя нет, вся "моя волна" дебильная */
/* делаем поменьше отступы основной части интерфейса */
.centerblock {
padding: 10px 30px 60px;
}
.d-header__title {
@hatarist
hatarist / README.md
Created June 30, 2023 16:45
Python RGB to color name

RGB to color name converter using Python

Dependencies

Oops, I was too lazy to implement the RGB to HSL conversion myself, hence you need the colormath.

Usage example

get_color_name((241, 95, 188)) # 'pink'
{# include this template right at the beginning of the <body> tag in your base.html #}
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
{# +- title, login_required, urls #}
{# +-- url, login_required, title #}
{% set elements = [
("Index", True, [
(url_for('webui.index'), True, "Index")

создаем таблицу

❯ curl -d "" "http://127.0.0.1:8123/?query=CREATE+TABLE+test+(x+UInt32,+y+String,+z+String)+ENGINE+=+TinyLog;"

смотрим формат входящих данных для VALUES

❯ cat example.values
(1, 'foo', 'bar'),
(2, 'foo', 'baz'),

(3, 'fxx', 'bxx')

@hatarist
hatarist / ensure_csrf_cookie_mixin.py
Created July 16, 2015 15:37
EnsureCsrfCookieMixin for Django's Class-Based Views
@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": {

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)
@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 = []