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.contrib.auth.models import User | |
class UsernameEmailAuthBackend(object): | |
""" | |
Authentication with username or E-mail | |
Allows user to login using username or E-mail and password pair. | |
""" | |
def authenticate(self, username=None, password=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
vbell off | |
autodetach on | |
startup_message off | |
shell -$SHELL | |
allpartial off | |
defc1 off | |
defencoding utf8 | |
bind b encoding big5 utf8 | |
bind u encoding utf8 utf8 |
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 MyForm(forms.Form): | |
username = forms.CharField(label=_('Your username'), min_length=3, max_length=30) | |
email = forms.EmailField(label=_('Your email address'), min_length=3, max_length=30) | |
def __init__(self, *args, **kwargs): | |
super(MyForm, self).__init__(*args, **kwargs) | |
for field in self.fields.values(): | |
field.error_messages = { | |
'required': ugettext('The field : {fieldname} is required !!').format(fieldname=field.label), |
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
# -*- coding: utf-8 -*- | |
import urllib, simplejson as json | |
likeurl = 'http://zenphoto.rdandy.com/yaya-2012-07-14/' | |
query = 'select like_count,total_count,share_count from link_stat where url="%s"' % likeurl | |
params = urllib.urlencode({'format': 'json','query': query}) | |
url = 'https://api.facebook.com/method/fql.query?%s' % params | |
result = urllib.urlopen(url) | |
res = json.loads(result.read()) |
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 math | |
""" | |
Sample: | |
lat = 25.0763881 | |
lon = 121.5259891 | |
brng = 45 | |
dist = 600 |
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
# paginator objects and page parameter in url | |
from django.http import HttpResponse | |
from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger | |
import json | |
AMOUNT_PER_PAGE = 10 | |
def someview(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
# serial_read.py | |
import serial, time | |
SERIALPORT = "/dev/ttyS0" | |
ser = serial.Serial(SERIALPORT, baudrate=115200, bytesize=8, parity="N", stopbits=1, rtscts=False, xonxoff=False) | |
def read_data(): | |
while True: | |
if ser.in_waiting: | |
print (ser.read()) |
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
# serial_write.py | |
import serial, time | |
SERIALPORT = "/dev/ttyS0" | |
ser = serial.Serial(SERIALPORT, baudrate=115200, bytesize=8, parity="N", stopbits=1, rtscts=False, xonxoff=False) | |
def write_data(): | |
while True: | |
txt = input("input some thing ...\r\n") |