Skip to content

Instantly share code, notes, and snippets.

@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:
@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 / 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: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() {
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: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.
@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:750b990bcc8774315752
Created September 5, 2014 05:17
django设置取消自动登录
request.session.set_expiry(0)
@xiaotangyuan
xiaotangyuan / gist:fb14d690e7a7deeb942a
Created August 21, 2014 03:19
windows下安装pip-文件get-pip.py
This file has been truncated, but you can view the full file.
#!/usr/bin/env python
#
# Hi There!
# You may be wondering what this giant blob of binary data here is, you might
# even be worried that we're up to something nefarious (good for you for being
# paranoid!). This is a base64 encoding of a zip file, this zip file contains
# an entire copy of pip.
#
# Pip is a thing that installs packages, pip itself is a package that someone
# might want to install, especially if they're looking to run this get-pip.py
@xiaotangyuan
xiaotangyuan / gist:61d0403d269cda9a0c77
Created August 21, 2014 03:18
windows下安装pip-文件distribute_setup.py
#!python
"""Bootstrap distribute installation
If you want to use setuptools in your package's setup.py, just include this
file in the same directory with it, and add this to the top of your setup.py::
from distribute_setup import use_setuptools
use_setuptools()
If you want to require a specific version of setuptools, set a download