This file contains 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 geopy import units, distance | |
from mezzanine.core.managers import CurrentSiteManager | |
class GeoManager(CurrentSiteManager): | |
def near(self, latitude=None, longitude=None, distance_range=30): | |
queryset = super(GeoManager, self).get_query_set() | |
if not (latitude and longitude and distance_range): | |
return queryset.none() |
This file contains 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 render_to_response(self, context, **response_kwargs): | |
from django.conf import settings | |
STATIC_URL = settings.STATIC_URL | |
if 'http' not in STATIC_URL: | |
# wkhtmltopdf requires full uri to load css | |
from urlparse import urlparse | |
parsed = urlparse(self.request.META.get('HTTP_REFERER')) | |
parsed = '{uri.scheme}://{uri.netloc}'.format(uri=parsed) | |
context["STATIC_URL"] = "{}{}".format(parsed, settings.STATIC_URL) |
This file contains 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
/* sans-serif */ | |
font-family: Arial, "Helvetica Neue", Helvetica, sans-serif; | |
font-family: Helvetica, "Helvetica Neue", Arial, sans-serif; | |
font-family: Verdana, Geneva, Tahoma, sans-serif; | |
font-family: Trebuchet, Tahoma, Arial, sans-serif; | |
font-family: GillSans, Calibri, Trebuchet, sans-serif; | |
font-family: "DejaVu Sans", "Bitstream Vera Sans", "Segoe UI", "Lucida Grande", Verdana, Tahoma, Arial, sans-serif; | |
font-family: Geneva, "Lucida Sans", "Lucida Grande", "Lucida Sans Unicode", Verdana, sans-serif; | |
font-family: Geneva, Verdana, "Lucida Sans", "Lucida Grande", "Lucida Sans Unicode", sans-serif; | |
font-family: "HelveticaNeue-Roman", "Helvetica 55 Roman", Helvetica, Arial, sans-serif; |
This file contains 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
import urllib2 | |
def urlencode(s): | |
return urllib2.quote(s) | |
def urldecode(s): | |
return urllib2.unquote(s).decode('utf8') |
This file contains 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
image_url = og.get('image') | |
if image_url: | |
import urllib2 | |
from django.core.files import File | |
from django.core.files.temp import NamedTemporaryFile | |
img_temp = NamedTemporaryFile(delete=False) | |
img_temp.write(urllib2.urlopen(image_url).read()) | |
img_temp.flush() | |
import os |
This file contains 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
import array | |
def ilist_to_str(list): | |
'''Integer list to string.''' | |
return array.array('B', list).tostring() | |
def str_to_ilist(string): | |
'''String to integer list''' | |
return array.array('b', string).tolist() |
This file contains 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
# http://stackoverflow.com/questions/431628/how-to-combine-2-or-more-querysets-in-a-django-view | |
from itertools import chain | |
from operator import attrgetter | |
def join_list(*args, sort_key=None): | |
if sort_key: | |
return sorted(chain(args), key=attrgetter(sort_key)) | |
return list(chain(args)) |
This file contains 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
find . -name "*.html" -print0 | xargs -0 sed -i "" 's/ url \([^" >][^ >]*\)/ url "\1"/g' |
This file contains 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
#!/usr/bin/env pypy | |
import time | |
n = 13 | |
# n = 1000000 | |
if __name__ == "__main__": |
This file contains 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
<!-- new_base.html --> | |
<header> | |
{% block header %} | |
{% endblock %} | |
</header> | |
<main id="content" class="group" role="main"> | |
{% block main %} | |
<div id="main-container" class="main-container container"> |
NewerOlder