This file contains 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
a,b = 1,0 | |
while True: | |
a, b = b, a+b | |
print b |
This file contains 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 minimum(first, second): | |
# Returns the minimum | |
if first > second: | |
return sec | |
return first | |
#Test this | |
# print 5 |
This file contains 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 happy_birthday(name): | |
for i in range(0,4): | |
if i == 2: | |
print('happy birthday dear {}'.format(name)) | |
else: | |
print('happy birthday to you') | |
# example: |
This file contains 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 fib(n): | |
a, b = 1, 0 | |
while a < n: | |
yield a | |
a, b = b, a+b | |
# example: | |
''' |
This file contains 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 sum(ord(c) for c in 'Happy new year to you!') |
This file contains 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
# List comprehensions | |
# Generate a list of integers from 1 to 10 in one line | |
l = [i for i in range(1, 11)] | |
# Lambdas | |
# Anonymous functions assigned to variables | |
f = lambda x: x % 2 == 0 | |
for i in l: |
This file contains 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.conf import settings | |
from functools import wraps | |
from django.contrib.sites.models import get_current_site | |
from django.http import HttpResponseNotFound | |
def main_site_only(function): | |
"Use this decorator on views that should only be visible on your main site" | |
@wraps(function) | |
def decorator(request, *args, **kwargs): |
This file contains 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(text): | |
html_escape_table = { | |
"&": "&", | |
'"': """, | |
"'": "'", | |
">": ">", | |
"<": "<", | |
} | |
return "".join(html_escape_table.get(c,c) for c in text) |
This file contains 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
import pykemon | |
name = 'charizard' # Example | |
p = pykemon.get(pokemon=name) | |
# Figure out the number of descriptions we have for this Pokemon | |
des = p.descriptions | |
l = str(len(des)) |
This file contains 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
r = Response() | |
r.message(pokemon_name + ',' + description) |
OlderNewer