Skip to content

Instantly share code, notes, and snippets.

View lepture's full-sized avatar
💭
I'm working on Typlog.com now

Hsiaoming Yang lepture

💭
I'm working on Typlog.com now
View GitHub Profile
import pydouban
@route('/login')
class Login(WebHandler):
def get(self):
auth = pydouban.Auth(key, secret) # your consumer key and secret
dic = auth.login('http://localhost/auth')
memcache.set('douban', dic)
return self.redirect(dic['url'])
import pydouban
@route('/me')
class Profile(WebHandler):
def get(self):
qs = db.Douban.get('qs')
api = pydouban.Api()
api.set_qs_consumer(key, secret, qs)
profile = api.get_profile()
return self.response(profile)
#!/usr/bin/env python
#
# Copyright 2010 by Marvour
#
# Under the BSD License
"""
A simple handler with cookie and session supporting.
Here is a simple example:
@lepture
lepture / embed.py
Created October 13, 2010 09:29
filter
@register.filter
def embed(value):
#gist
value = re.sub(r'(https?://gist.github.com/[\d]+)',r'<small><a rel="nofollow" href="\1">\1</a></small><script src="\1.js"></script>', value)
#youtube
value = re.sub(r'http://www.youtube.com/watch\?v=([a-zA-Z0-9\-\_]+)', r'<small><a rel="nofollow" href="http://www.youtube.com/watch?v=\1">Youtube Source</a></small><br /><embed src="http://www.youtube.com/v/\1?fs=1&amp;hl=en_US" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385" />', value)
#youku
value = re.sub(r'http://v.youku.com/v_show/id_([a-zA-Z0-9\=]+).html', r'<small><a rel="nofollow" href="http://v.youku.com/v_show/id_\1.html">Youku Source</a></small><br /><embed src="http://player.youku.com/player.php/sid/\1/v.swf" quality="high" width="480" height="400" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" />', value)
#tudou
value = re.sub(r'http://www.tudou.com/programs/view/([a-zA-z0-9\-\=]+)/',r'<small
@lepture
lepture / datetime_json.py
Created October 19, 2010 11:53
datetime_json
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import datetime
from django.utils import simplejson
#import simplejson
class DateTimeJSONEncoder(simplejson.JSONEncoder):
"""
@lepture
lepture / .vimrc
Created November 14, 2010 11:23
vimrc
" System
set nocompatible
set backspace=indent,eol,start
set nobackup
set history=50
set encoding=utf-8
set fileencoding=utf-8
set fileencodings=utf-8,cp936
set ff=unix
@lepture
lepture / django_render.py
Created December 28, 2010 07:49
django_render.py
# -*- coding: utf-8 -*-
import datetime
from django.http import HttpResponse
from django.utils import simplejson
from django.shortcuts import render_to_response
from django.template import RequestContext
class DateTimeJSONEncoder(simplejson.JSONEncoder):
"""
@lepture
lepture / .gitconfig
Created January 7, 2011 07:29
git config
[core]
editor=vim
[merge]
tool = vimdiff
[alias]
st = status
ci = commit -a
br = branch
df = diff
co = checkout
@lepture
lepture / xiami.py
Created June 8, 2011 12:35
xiami checkin script
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (c) 2011, lepture.com
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# * Redistributions of source code must retain the above copyright
@lepture
lepture / iframe-upload.js
Created September 25, 2011 09:39
iframe uploader
/*
* @require jquery.js
* @author lepture
*/
if(window.jQuery){(function($){
var iframeUploader = function(options) {
var settings = {
'iframeID': 'ifrUploader',
'callback': null