Skip to content

Instantly share code, notes, and snippets.

View un1t's full-sized avatar

Ilya Shalyapin un1t

View GitHub Profile
#!/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 / 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('',
@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']
package main
import (
"fmt"
"os"
"flag"
"encoding/xml"
)
type Offer struct {
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: