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 getfour(): | |
... return 4 | |
... | |
>>> mydict['special'] = getfour() | |
>>> mydict | |
{'a': 1, 'b': 2, 'special': 4} | |
>>> |
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 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); | |
} |
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
<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) |
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 escape(html): | |
""" | |
Returns the given HTML with ampersands, quotes and angle brackets encoded. | |
""" | |
return mark_safe(force_unicode(html).replace('&', '&').replace('<', '<').replace('>', '>').replace('"', '"').replace("'", ''')) | |
escape = allow_lazy(escape, unicode) |
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 django.utils.html import escape | |
>>> escape('<h1>hello</h1>') | |
u'<h1>hello</h1>' |
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 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): |
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
""" | |
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. :) | |
""" |
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 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 |
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 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."), |
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
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: |