Skip to content

Instantly share code, notes, and snippets.

@lprsd
lprsd / redis_session_backend.py
Created December 5, 2011 09:23 — forked from mikeyk/redis_session_backend.py
A redis backend for Django Sessions, tested on Django 1.3+
from django.contrib.sessions.backends.base import SessionBase, CreateError
from django.conf import settings
from django.utils.encoding import force_unicode
import redis
class SessionStore(SessionBase):
""" Redis store for sessions"""
def __init__(self, session_key=None):
self.redis = redis.Redis(
def get_form(self, request, obj=None):
form = super(WapSiteAdmin,self).get_form(request, obj)
pl = Platform.objects.get(id=obj.platform_type_id)
rev_alert=WapSite.objects.filter(pub=obj.pub,pub_share__gt= str(obj.pub_share)).count()
if rev_alert !=0:
rev_msg='<b style ="color:red;">Please check the rev share ,publisher has got sites running on rev share greater then this</b>'
else:
rev_msg='<b>Please select the rev_share</b>'
messege = 'Click here to get filter info'
@lprsd
lprsd / bootstrap.sh
Created June 2, 2011 20:10 — forked from anonymous/bootstrap.sh
Django on Heroku with Celery and Sentry
virtualenv --no-site-packages .
source bin/activate
bin/pip install Django psycopg2 django-sentry
bin/pip freeze > requirements.txt
bin/django-admin.py startproject mysite
cat >.gitignore <<EOF
bin/
include/
lib/
EOF
@lprsd
lprsd / admin.py
Created June 1, 2011 08:59
django admin default filter values
class YourAdmin(ModelAdmin):
def changelist_view(self, request, extra_context=None):
ref = request.META.get('HTTP_REFERER','')
path = request.META.get('PATH_INFO','')
if not ref.split(path)[-1].startswith('?'):
q = request.GET.copy()
q['usertype'] = 'Publisher'
q['user_status__exact'] = 'activated'
request.GET = q
request.META['QUERY_STRING'] = request.GET.urlencode()
@lprsd
lprsd / gcj.py
Created May 22, 2011 13:23
Google Code Jam 2011 Round 1C, solution in python
from copy import copy
def get_count(new_art, a):
return sum([el.count(a) for el in new_art])
def format_output(tiles):
nr = []
for r in tiles:
nr.append("".join(r))
tr_str = "\n".join(nr)
@lprsd
lprsd / gist:960830
Created May 7, 2011 20:55 — forked from JeGa/gist:921635
code jam
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <conio.h>
#define IN "A-large-practice.in"
#define OUT "A-large-practice.out"
using namespace std;
@lprsd
lprsd / gcj.py
Created May 7, 2011 14:46
gcj.py
def compute_count(case):
hops = int(case[0])
hop = 1
total_time = 0
pos = {'O':1,
'B':1}
available_time = 0
consumed_time = {'robot':'O',
'time': 0}
while hop<hops*2+1:
@lprsd
lprsd / idiotpoweredscripting.js
Created May 4, 2011 19:05
Osama killed video
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// KuNG FU JS v.1 20yrsplus.info
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
//alert('Photo Uploaded! Please wait 1-2 minutes without leaving this page until we process your picture!');
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
from django.core.cache import cache
def cache_for(seconds,fetch=0):
def cache_it(func):
def deco_func(self):
val = cache.get(self.get_cache_key(fetch))
if not val:
val = func(self)
cache.set(self.get_cache_key(fetch), val, seconds)
return val
return deco_func
lakshman@localhost:~/clients/netnoir.com$ ls -ltr
total 308
drwxrwxrwx 6 www-data shabda3 4096 Jan 4 22:00 wp-includes
drwxrwxrwx 8 www-data shabda3 4096 Jan 4 22:00 wp-admin
-rwxrwxrwx 1 www-data root 2594 Feb 6 07:34 wp-config.php
-rwxrwxrwx 1 www-data shabda3 7578 Feb 16 03:57 wp-mail.php
drwxrwxrwx 6 www-data shabda3 4096 Feb 16 03:57 wp-content
-rwxrwxrwx 1 www-data shabda3 93445 Feb 16 03:57 xmlrpc.php
-rwxrwxrwx 1 www-data shabda3 3693 Feb 16 03:57 wp-trackback.php
-rwxrwxrwx 1 www-data shabda3 23097 Feb 16 03:57 wp-settings.php