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
""" | |
python to_base64.py some_file | |
""" | |
import sys | |
import os | |
def main(path): | |
with open(path) as f: | |
sys.stdout.write(f.read().encode('base64').replace('\n', '')) |
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
<script type="text/javascript"> | |
$(function() { | |
var API_KEY = '2132d453ab3cc055308fb40c708ea412'; | |
$(".set").each(function() { | |
var set_id = $(this).find('a.flickr-set').attr('rel'); | |
url = 'http://api.flickr.com/services/rest/?method=flickr.photosets.getPhotos&api_key=' + API_KEY + '&per_page=48&page=1&format=json&jsoncallback=?&photoset_id=' + set_id; | |
var selector = $(this); | |
data = $.getJSON(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
def db_default(field, db_default): | |
""" | |
Set attribute __db_default for signal to set default values with. | |
""" | |
if db_default == '': | |
db_default = "''" | |
field.__db_default = db_default | |
return field | |
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
def generate_default_sql(app, created_models, verbosity, **kwargs): | |
""" | |
Generate default SQL | |
""" | |
db_fields = filter(lambda x: hasattr(x, 'db_default'), OrderShipLog._meta.fields) | |
modelname = OrderShipLog._meta.object_name | |
sql_dir = os.path.join(os.path.dirname(__file__), '../sql/') | |
sql_filename = os.path.join(sql_dir, '{modelname}.postgresql_psycopg2.sql'.format( | |
modelname=modelname.lower())) |
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 django.core.urlresolvers import reverse, reverse_lazy, NoReverseMatch | |
# from django.utils.functional import lazy | |
# CONTEXT_INJECTOR_REVERSE_DEBUG = getattr(settings, 'CONTEXT_INJECTOR_REVERSE_DEBUG', False) | |
class TemplateContextInjectorMiddleware(object): | |
lazy_url_func_pairs = [] |
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
""" | |
Capture contents of block into context | |
-------------------------------------- | |
Use case: variable accessing based on current variable values. | |
{% capture foo %}{{ foo.value }}-suffix{% endcapture %} | |
{% if foo in bar %}{% endif %} | |
Created on Monday, February 2012 by Yuji Tomita |
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
""" | |
Resolve lookup based on variable value | |
-------------------------------------- | |
{% resolve foovar foodict %} # does django's Variable(foovar).resolve(foodict) | |
Created on Monday, February 2012 by Yuji Tomita | |
""" | |
from django import template | |
from django.template.base import Variable, VariableDoesNotExist |
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
""" | |
Sorl Thumbnail Engine that accepts background color | |
--------------------------------------------------- | |
Created on Sunday, February 2012 by Yuji Tomita | |
""" | |
from PIL import Image, ImageColor | |
from sorl.thumbnail.engines.pil_engine import Engine | |
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
""" | |
Sorl Thumbnail Engine that accepts background color | |
--------------------------------------------------- | |
Created on Sunday, February 2012 by Yuji Tomita | |
""" | |
from PIL import Image, ImageColor | |
from sorl.thumbnail.engines.pil_engine import Engine | |
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
/* | |
Stick element to top | |
Version 0.01 | |
Usage: | |
$("#product_preview_container").stickyElement({ // apply to element to stick. | |
stopPoint: $("#products_see_more"), // integer or jquery element to stop fading at | |
stopPointOffset: 100, // offset the stop point |