Skip to content

Instantly share code, notes, and snippets.

View FZambia's full-sized avatar

Alexander Emelin FZambia

View GitHub Profile
@FZambia
FZambia / nested.js
Created November 17, 2012 17:44
jquery nested selects
/**
*
* usage: $('#select-container').nested({url:'/path/to/backend/which/returns/options/'})
*
*/
(function($){
$.fn.extend({
//pass the options variable to the function
nested: function(options) {
//Set the default values
@FZambia
FZambia / profile.py
Created November 17, 2012 17:49
python function profile
import tempfile
import hotshot
import hotshot.stats
def profile(func):
def wrapper(request, *args, **kwargs):
tmpfile = tempfile.NamedTemporaryFile()
prof = hotshot.Profile(tmpfile.name)
result = prof.runcall(func, request, *args, **kwargs)
@FZambia
FZambia / tastypie_template.py
Created December 10, 2012 13:54
Render tastypie data into template (initially for debugging with django-debug-toolbar)
def tastypie_template(template_name="base.html", var_name='data', serialize=True):
"""
Decorator.
Wrap Tastypie Resource class with it to render into template.
Usage:
@tastypie_template()
class UserResource(ModelResource):
...
@FZambia
FZambia / apacheconf.py
Created December 15, 2012 21:21
Parse Apache-like configuration files and strings. This is a modified version of initial parser implementation described here: http://www.poldylicious.de/node/25
# coding: utf-8
#
# This is a modified version of initial parser implementation
# described here: http://www.poldylicious.de/node/25
import re
class ApacheConfig(object):
"""
@FZambia
FZambia / tornado_on_twisted.py
Last active December 10, 2015 08:28
Tornado simple application running on Twisted. Some simple handlers to test using Twisted Deferred, InlineCallbaks, deferToThread, callLater functionality.
#!/usr/bin/env python
#
# Copyright 2009 Facebook
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
@FZambia
FZambia / tornado_persona_auth.py
Created February 5, 2013 19:56
tornado Persona auth handler
class PersonaAuthHandler(BaseHandler):
@tornado.web.asynchronous
def post(self):
assertion = self.get_argument('assertion')
http_client = tornado.httpclient.AsyncHTTPClient()
domain = 'localhost' # MAKE SURE YOU CHANGE THIS
url = 'https://browserid.org/verify'
data = {
'assertion': assertion,
@FZambia
FZambia / error_handling.cpp
Last active December 13, 2015 22:58
C Python Division gcc error_handling.cpp -I /usr/include/python2.7/ -lpython2.7 -lstdc++ -o error_handling ./error_handling
#include <Python.h>
#include <iostream>
using namespace std;
int main()
{
Py_Initialize();
PyObject* po_operator = PyImport_ImportModule("operator");
PyObject* po_division = PyObject_GetAttrString(po_operator, "div");
@FZambia
FZambia / reload_urlconf.py
Last active September 26, 2021 02:20
reload django urlconf
#python manage.py runserver --noreload
from django.conf.urls import patterns, include, url
from django.conf import settings
from django.http import HttpResponse
import sys
def reload_urls(request, urlconf=None):
if urlconf is None:
urlconf = settings.ROOT_URLCONF
@FZambia
FZambia / procache.py
Last active April 27, 2019 16:06
python in process memory cache based on ordered dictionary - with size limit and timeout support
# coding: utf-8
import time
from collections import OrderedDict
class Cache():
"""
In process memory cache. Not thread safe.
Usage:
@FZambia
FZambia / rsyslog.conf
Last active September 29, 2017 01:50
Configuring django to work with rsyslog
# rsyslog v5 configuration file
#### MODULES ####
$ModLoad imuxsock # provides support for local system logging (e.g. via logger command)
$ModLoad imklog # provides kernel logging support (previously done by rklogd)
#$ModLoad immark # provides --MARK-- message capability
# Provides UDP syslog reception
$ModLoad imudp