Skip to content

Instantly share code, notes, and snippets.

View FZambia's full-sized avatar

Alexander Emelin FZambia

View GitHub Profile
@FZambia
FZambia / light_model.py
Created March 17, 2013 13:00
when we need methods groupped together
# coding: utf-8
from datetime import datetime
try:
import simplejson as json
except ImportError:
import json
datetime_json_handler = lambda obj: obj.isoformat() if isinstance(obj, datetime) else None
@FZambia
FZambia / bootstrap_prefix_tab.js
Last active December 15, 2015 06:49
Twitter bootstrap tab's jQuery plugin to show hash in location string (custom prefix prevent page jumps to links containing hash), keep current tab on page reload and react on hash change event
/*
Usage:
$(document).ready(function() {
$('#tabs').prefix_tab({
prefix: 'settings_',
default_route: 'general'
});
});
.pill {
margin: 0;
text-align: center;
display: inline-block;
position: relative;
}
.pill.pill-large a {
height: 100px;
line-height: 100px;
@FZambia
FZambia / relation.py
Created March 26, 2013 13:41
django relation between user and object using contenttypes framework
from django.db import models
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes import generic
class RelationManager(models.Manager):
"""
Contains helpful methods for operating with Relation model
"""
@FZambia
FZambia / call_subprocess.py
Last active September 27, 2022 08:16
tornado subprocess call
from __future__ import print_function
from tornado.gen import Task, Return, coroutine
import tornado.process
import subprocess
from tornado.ioloop import IOLoop
STREAM = tornado.process.Subprocess.STREAM
@FZambia
FZambia / tornado_start_stop_daemon
Created April 12, 2013 13:23
start-stop-daemon with tornado example
#!/bin/bash
DAEMON_DIR=/opt/mytornadoapp
DAEMON=$DAEMON_DIR/main.py
NAME=tornado
DESC="tornado daemon"
test -f $DAEMON || exit 0
set -e
@FZambia
FZambia / fieldset_form.py
Created April 16, 2013 07:12
fieldset form for django
from django import forms
from django.forms.forms import BoundField
from django.utils.datastructures import SortedDict
class BoundFieldset(object):
def __init__(self, form, name, title, fields, is_fieldset):
self.form = form
self.name = name
@FZambia
FZambia / httperf_content
Created May 17, 2013 14:41
httperf POST with form data
/path/to/location/ method=POST contents="name=TEST&password=SECRET"
@FZambia
FZambia / jquery_django_ajax_csrf.js
Last active June 25, 2018 22:12
add csrf token on every jQuery POST ajax request
// using jQuery
function getCookie(name) {
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
@FZambia
FZambia / tornado_http_fetch.py
Created May 24, 2013 16:20
fetch several resources simultaniously in Tornado
from __future__ import print_function
import tornado.httpclient
import tornado.ioloop
import tornado.web
import tornado.gen
@tornado.gen.coroutine
def get():
urls = [