Skip to content

Instantly share code, notes, and snippets.

View hatarist's full-sized avatar

Igor Hatarist hatarist

View GitHub Profile
#!/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)
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)
@hatarist
hatarist / fucking_sanic.py
Last active September 8, 2017 15:36
A quick Sanic workaround that doesn't complain about weird HTTP 408 errors that lead to the blank access.log entries
from sanic.exceptions import RequestTimeout
from sanic.server import HttpProtocol
class NoTimeoutHttpProtocol(HttpProtocol):
"""
Doesn't complain about request timeouts to the logger.
Usage:
app = Sanic()
@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);

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

❯ 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')

{# 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")
// ==UserScript==
// @name Slack: Full Name (@username)
// @namespace http://hatari.st/
// @version 0.1
// @description nuff said
// @author igor@hatari.st
// @match https://*.slack.com/messages/*
// ==/UserScript==
(function() {
@hatarist
hatarist / goatse.go
Created February 27, 2016 20:06
(18+, censored) Goatse: A perfect «hello.jpg world» on Go.
package main
import "fmt"
func main() {
hellotxt := `
* * * * * * * * * * * * * * * * * * * * * * * * *
* goatse / hello.jpg world *
* *
* / \ \ / \ *
*| | \ | | *
@hatarist
hatarist / config.fish
Created September 24, 2015 08:43
fish + iterm2 shell integration + scp/rsync = <3
# ~/.config/fish/config.fish:
# Shell integration breaks utilites like scp or rsync because of the excessive output.
# We will load it only if the shell is actually interactive.
if status --is-interactive
. $HOME/.iterm2_shell_integration.fish
end
@hatarist
hatarist / ensure_csrf_cookie_mixin.py
Created July 16, 2015 15:37
EnsureCsrfCookieMixin for Django's Class-Based Views