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
import uuid | |
def get_token(): | |
token = uuid.uuid4() # random | |
return token |
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 activate_user(request, token): | |
# some preliminaries ... | |
user_profile.status_of_user = True | |
user_profile.token = "" | |
user_profile.save() # possibly hook on a post signal to handle any other cleanups etc. | |
return HttpResponseRedirect("/some/url/to/success/page") |
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 ScoreKeeper(object): | |
def __init__(self,f1,f2,f3,f4,f5,f6,f7,f8,f9,f10): | |
self.f1 = [f1, None] | |
self.f2 = [f2, None] | |
self.f3 = [f3, None] | |
self.f4 = [f4, None] | |
self.f5 = [f5, None] | |
self.f6 = [f6, None] | |
self.f7 = [f7, None] | |
self.f8 = [f8, None] |
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.core.cache import cache | |
# simple cache fetch: | |
vkey = "%s_%s_%s" % (site, slug, get_param) | |
vcache = cache.get(vkey) | |
if vcache: | |
return vcache # cached response |
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
# if we didn't get cache key, we continue with the view and then cache it before returning | |
resp = render_to_response(template_name, { | |
# ... stuff here | |
}, context_instance=RequestContext(request)) | |
cache.set(vkey, resp, TIMEOUT) | |
return resp |
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
import datetime | |
def dummy_view(request): | |
# view code | |
timestamp = datetime.datetime.now() | |
resp = render_to_response(template_name, { | |
# stuff... | |
'timestamp': timestamp, | |
}, context_instance=RequestContext(request)) |
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
metals <- data.frame(gold, silver) # gold, silver are vectors containing the closing prices | |
qplot(gold, silver, data=metals, geom=c("point", "smooth"), method="lm") |
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
# Example of a TCP/IP Server in .NET # | |
# Tested on Mono/IronPython # | |
# imports | |
from System.Net.Sockets import * | |
from System.Threading import * | |
from System.IO import * | |
# basic configuration | |
SERVER_PORT = 31000 |
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
# Example of a TCP/IP Client in .NET # | |
# Tested on Mono/IronPython # | |
# imports | |
from System.Net.Sockets import * | |
from System.IO import * | |
HOST = "127.0.0.1" | |
PORT = 31000 |
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 add_curly_wurly(func): | |
def curlized(): | |
print "~" | |
func() | |
print "~" | |
return curlized | |
@add_curly_wurly | |
def hello_world(): |