Skip to content

Instantly share code, notes, and snippets.

@xiaotangyuan
xiaotangyuan / gist:750b990bcc8774315752
Created September 5, 2014 05:17
django设置取消自动登录
request.session.set_expiry(0)
@xiaotangyuan
xiaotangyuan / gist:827ff30022b81e1defc4
Created September 11, 2014 10:16
去掉html标签
import re
re.subn(r'<.+>','','fdsfdsfs32<fdsfsf>1321f<fdsf/a>dsfvds')
@xiaotangyuan
xiaotangyuan / gist:c2127743b3c2962d0f64
Created September 25, 2014 03:08
django禁用{{}}标签
# coding=utf-8
"""
jQuery templates use constructs like:
{{if condition}} print something{{/if}}
This, of course, completely screws up Django templates,
because Django thinks {{ and }} mean something.
from oss.oss_api import *
ID='fdsfdsf'
KEY='fdsfdsfsfdd'
oss=OssAPI(access_id=ID,secret_access_key=KEY)
# res=oss.get_bucket_acl('headimg2')
# print res.status,res.read()
res=oss.put_object_from_file('headimg','your.jpg','1.jpg')
print res.status,res.read()
@xiaotangyuan
xiaotangyuan / gist:d0a5759d34deed7a3851
Created September 28, 2014 10:14
angularjs更新title
// 定义updateTitle指令
app.directive('updateTitle', function($rootScope, $timeout) {
return {
link: function(scope, element) {
var listener = function(event, toState, toParams, fromState, fromParams) {
var title = 'Default Title';
if (toState.data && toState.data.pageTitle) title = toState.data.pageTitle;
// Set asynchronously so page changes before title does
$timeout(function() {
@xiaotangyuan
xiaotangyuan / signals.py
Last active April 1, 2016 03:24
django signals example
#--example 1--
from django.dispatch import Signal
login_signal=Signal()
def login_func(**kwargs):
print 'login_func'
login_signal.send(sender='login_func', **kwargs)
def login_handler1(sender,**kwargs):
print 'someone login'
@xiaotangyuan
xiaotangyuan / gist:849dbf41f60c0fcce0cc0bbd8f438925
Last active June 27, 2016 14:33
leetcode:2. Add Two Numbers
# Definition for singly-linked list.
# class ListNode(object):
# def __init__(self, x):
# self.val = x
# self.next = None
def addtwoNode(node1,node2,step):
if node1 is None:
node1_val = 0
else:
node1_val = node1.val
@xiaotangyuan
xiaotangyuan / gist:da89f50508c34aa7e731e8c049b20f3e
Created June 29, 2016 07:43
leetcode:3. Longest Substring Without Repeating Characters
class Solution(object):
def lengthOfLongestSubstring(self, s):
"""
:type s: str
:rtype: int
"""
resstring = ''
cache = ''
for i in s:
if i not in cache:
class Solution(object):
def findMedianSortedArrays(self, nums1, nums2):
"""
:type nums1: List[int]
:type nums2: List[int]
:rtype: float
"""
nums = nums1 + nums2
nums = sorted(nums)
total = len(nums)
def selectorder(thelist):
for index,num in enumerate(thelist):
minnum = num
minnum_index = index
for index2,num2 in enumerate(thelist[index+1:]):
if num2 < minnum:
minnum = num2
minnum_index = index + index2 + 1
thelist[index] = minnum