Skip to content

Instantly share code, notes, and snippets.

>>> def getfour():
... return 4
...
>>> mydict['special'] = getfour()
>>> mydict
{'a': 1, 'b': 2, 'special': 4}
>>>
var c2t = paper.text(300, 130, "13.41");
c2t.hide();
var c2 = paper.circle(50,145,5);
c2.attr('fill', '#555');
c2.attr('stroke-width', 0);
c2.node.onmouseover = function() {
c2t.show();
c2.attr('stroke','#fff');
c2.attr('stroke-width', 2);
}
<script type='text/javascript+protovis'>
new pv.Panel()
.width(350)
.height(200)
.add(pv.Image)
.url('bg.gif')
.title('_incubator by kenny shen')
.add(pv.Dot)
.data([[1,11.29],[2,13.41],[3,13.11],[4,12.51],[5,14.02],[6,14.65],[7,13.36],[8,14.34],[9,16.38],[10,17.23],[11,17.8],[12,17.67]])
.left(function(d) d[0] * 15)
def escape(html):
"""
Returns the given HTML with ampersands, quotes and angle brackets encoded.
"""
return mark_safe(force_unicode(html).replace('&', '&amp;').replace('<', '&lt;').replace('>', '&gt;').replace('"', '&quot;').replace("'", '&#39;'))
escape = allow_lazy(escape, unicode)
>>> from django.utils.html import escape
>>> escape('<h1>hello</h1>')
u'&lt;h1&gt;hello&lt;/h1&gt;'
def mark_safe(s):
"""
Explicitly mark a string as safe for (HTML) output purposes. The returned
object can be used everywhere a string or unicode object is appropriate.
Can be called multiple times on a single string.
"""
if isinstance(s, SafeData):
return s
if isinstance(s, str) or (isinstance(s, Promise) and s._delegate_str):
"""
Pages in Django can are served up with custom HTTP headers containing useful
information about those pages -- namely, the content type and object ID.
This module contains utility functions for retrieving and doing interesting
things with these special "X-Headers" (so called because the HTTP spec demands
that custom headers are prefixed with "X-").
Next time you're at slashdot.org, watch out for X-Fry and X-Bender. :)
"""
from django.shortcuts import render_to_response
from django.core.xheaders import populate_xheaders
from mysite.sampleapp.models import Company
def home(request):
myresponse = render_to_response('home.html')
test_object_id = 2
populate_xheaders(request, myresponse, Company, test_object_id)
return myresponse
from django import forms
from django.contrib import admin
from django.contrib.flatpages.models import FlatPage
from django.utils.translation import ugettext_lazy as _
class FlatpageForm(forms.ModelForm):
url = forms.RegexField(label=_("URL"), max_length=100, regex=r'^[-\w/]+$',
help_text = _("Example: '/about/contact/'. Make sure to have leading"
" and trailing slashes."),
class Squash:
def __init__(self):
self.alp = ALP
self.base_length = len(self.alp)
def _squash(self, num):
if (num == 0):
return self.alp[0]
squash_collect = []
while num: