Skip to content

Instantly share code, notes, and snippets.

View un1t's full-sized avatar

Ilya Shalyapin un1t

View GitHub Profile
package main
import (
"fmt"
"os"
"flag"
"encoding/xml"
)
type Offer struct {
@un1t
un1t / sanitizer.py
Created January 30, 2015 11:22
html sanitizer
# -*- coding: utf-8 -*-
import re
from html5lib import HTMLParser
from html5lib.tokenizer import HTMLTokenizer
from html5lib.sanitizer import HTMLSanitizerMixin
class WysiwygSanitizerMixin(HTMLSanitizerMixin):
allowed_elements = ['b','i','strong', 'em', 'strike', 'a']
@un1t
un1t / one-file-django
Created February 10, 2015 20:22
How to run Django in one file
#!/usr/bin/env python
import os
import sys
from django.conf import settings
from django.conf.urls import patterns, include, url
from django.http import HttpResponse
filename = os.path.splitext(os.path.basename(__file__))[0]
urlpatterns = patterns('',
#!/bin/bash
virtualenv_auto_activate() {
GITPATH=`git rev-parse --show-toplevel 2>/dev/null`
if [[ "$GITPATH" != "" ]]
then
if [[ "$VIRTUAL_ENV" == "" ]]
then
[ -f $GITPATH"/python/bin/activate" ] && source $GITPATH"/python/bin/activate"
@un1t
un1t / .vimrc
Created February 24, 2015 07:50
set list
set expandtab
retab 4
set shiftwidth=4
set tabstop=4
syntax on
set nu
set ai
@un1t
un1t / pathspec
Created March 10, 2015 18:31
pathspec match_files example
pathspec.match_files(map(pathspec.GitIgnorePattern, ["*.css", "!*.ie.css"]), ["styles.css", "styles.ie.css", ".tmp"])
import readline
texts = ['hello', 'world', 'readline']
def completer(text, state):
options = [x for x in texts if x.startswith(text)]
try:
return options[state]
except IndexError:
return None
from decorator import decorator
from line_profiler import LineProfiler
@decorator
def profile_each_line(func, *args, **kwargs):
profiler = LineProfiler()
profiled_func = profiler(func)
try:
return profiled_func(*args, **kwargs)
finally:
@un1t
un1t / vagrant-boxes
Created April 27, 2015 14:05
Suspend Vagrant boxes before shutdown on Ubuntu
#!/bin/sh
# save it to "/etc/init.d/vagrant-boxes"
# sudo update-rc.d vagrant-boxes defaults 99 01
RETVAL=0
USER='ilya'
stop() {
LIST=`sudo -u $USER vagrant global-status | grep running | awk '{print $1}'`
for i in `echo $LIST`; do
@un1t
un1t / checksock.py
Created December 11, 2015 11:02
python check unix socket
from __future__ import print_function
import socket, sys
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
addr,path = sys.argv[1].split(":")
sock.connect(addr)
sock.send("""GET {} HTTP/1.1
host: test.ru