This file contains hidden or 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
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>" |
This file contains hidden or 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
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, |
This file contains hidden or 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
# 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) |
This file contains hidden or 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 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)) |
This file contains hidden or 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 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)) |
This file contains hidden or 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
.clearfix { | |
line-height: 1px; | |
height: 1px; | |
width: auto; | |
clear: both; } |
This file contains hidden or 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 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: |
This file contains hidden or 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
/* 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%;} |
This file contains hidden or 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
# 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" = "/" ] |
This file contains hidden or 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
# 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 |
OlderNewer