Skip to content

Instantly share code, notes, and snippets.

View wyattdanger's full-sized avatar

Stephen Bush wyattdanger

View GitHub Profile
var compiled = _.template("hello: <%= name %>");
compiled({name : 'moe'});
=> "hello: moe"
var list = "<% _.each(people, function(name) { %> <li><%= name %></li> <% }); %>";
_.template(list, {people : ['moe', 'curly', 'larry']});
=> "<li>moe</li><li>curly</li><li>larry</li>"
var locations = [[37,-122],[38,-121],[39,-120]], // An array of arrays of [ lat , lng ]. You'll find the closest to target
target = [37.75,-121], // starting point
radians = function (deg) {
return Math.PI*deg/180; // needed function not native to JavaScript's Math object
};
function getDistances (target, locations) {
var spots = [];
for (var i=0;i<locations.length;i++) {
var distance = 0,
# Place in models.py
class ExternalLink(db.Item):
title = db.NameProperty()
href = db.LinkProperty(verbose_name='Link')
@site.item_view.define(ExternalLink)
def link_view(item, request):
return http.HttpResponseRedirect(item.href)
from re import sub
from django import template
register = template.Library()
@register.filter(name='cleanhtml')
def cleanhtml(value):
"""Removes all attributes from all HTML tags, but keeps <img> tags intact.
Ideal for cleaning WYSIWYG-generated mess."""
return sub('(<\w+(\ssrc=[\'"][\w:/\.-]+[\'"])?)[^>(/>)]*(>)', r'\1\2', str(value))
from re import sub
from django import template
register = template.Library()
@register.filter(name='cleanhtml')
def cleanhtml(value):
'''Removes inline styles from WYSIWYG-generated markup.'''
return sub('(\s?style\s?=\s?[\'\"].+[\'\"])', '', str(value))
.clearfix {
line-height: 1px;
height: 1px;
width: auto;
clear: both; }
def main():
import csv, sys, re
from pykk.message import site, db
from yourapp.apps.models import YourModel # import your relevant models
db.initialize()
reader = csv.DictReader(open(sys.argv[1]))
with db.transaction('Importing Employees'):
for row in reader:
/* grids */
@media screen and (max-width: 319px) {.unit { float: none !important; width: auto !important;}
}
.line:after,.lastUnit:after { clear: both; display: block; visibility: hidden; overflow: hidden; height: 0 !important; line-height: 0; font-size: xx-large; content: " x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x x ";}
.line {*zoom:1;}
.unit { float: left;}
.size1of1 { float: none;}
.size1of2 { width: 50%;}
.size1of3 { width: 33.33333%;}
.size2of3 { width: 66.66666%;}
@wyattdanger
wyattdanger / base.sh
Created December 13, 2010 16:41 — forked from jamessanders/base.sh
# change directory to the base of your project
# Your project base is the directory that contains
# either _darcs or .git or .hg
# to use as a command add to .zshrc or .bashrc
# alias base='source <path/to/base.sh>
CUR=$(pwd);
while [ ! "$CUR" = "/" ]
# Print the string "Hello, World"
puts "Hello, World"
# Find index of "Ruby" in "Hello, Ruby"
"Hello, Ruby".index "Ruby"
# Print your name ten time
10.times { puts "Stephen" }
# This is equivalent to the above one-liner