Skip to content

Instantly share code, notes, and snippets.

@becomingGuru
becomingGuru / gcj.py
Created May 22, 2011
Google Code Jam 2011 Round 1C, solution in python
View gcj.py
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)
@becomingGuru
becomingGuru / admin.py
Created Jun 1, 2011
django admin default filter values
View admin.py
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()
@becomingGuru
becomingGuru / bootstrap.sh
Created Jun 2, 2011 — forked from anonymous/bootstrap.sh
Django on Heroku with Celery and Sentry
View bootstrap.sh
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
View admin.py
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'
@becomingGuru
becomingGuru / redis_session_backend.py
Created Dec 5, 2011 — forked from mikeyk/redis_session_backend.py
A redis backend for Django Sessions, tested on Django 1.3+
View redis_session_backend.py
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(
@becomingGuru
becomingGuru / dynamic_test.py
Created Jan 2, 2012
Create Test Cases Dynamically, in Python.
View dynamic_test.py
import unittest2 as unittest
def get_verify_mtd(sum_tuple, sum_value):
def test1(self):
self.assertEqual(sum(sum_tuple),sum_value)
return test1
def create_test_case_class():
sumlist = range(20,30,2)
sum1_list = [20]*5
@becomingGuru
becomingGuru / pyimport.py
Created Jan 9, 2012
How do you dynamically import a method from a module in the syspath, which you have as a string.
View pyimport.py
def get_method_from_file(full_path=['credit', 'syndloan', 'importer', 'sql', 'sql', 'loanDealSql']):
if len(full_path) == 1:
return map(__import__,[full_path[0]])[0]
return getattr(get_method_from_file(full_path[:-1]),full_path[-1])
View id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA0yVPIfiCJWVipZAriF4nWSEvNaWxMK1Ruz7sqz86eT/vp9hvZRWPVNoT4N56JTyZbfYoSGfIhf0N1AUkDzsMTcXezL8WJ67c8Yr+29mFZ36iA7eVHNbeyCH3UGgNRV+Sqhu0i+Q8DKt4F77BMXBxGikE2Z8nLU2lPqZcYrUvjTbx5RuWH1o7/GFt9Tof7jNjsMRwy5FoKaZ+BK6vwm0hTGPuC2bHeQCNABUxmPhZGkGYngSbDxOP3+xdCRTpmmOEChZN3r0UXFC3re1tKoenNldxYPSw5l7z4SlhjY0UTVUFx6txZh/k3O2DQe19Ei3ZxiU6LeLhbbd0L4RK6KU/Pw==
View ph
302 745 2095