Wednesday, May 25, 2011

cshell redirection

Character Action

>
Redirect standard output

>&
Redirect standard output and standard error

<
Redirect standard input

>!
Redirect standard output; overwrite file if it exists

>&!
Redirect standard output and standard error; overwrite file if it exists

|
Redirect standard output to another command (pipe)

>>
Append standard output

>>&
Append standard output and standard error

Tuesday, May 10, 2011

[python] Parameters: pass by value or ref?

C is pass-by-value.
Java is pass-by-value.
Python passes references-to-objects by value (like Java), and everything in Python is an object.

Some objects, like strings, tuples, and numbers, are immutable. Altering them inside a function/method will create a new instance and the original instance outside the function/method is not changed.

Other objects, like lists and dictionaries are mutable, which means you can change the object in-place. Therefore, altering an object inside a function/method will also change the original object outside. Assigning a separate object (e.g. creating a new instance) to the input parameter will also not change the original instance.


   def  no_change0(val)
          val *= 2   #original val is not changed.
         
    def  no_change1(inst)
          inst = {}
          inst['anything'] = 'something'  #original inst is not changed!!!


   def  change1(inst)
          inst['anything'] = 'something'  #original inst is changed this time.

[python] How to iterate through a list

  • basic iteration 
Iterating through a list in Python is simple using a for in loop.
colours = ["red","green","blue"]

for colour in colours:
    print colour
  • enumerate 
To iterate through the same list using an index we can apply the enumerate() function.
colours = ["red","green","blue"]

for i, colour in enumerate(colours):
    print i, colour

  • Remove elements as you traverse a list
iterate over a copy of the list:
for c in colors[:]:
    if c == 'green':
        colors.remove(c)
Hereby colors[:] is a copy (a weird but, sigh, idiomatic way to spell list(colors)) so it doesn't get affected by the .remove calls

Saturday, April 30, 2011

制作面包

溶解酵母

正确地溶解酵母是成功制作发酵面包最重要的步骤。

  1. 将酵母和少量糖溶解在40到46摄氏度左右的温水。这个温度和糖能使酵母迅速膨胀。可以使用温度计来检查液体的温度。
  2. 大约5分钟后,酵母将开始起泡。如果不起泡,请倒掉酵母混合物,然后重新操作。
     

切勿使用过期的酵母。酵母的效用会随时间降低。

和面
和面的时候将酵母水分次倒入面粉中,不要一次倒入,最好分次按量调节加入水分。
和面的目标是一定要把面团揉出筋。面筋是小麦粉中的蛋白质,它决定了面包的结构。面筋在面团中形成柔韧的长丝,这些长丝会拦住酵母产生的二氧化碳气体。拦住的气体会让面包发面。
用面包机揉面可以选发面团模式揉20分钟停下后再打开发面团模式再揉20分钟基本就可以出筋。
  1. 在面板上撒一层薄面,然后揉面。
  2. 揉面时,一定要使用手腕的力量,而不是手指的力量。
  3. 手腕用力将面团向外侧推开,然后将外侧的面放在下面,反复重复以上操作。
  4. 揉按面团,直到用手指按压时感觉到光滑、柔软、富有弹性(需8到10分钟)。气泡或水泡就会出现在面团表层下。
  5. 揉好面团后要对面团进行进一步的揉和摔打,直到揉出面筋,拉开面团有撑不破的膜为止,大概需要一小时左右的时间。
     
发面
  1. 用湿纱布将盆盖上,并将其放在温暖(21到24摄氏度)无风的地方。
  2. 让面团发面,直到体积增大一倍,这大概需要1小时。
发好的面团用手按下,按下的洞不回缩,为发酵完成。


塑形和二次发面

  1. 面团体积增大一倍后,用拳头进行挤压。这样可以去除大气泡,让面包的质地更细腻均匀。
  2. 将面团的各边向中间折,形成球形。
  3. 根据食谱说明对面团进行塑形,并将其放在涂好油的烤箱油纸或抹好油的面包盘中。
  4. 将塑形的面包盖上,然后将它们放在一个暖和的地方再次发面,直到体积增大一倍,这大概需要40分钟。
烘焙
  1. 将面包放在已经预热的烤箱中间的架子上。
  2. 如果面包变成金褐色,形状是圆圆的,轻拍时听起来是中空的,那么说明面包已经做好了。
  3. 若要使面包皮松脆,请在烘焙的过程中,在烤箱的底部放盘水,或者在面包表面刷层水。
    若要使面包皮松软,烘焙完后,立即在面包表面刷层软化黄油。

冷却和储藏
  1. 立即将面包从面包盘或烤箱油纸中取出,然后将面包放在铁架上冷却。
  2. 面包完全冷却后,用塑料包装袋将其包起来,或者将其放入密封的塑料袋或容器中。
  3. 在室温下储藏面包;将面包放在冰箱中会让面包更快变味。
  4. 将未包装的发酵面包放在室温下2到3小时进行解冻;您也可以将它们部分包起来放在温度190摄氏度左右的烤箱中加热20分钟。
  5. 在冷冻之前,需要将新出炉的面包放在铁架上至少冷却3小时。将面包在冰箱中的平面上放2小时,或者直到它已经冻硬。用塑料包装袋包好冷冻的面包,然后将面包放在铝箔中。标上面包的制作日期及面包的种类,然后将其放回冰箱。
  6. 面包最多可以冷冻6个月。将冷冻的面包连同包装放在室温下解冻2到3小时。将面包放在温度为150摄氏度左右的烤箱上加热20分钟,使其恢复新鲜。

Sunday, March 20, 2011

蛙泳

1.身体配合口诀:
蛙泳配合需注意,腿臂呼吸要适宜;
两臂划水腿放松,收手同时要收腿
两臂前伸腿蹬水,臂腿伸直划一会;
划水头部慢抬起,伸手滑行慢呼气。
2.蛙泳手臂动作口诀:
蛙泳手臂对称划,桃型划水向侧下;
两手屈腕来抓水,屈臂高肘向后划;
划到肩下快收手,两肘用力向里夹;
双手平行向前伸,伸直放松往前进。
3.蛙泳腿部动作口诀:
蛙泳蹬腿像青蛙,向后蹬夹向前滑;
收腿脚跟臀边靠,两膝相距似肩宽;
边收边分慢收腿,翻脚脚尖向两边;
用力向后蹬夹水,两脚并拢漂一会。

Monday, March 14, 2011

text formatter

#!/usr/bin/env python
# -*- coding: utf8 -*-
#-------------------------------------------------------------------------
#File name : strip.py
#Author : lfchen (Full Name please)
#Created : Mon 14 Mar 2011 02:04:35 PM CST
#Description :
# :
#Notes :
#-------------------------------------------------------------------------
#Copyright 2011 (c)
#-------------------------------------------------------------------------
import sys
import re

coding = 'utf-8'
def strip(infile, outfile):
try:
INFILE = open(infile,"r")
except:
print "\tERROR: fail to open file %s for processing" % infile
return
OUTFILE = open(outfile,"w")
prev_line=""
for line in INFILE:
line=line.decode(coding).rstrip("\n")
if line.endswith(" "): #keep ending space to avoid unintended contatenation of strings
line=line.rstrip() + " "
else:
line=line.rstrip()
if re.match(r'^\s*$', line) \
or line.endswith(".") or line.endswith("!") or line.endswith("?") or line.endswith(":") or line.endswith(";") \
or line.endswith("。".decode(coding)) or line.endswith("!".decode(coding)) or line.endswith("?".decode(coding)) \
or line.endswith(":".decode(coding)) or line.endswith(";".decode(coding)):
line += "\n"
if ('A'<=line[0]<='Z' or u'A'<=line[0]<=u'Z') and not prev_line.endswith("\n"):
line = "\n" + line
OUTFILE.write(line.encode(coding))
prev_line=line
INFILE.close()
OUTFILE.close()

if __name__ == "__main__":
if ("-h" in sys.argv[:]):
print "Usage: %s <filename(s)>" % sys.argv[0]
sys.exit(0)
else:
for filename in sys.argv[1:]:
print "dealing with file %s" % filename
strip(filename, "formatted_"+filename)

Wednesday, March 9, 2011

steps to setup web server (wsgi based)

========== installing apache ==========
1. download httpd-x.x.xx.tar.gz, and extract to specified folder; rename if necessary
2. chdir to exacted folder
3. ./configure --prefix=$PREFIX ($PWD is supported)
4. make (compile)
5. make install (install)
6. ./httpd -k start|stop|restart
========== installing python ==========
1. basically the same as apache installation
 2. additional package (try easy_install ) including genshi, repoze.tm, zif.sedna, xlwt, verilib, mx, RuleDispatch)0.
http://peak.telecommunity.com/snapshots/PyProtocols-1.0a0dev-r2302.tar.gz
http://peak.telecommunity.com/snapshots/RuleDispatch-0.5a1.dev-r2618.tar.gz

========== TurboGears ========
0. what's TurboGears
connect python to web (web io, db)
1. to install
download: wget http://www.turbogears.org/download/tgsetup.py
install: python tgsetup.py

========== paste ========
0. what's paste
1. to install (requires setuptools)
download: wget http://pypi.python.org/packages/source/P/Paste/Paste-1.7.5.1.tar.gz
wget http://pypi.python.org/packages/source/P/PasteScript/PasteScript-1.7.3.tar.gz#md5=9101a3a23809d3413b39ba8b75dd0bce
  install: python setup.py install
========== pylons ========
0. what's pylons
Pylons combines the very best ideas from the worlds of Ruby, Python and Perl, providing a structured but extremely flexible Python web framework. It's also one of the first projects to leverage the emerging WSGI standard, which allows extensive re-use and flexibility — but only if you need it. Out of the box, Pylons aims to make web development fast, flexible and easy.
1. to install
easy_install -f http://pylonshq.com/download/ Pylons==0.9.6.2
========== wsgi ========
0. what's wsgi
WSGI is the Web Server Gateway Interface. It is a specification for web servers and application servers to communicate with web applications (though it can also be used for more than that). It is a Python standard, described in detail in PEP 333.
1. to install
download: wget http://...
install: configure/make/make install
2. to use it, need python:paste & paste script

========== sedna ==========
1. download binary from website
http://modis.ispras.ru/sedna/install.html#srcfull
2. sh ./sedna-xxx-bin-xxx.sh
set the target addr to: /opt/soft/sedna-3.1.17 (3.4.66 doesn't work yet :( )
and the installed path will be .../sedna/
3. configure the result data folder (if necessary)
SEDNA_PATH/etc/sednaconf.xml
/opt/soft/SEDNA_DB_DATA
need to crate the data folder manually
4. at engsrv35, use se_exp export $mydb to export existent db
at bjdb, use se_exp import $mydb to import db