原创 ruby 一切都是對象

ruby中一切都是對象 ,變量名 都是引用,  函數是值傳遞(傳遞的引用, 可由此達到改變對象的值), 沒有基礎類型 對變量賦值實際是將變量名指向其他的值 a = ’value1‘                 a=’value2‘  

原创 python copy * shallow

需要在程序中使用二維數組,網上找到一種這樣的用法: 1 2 3 4 5 6 #創建一個寬度爲3,高度爲4的數組 #[[0,0,0], # [0,0,0], # [0,0,0], # [0,0,0

原创 ruby pass by reference

Q1: What happens when you assign a new variable str to a value of 'foo'? str = 'foo' str.object_id # => 2000 A: A lab

原创 python wraps decorator

frominspectimportgetmembers, getargspec fromfunctoolsimportwraps   defwraps_decorator(f):     @wraps(f)     defwraps_wr

原创 匹配漢字英文字符

  正則表達式 匹配中文,英文字母和數字及_的寫法!同時控制長度 2012-12-07 18:23 7639人閱讀 評論(0) 收藏 舉報 匹配中文:[\u4e00-\u9fa5]  英文字母:[a-zA-Z]  數字:[0-9

原创 markdown use

代碼 如果要標記一小段行內代碼,你可以用反引號把它包起來(`),例如: Use the `printf()` function. 會產生: <p>Use the <code>printf()</code> function.<

原创 redis sort 使用外部key排序

使用外部 key 進行排序 有時候你會希望使用外部的 key 作爲權重來比較元素,代替默認的對比方法。 假設現在有用戶(user)數據如下: id name level 1 admin 9999 2 huangz

原创 How To Use Linux epoll with Python

How To Use Linux epoll with Python

原创 redis python操作 string integer

打開Python解釋器: >>> import redis >>> r = redis.Redis(host='localhost', port=6379, db=0)   #如果設置了密碼,就加上password=密碼 >>> r.

原创 JavaScript事件冒泡

JavaScript的事件確實會帶着這個屬性。當程序捕獲一個事件的時候,它會知道這個事件來自於頁面上哪個元素。修改上面的程序,使用事件委託來處理點擊事件。當最頂層捕獲點擊事件時,查看事件來源於哪一層,然後只將那一層塗色。再次點擊每一層,

原创 socket SO_REUSEADDR

SO_REUSEADDR可以用在以下四種情況下。    (摘自《Unix網絡編程》卷一,即UNPv1)    1、當有一個有相同本地地址和端口的socket1處於TIME_WAIT狀態時,而你啓動的程序的socket2要佔用該地址和端口,

原创 python default arg 和 *args 不能同時用

python 函數 定義過程中參數的設置有一個問題 def func1( a, b, c=1, d=1, *args): ###默認參數必須在*args前, 但調用函數過程卻會有問題(因爲調用函數時輸入的參數必須是keyword ar

原创 pitfall while if condition in python non zero

python 中 if while 條件語句 條件是不爲零

原创 python 判斷控制符 unicode str

import codecs f = codecs.open('unicode.rst', encoding='utf-8') def rm_control_characters(string): return "".jo

原创 python dict reg key

Dictionary lookup with regular expression as key I just remembered that I was meant to post that thing here, too. P