Skip to content

Instantly share code, notes, and snippets.

@yuchant
yuchant / gist:9108622
Created February 20, 2014 07:32
very simple git revision based cache buster
# very simple git revision based cache buster
app = make_app()
def get_git_revision_hash():
'''
Get current revision short hash and use as cache buster key.
'''
import subprocess
return subprocess.check_output(['git', 'rev-parse', '--short', 'HEAD'])
@yuchant
yuchant / generational_cache.py
Created February 12, 2014 08:45
Generational Caching
import logging
import pylibmc
from werkzeug.contrib.cache import MemcachedCache
from flask import request
from flask.ext.cache import Cache
log = logging.getLogger(__name__)
@yuchant
yuchant / viewport.coffee
Created January 25, 2014 02:33
Viewport Units with Coffee
class root.utils.ViewportHeight
'The VH unit is not well supported. Use data-tags instead.
data-viewport-unit="line-height: 100vh; height: 100vh;'
constructor: ({@element, @styles}={}) ->
@$element = $ @element
@$window = $ window
@_bindHandlers()
_getStyles: ->
$grid_columns: 12;
@mixin responsive-gutters {
padding-right: $touch-gutter/2;
padding-left: $touch-gutter/2;
@include breakpoint($bp-desktop) {
padding-right: $desktop-gutter/2;
padding-left: $desktop-gutter/2;
}
}
$grid_columns: 12;
@mixin responsive-gutters {
padding-right: $touch-gutter/2;
padding-left: $touch-gutter/2;
@include breakpoint($bp-desktop) {
padding-right: $desktop-gutter/2;
padding-left: $desktop-gutter/2;
}
}
module.exports = (grunt) ->
srcBase = "v2/frontend"
grunt.initConfig
# config:
paths:
phpBase: "public_html"
src: "public_html/v2/frontend"
def send_html_mail(subject, message, message_html, from_email, recipient_list,
priority="medium", fail_silently=False, auth_user=None,
auth_password=None, account=0, attachments=None, headers=None):
"""
Ripped out of mailer.. does not accept headers.
"""
from django.utils.encoding import force_unicode
from django.core.mail import EmailMultiAlternatives
@yuchant
yuchant / nodejs_ubuntu.txt
Created September 12, 2013 01:11
Node, bower, etc on ubuntu install
sudo apt-get update
sudo apt-get install python-software-properties python g++ make
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs
npm -g install bower
@yuchant
yuchant / get_template_source.py
Last active December 18, 2015 12:08
Django Get Template Source
'''
Django doesn't ship with a way to use the template loading framework to output raw source.
It's kinda important since we use the framework to walk the template dirs
'''
import inspect
from django.conf import settings
from django.template.loader import find_template_loader
from django.template import TemplateDoesNotExist
@yuchant
yuchant / gist:5148674
Created March 13, 2013 01:28
Django ModelForm Mixin to prevent overwriting of data if the form does not contain the POST keys
from django.forms.models import model_to_dict
from django import forms
class OverwriteOnlyModelFormMixin(object):
'''
Delete POST keys that were not actually found in the POST dict
to prevent accidental overwriting of fields due to missing POST data.
'''
def clean(self):