Skip to content

Instantly share code, notes, and snippets.

@yuchant
yuchant / django_db_defaults.py
Created June 7, 2012 04:59
Django: set database level defaults with postgresql_psycopg2 from the model file.
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
<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,
@yuchant
yuchant / to_base64.py
Created December 8, 2012 00:59
Convert file to base64. Using for fonts > b64 string.
"""
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', ''))
@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):
@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 / 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
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
module.exports = (grunt) ->
srcBase = "v2/frontend"
grunt.initConfig
# config:
paths:
phpBase: "public_html"
src: "public_html/v2/frontend"
$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;
}
}