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
    
  
  
    
  | def changed(l): | |
| l.append("a") # change the original object | |
| def unchanged(l): | |
| l = l + ["a"] # l + ["a"] will create a new list, instead of changing the original object | |
| l1 = [] | |
| changed(l1) | |
| # l1 == ["a"] | 
  
    
      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
    
  
  
    
  | # simple iteration | |
| a = [] | |
| for x in range(10): | |
| a.append(x*2) | |
| # a == [0, 2, 4, 6, 8, 10, 12, 14, 16, 18] | |
| # list comprehension | |
| a = [x*2 for x in range(10)] | |
| # dict comprehension | 
  
    
      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
    
  
  
    
  | # create virtual env | |
| virtualenv --no-site-packages --python=python3.2 ./venv | |
| # activate virtual env | |
| source ./venv/bin/activate | |
| # install requirements | |
| pip install -r requirements.txt | |
| #..... | |
| # update requirements | 
  
    
      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
    
  
  
    
  | # 计算列表内所有元素的和, 包括基本loop方式,sum函数方式,以及使用reduce函数 | |
| # the basic way | |
| s = 0 | |
| for x in range(10): | |
| s += x | |
| # the right way | |
| s = sum(range(10)) | 
  
    
      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
    
  
  
    
  | def memoize(f): | |
| memo = {} # 将结果缓存在memo字典对象中,key是参数,value是结果。 | |
| def helper(x): | |
| if x not in memo: | |
| memo[x] = f(x) | |
| return memo[x] | |
| return helper | |
| # 修饰fib函数,任何fib函数的调用,将首先察看是否已经有缓存的结果 | |
| @memoize | 
  
    
      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
    
  
  
    
  | def argument_test_natural_number(f): | |
| def helper(x): | |
| if type(x) == int and x > 0: | |
| return f(x) | |
| else: | |
| raise Exception("Argument is not an integer") | |
| return helper | |
| @argument_test_natural_number | |
| def faculty(n): | 
  
    
      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
    
  
  
    
  | // node.js proxy server example for adding CORS headers to any existing http services. | |
| // yes, i know this is super basic, that's why it's here. use this to help understand how http-proxy works with express if you need future routing capabilities | |
| var httpProxy = require('http-proxy'), | |
| express = require('express'); | |
| var proxy = new httpProxy.RoutingProxy(); | |
| var proxyOptions = { | |
| host: 'ats.borqs.com', | 
  
    
      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
    
  
  
    
  | #!/usr/bin/env python | |
| # -*- coding: utf-8 -*- | |
| """ | |
| """ | |
| import jsonrpclib | |
| import os | |
| import urllib2 | |
| import subprocess | 
  
    
      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 bottle | |
| from wsgiproxy.app import WSGIProxyApp | |
| # Remove "hop-by-hop" headers (as defined by RFC2613, Section 13) | |
| # since they are not allowed by the WSGI standard. | |
| FILTER_HEADERS = [ | |
| 'Connection', | |
| 'Keep-Alive', | |
| 'Proxy-Authenticate', | |
| 'Proxy-Authorization', | 
  
    
      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
    
  
  
    
  | // Source: https://groups.google.com/forum/#!topic/angular/hVrkvaHGOfc | |
| // jsFiddle: http://jsfiddle.net/pkozlowski_opensource/PxdSP/14/ | |
| // author: Pawel Kozlowski | |
| var myApp = angular.module('myApp', []); | |
| //service style, probably the simplest one | |
| myApp.service('helloWorldFromService', function() { | |
| this.sayHello = function() { | |
| return "Hello, World!" | 
OlderNewer