Skip to content

Instantly share code, notes, and snippets.

View hatarist's full-sized avatar

Igor Hatarist hatarist

View GitHub Profile
@hatarist
hatarist / .zshrc
Last active December 31, 2015 17:39
(zsh) Colorize iTerm2 prompt when connecting to SSH servers
alias sww="iterm_bg_color 30 0 0; ssh web-production; iterm_bg_color 0 0 0"
alias swt="iterm_bg_color 0 20 20; ssh web-test; iterm_bg_color 0 0 0"
function iterm_bg_color() {
local tty=$(tty)
osascript -e "
tell application \"iTerm\"
repeat with theTerminal in terminals
tell theTerminal
try
@hatarist
hatarist / json_login_required_mixin.py
Last active August 29, 2015 14:25
Django: JSONLoginRequiredMixin
from django.core.exceptions import PermissionDenied
from django.utils.translation import ugettext as _
from django.views.generic import TemplateView
from braces.views import JSONResponseMixin, LoginRequiredMixin
class JSONLoginRequiredMixin(LoginRequiredMixin, JSONResponseMixin):
"""
@hatarist
hatarist / ensure_csrf_cookie_mixin.py
Created July 16, 2015 15:37
EnsureCsrfCookieMixin for Django's Class-Based Views
@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 / 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 *
* *
* / \ \ / \ *
*| | \ | | *
// ==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() {
{# 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 / 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 / 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()