from django.http import HttpResponseRedirect, HttpResponse
import time, sha, urllib, hmac
def jump(request):
query = { 'app_key': "...application_key...",
'perms': 'userhash',
't': str( int(time.time())),
'v': '1.0',
'userdata': request.POST.get('url','http://www.sample.net/')
}
sec_key = "...secret_key..."
sig = hmac.new(sec_key, digestmod=sha)
keys = query.keys()
keys.sort()
for key in keys:
sig.update(key)
sig.update(query[key])
query['sig'] = sig.hexdigest()
return HttpResponseRedirect('http://auth.livedoor.com/login/?%s'%urllib.urlencode(query))
def callback(request):
query = request.GET
sec_key = "...secret_key..."
sig = hmac.new(sec_key, digestmod=sha)
keys = query.keys()
keys.sort()
for key in keys:
if key == "sig":
continue
sig.update(key)
sig.update(query[key])
if sig.hexdigest() == request.GET.get("sig",""):
return HttpResponseRedirect(urllib.unquote(query.get("userdata","http://www.sample.net")))
else:
return HttpResponse("NG")
どこかで子供が痛めつけられたとか、殺人事件があったとか、そういったニュースはそれ自体は非常に痛ましくて、なんとかしてあげたい気持ちにさせられますが、たいがいはもうすでに視聴者としての私にできることはなく、ただ後味の悪さが残るばかりです。
for v in range(5): ws.store('v', v)
for v in ws.ifind('v'): print v
ws.deleteVar('v')
ws = NetWorkSpace('example', serverHost='myhost.mycorp.com')
ws = NetWorkSpace('not mine', useUse=True)
>>> from nws.sleigh import Sleigh
>>> s = Sleigh()
>>> from socket import gethostname
>>> s.eachWorker(gethostname)
['newt', 'newt', 'newt']
>>> s.stop()
>>> from nws.sleigh import sshcmd
>>> s = Sleigh(nodeList=['hippo', 'newt', 'python', 'rhino'], launch=sshcmd)
>>> s.eachWorker(gethostname)
['rhino', 'hippo', 'newt', 'python']
>>> r = s.eachElem(lambda x: x*x*x, range(100))
>>> len(r)
100
>>> r[2:5]
[8, 27, 64]
import sys
from nws.sleigh import Sleigh
def initPrimes():
global chunk, chunks, limit
limit, chunk = SleighUserNws.find('prime parameters')
chunks = {}
def findPrimes(first):
last = min(first+chunk, limit)
# we need to know all the primes up to the smaller of the start of
# this chunk or the square root of its last element.
need = min(first-2, int(.5+(last-1)**.5))
myPrimes = []
for c in xrange(3, need+1, chunk):
if not c in chunks: chunks[c] = SleighUserNws.find('primes%d'%c)
myPrimes += chunks[c]
newx = len(myPrimes)
for x in xrange(first, last, 2):
for p in myPrimes:
if x%p == 0: break
else: myPrimes.append(x)
if first**2 < limit: SleighUserNws.store('primes%d'%first, myPrimes[newx:])
return myPrimes[newx:]
def master(workers, limit, chunk):
s = Sleigh(workerCount=workers)
s.userNws.store('prime parameters', (limit, chunk))
s.eachWorker(initPrimes)
primes = [2]
map(primes.extend, s.eachElem(findPrimes, range(3, limit, chunk)))
return primes
if __name__=='__main__':
primes = master(int(sys.argv[1]), int(sys.argv[2]), int(sys.argv[3]))
print len(primes), primes[:3], '...', primes[-3:]
ws.store('x', ws.fetch('y'))
ws.x = ws.y
>>> from nws.client import NetWorkSpace
>>> ws=NetWorkSpace('test')
>>> l=['a','b','c']
>>> t=(1,2,3)
>>> d={'list':l, 'tuple':t}
>>> ws.store('dict example', d)
>>> ws.fetch('dict example')
{'list': ['a', 'b', 'c'], 'tuple': (1, 2, 3)}
Python
>>> from nws.client import NetWorkSpace
>>> ws=NetWorkSpace('tickets')
>>> ws.store('ticket', 'ticket string')
R
> library(nws)
> ws<-netWorkSpace('tickets')
> nwsFetch(ws, 'ticket')
[1] "ticket string"
from nws.client import NetWorkSpace
def f(x): return x*x*x
ws = NetWorkSpace('table')
while True:
ws.store('r', f(ws.fetch('x')))
ws = NetWorkSpace('table')
for x in range(100): ws.store('x', x)
for x in range(100): print 'f(%d) = %d'%(x, ws.fetch('r'))
for x in MyCandidateList:
currentMax = ws.fetch('max')
y = f(x)
if y > currentMax: ws.store('max', y)
for x in MyCandidateList:
currentMax = ws.find('max')
y = f(x)
if y > currentMax: ws.store('max', y)
for x in MyCandidateList:
currentMax = ws.find('max')
y = f(x)
if y > currentMax:
currentMax = ws.fetch('max')
if y > currentMax: currentMax = y
ws.store('max', currentMax)
from nws.client import SINGLE
ws.declare('status', SINGLE)
while True:
time.sleep(60)
status=...
ws.store('status', status)