Skip to content

Instantly share code, notes, and snippets.

View pije76's full-sized avatar

panjianom pije76

View GitHub Profile
class CachedCountCloneProxy(object):
''' This allows us to monkey-patch count() on QuerySets so we can cache it and speed things up.
._clone is called so we have to monkey-patch that first...
'''
def __init__(self, queryset):
self._queryset = queryset
self._queryset._clone_original = self._queryset._clone
def __call__(self):
#!/bin/sh
# Converts a mysqldump file into a Sqlite 3 compatible file. It also extracts the MySQL `KEY xxxxx` from the
# CREATE block and create them in separate commands _after_ all the INSERTs.
# Awk is choosen because it's fast and portable. You can use gawk, original awk or even the lightning fast mawk.
# The mysqldump file is traversed only once.
# Usage: $ ./mysql2sqlite mysqldump-opts db-name | sqlite3 database.sqlite
# Example: $ ./mysql2sqlite --no-data -u root -pMySecretPassWord myDbase | sqlite3 database.sqlite
/**
* Builds a horizontal masonry in whats possbily (i haven't researched
* the techniques) a crude manner.
* Fits elements into columns if there is room and sets the width of
* the container element to contain all the columns.
*
* Known Issues:
* - Does not do anything clever for elements where height exceeds
* window height (probably just gets chopped off if overflow: hidden)
* - All elements are expected to be the column width
#views.py
def events_index(request, year):
selected_year = Year.objects.get(title=year)
events_list = Event.objects.filter(year = selected_year.id).order_by('category','start_date')
return render_to_response('events_list.html', {"events_list": events_list})
#events_list.html
{% regroup events_list by category.title as events_list_by_category %}
@pije76
pije76 / Gemfile
Created May 23, 2013 15:20 — forked from pilt/Gemfile
source "http://rubygems.org"
gem "jammit"
gem "closure-compiler"
from cStringIO import StringIO
@register.simple_tag
def thumbnail(image_url, width, height, quality=95):
"""
Given the URL to an image, resizes the image using the given width and
height on the first time it is requested, and returns the URL to the new
resized image. if width or height are zero then original ratio is
maintained.
"""
if not image_url:
@pije76
pije76 / admin.py
Created February 19, 2013 03:09 — forked from uhop/admin.py
# Example how to add rich editor capabilities to your models in admin.
from django.contrib.admin import site, ModelAdmin
import models
# we define our resources to add to admin pages
class CommonMedia:
js = (
'https://ajax.googleapis.com/ajax/libs/dojo/1.6.0/dojo/dojo.xd.js',
@pije76
pije76 / scrapy.py
Created February 17, 2013 13:13 — forked from samliu/scrapy.py
# Enable us to call scrapy from manage.py
from __future__ import absolute_import
from django.core.management.base import BaseCommand
class Command(BaseCommand):
def run_from_argv(self, argv):
self._argv = argv
self.execute()
data:text/html, <style type="text/css">.e{position:absolute;top:0;right:0;bottom:0;left:0;}</style><div class="e" id="editor"></div><script src="http://d1n0x3qji82z53.cloudfront.net/src-min-noconflict/ace.js" type="text/javascript" charset="utf-8"></script><script>var e=ace.edit("editor");e.setTheme("ace/theme/monokai");e.getSession().setMode("ace/mode/ruby");</script>
<!--
For other language: Instead of `ace/mode/ruby`, Use
Python -> `ace/mode/python`
C/C++ -> `ace/mode/c_cpp`
Javscript -> `ace/mode/javascript`
Java -> `ace/mode/java`
from socialregistration.signals import connect as profile_connect
PERMISSIONS = {
'profile': ('view_profile', 'change_profile'),
'user': ('change_user', 'delete_user')
}
def social_connect_callback(sender, user, profile, client, **kwargs):
"""
Create a profile for this user after connecting