Skip to content

Instantly share code, notes, and snippets.

from django import forms
class SomeForm(forms.Form):
visible = forms.DecimalField(label="Amount")
hidden = forms.IntegerField(widget=forms.HiddenInput)
@pauladam
pauladam / gist:304295
Created February 14, 2010 22:03
Random choice with weighted probabilities
# typical to sum over your list of items perhaps
# performing some calculation on each item
normalizing_constant = \
sum([calc(item) for item in items if filter(item)])
r = random.random()
for item in items:
prob = get_probability(item) / normalizing_constant
@pauladam
pauladam / gist:226467
Created November 4, 2009 22:59
Simple script for remotely shutting down your DS nas device. Im lazy so I like to avoid logging into the web ui and clicking around.
#!/usr/bin/python
import urllib,urllib2, sys
BASE_URL = 'http://192.168.100.101:5000'
ADMIN_PASS = 'YOUR ADMIN PASS'
# Login to admin interface
parameters = {'username' : 'admin', 'passwd':ADMIN_PASS,'service_type':'1'}
request = urllib2.Request(BASE_URL+'/webman/modules/login.cgi', urllib.urlencode(parameters))