Skip to content

Instantly share code, notes, and snippets.

import uuid
def get_token():
token = uuid.uuid4() # random
return token
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")
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]
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
# 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
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))
metals <- data.frame(gold, silver) # gold, silver are vectors containing the closing prices
qplot(gold, silver, data=metals, geom=c("point", "smooth"), method="lm")
# 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
# 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
def add_curly_wurly(func):
def curlized():
print "~"
func()
print "~"
return curlized
@add_curly_wurly
def hello_world():