This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source "http://rubygems.org" | |
gem "jammit" | |
gem "closure-compiler" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |