Skip to content

Instantly share code, notes, and snippets.

@renyi
renyi / django-wkhtmltopdf-static-url-hack.py
Created May 21, 2016 10:38
django-wkhtmltopdf STATIC_URL hack to make static files work on both local and remote hosting.
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)
#!/usr/bin/env pypy
import time
n = 13
# n = 1000000
if __name__ == "__main__":
@renyi
renyi / epiweek.py
Last active August 29, 2015 14:27 — forked from kagesenshi/epiweek.py
Epidemic Week Calculator
from datetime import date
from datetime import timedelta
import copy
# ported from npmjs epi-week package
# https://github.com/wombleton/epi-week
#
#getFirstWeek = (year) ->
# end = new Date(year, 0, 1)
<!-- 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">
@renyi
renyi / gist:7300109
Created November 4, 2013 09:21
Replaces {% url something %} with {% url "something" %}
find . -name "*.html" -print0 | xargs -0 sed -i "" 's/ url \([^" >][^ >]*\)/ url "\1"/g'
@renyi
renyi / 0_reuse_code.js
Created October 26, 2013 11:24
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@renyi
renyi / start_postgres.sh
Created October 23, 2013 10:46
OS X postgres script
#!/bin/sh
pg_ctl -D /usr/local/var/postgres start
@renyi
renyi / gist:7019854
Created October 17, 2013 06:16
Django, download and store image in ImageField
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
@renyi
renyi / gist:6971520
Last active December 25, 2015 11:49
{% for p in period_list %}
{# or Try regroup p.subject_periods.subject #}
{% for sp in p.subject_periods.all %}
{# or Try regroup sp.subject #}
@renyi
renyi / dev_settings.py
Last active December 19, 2015 17:48
settings boilerplate.
DEBUG = True
TEMPLATE_DEBUG = True
COMPRESS_ENABLED = False
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": "dev.db",
}
}