Skip to content

Instantly share code, notes, and snippets.

View maxpoletaev's full-sized avatar

Max Poletaev maxpoletaev

View GitHub Profile
@maxpoletaev
maxpoletaev / middleware.py
Created September 7, 2014 22:35
Compress HTML to one line in Django (python3)
import re
class CompressHtmlMiddleware(object):
def __init__(self):
self.whitespace = re.compile(r'^\s+', re.MULTILINE)
self.linebreak = re.compile(r'\n', re.MULTILINE)
def process_response(self, request, response):
@maxpoletaev
maxpoletaev / metrika-angular.js
Last active September 18, 2019 17:59
Goals directive for Yandex.Metrika
(function() {
var module = angular.module('yaMetrika',
[]
);
module.provider('yaMetrika', function() {
var counter = null;
this.setCounter = function(ycounter) {
@maxpoletaev
maxpoletaev / html_compress.rb
Last active August 29, 2015 14:09
Jekyll HTML compress
module Jekyll
module Compressor
def compress_html(content)
content.gsub(/(?>[^\S ]\s*|\s{2,})(?=(?:(?:[^<]++|<(?!\/?(?:textarea|pre)\b))*+)(?:<(?>textarea|pre)\b|\z))/ix, '')
end
def output_file(dest, content)
FileUtils.mkdir_p(File.dirname(dest))
File.open(dest, 'w') do |f|
@maxpoletaev
maxpoletaev / i18n_filter.rb
Created November 16, 2014 12:15
Jekyll i18n filter
require 'i18n'
# Create folder "_locales" and put some locale file from https://github.com/svenfuchs/rails-i18n/tree/master/rails/locale
module Jekyll
module I18nFilter
# Example:
# {{ post.date | localize: "%d.%m.%Y" }}
# {{ post.date | localize: ":short" }}
def localize(input, format=nil)
load_translations
@maxpoletaev
maxpoletaev / async.py
Last active November 1, 2016 11:54
Async decorator
from threading import Thread
from queue import Queue
tasks = {}
def task_consumer(queue):
while True:
try:
task, args, kwargs = queue.get()
@maxpoletaev
maxpoletaev / month_day_range.py
Created December 1, 2014 15:06
Month day range
import calendar
def month_day_range(date):
first_day = date.replace(day = 1)
last_day = date.replace(day = calendar.monthrange(date.year, date.month)[1])
return first_day, last_day
@maxpoletaev
maxpoletaev / iptables-ssh.sh
Created February 15, 2015 09:08
SSH protection for iptables
#!/bin/bash
# base iptables rules
# run by /etc/rc.local
iptables -F INPUT
iptables -Z INPUT
iptables -P INPUT ACCEPT
iptables -F OUTPUT
@maxpoletaev
maxpoletaev / beautiful-fonts.css
Last active October 19, 2015 18:27
Beautiful font rendering
body {
text-rendering: optimizeLegibility;
font-feature-settings: "kern";
font-kerning: normal;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
@maxpoletaev
maxpoletaev / shipit-django
Created March 25, 2015 13:14
Django Shipit
host='user@host'
path='/home/path_to_project'
[deploy]
hg pull
hg update
LD_LIBRARY_PATH=/usr/local/lib \
python3.4 manage.py migrate
sudo ln -s /lib/x86_64-linux-gnu/libncurses.so.5.9 /lib/libtermcap.so.2