Skip to content

Instantly share code, notes, and snippets.

View hatarist's full-sized avatar

Igor Hatarist hatarist

View GitHub Profile
@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 / 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 / .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 / 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() {
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 / 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()
:) 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)))