Monday, September 5, 2011

how to disable "dim" or "opacity" when searching in opera

type opera:config in address bar, and search for "opacity" in the search field.
change the value from default 52 to 0, and apply. The window will no longer dim .

how to control "double click" popup menu of opera

open file ui\standard_menu.ini, and search for  "copy to note". Modify following section, and "copy" will be moved to No. 1 position.

[Hotclick Popup Menu]
Item, MI_IDM_DOCCOPY = Copy
Item, MI_IDM_SELSEARCH = Hotclick search, 200,,, "Search Web"
Item, MI_IDM_SELSEARCH = Hotclick search, 200,,, "Search Web"
Submenu, MI_IDM_SEARCH_DUMMY_PARENT, Internal Search With
--------------------1
Item, M_COPY_TO_NOTE = Copy to note
Platform Win2000-Unix-Mac, Feature Voice, Item, M_HOTCLICK_MENU_ITEM_SPEAK = Speak selection

mips instruction encoding

Instructions are divided into three types: R, I and J. Every instruction starts with a 6-bit opcode. In addition to the opcode,
R-type instructions specify three registers, a shift amount field, and a function field;
I-type instructions specify two registers and a 16-bit immediate value;
J-type instructions follow the opcode with a 26-bit jump target.

The following are the three formats used for the core instruction set:
Type format (bits)

      31-26 | 25-21 |20-16 |15-11 | 10-6 | 5-0 |
R: opcode (6) | rs (5) |rt (5) |rd (5) | shamt (5) | funct (6) |
I: opcode (6) | rs (5) |rt (5) |immediate (16) |
J: opcode (6) | address (26)                         |


UDI instructions are added to MIPS24Kc core.

Thursday, June 30, 2011

python example (jpeg timestamp)

This is a combination usage of:
iterator
callback
yield
image processing

Created/updated by BA43B09F0725,qunshan@newsmth

import os, sys, time
import Image, ImageDraw, ImageFont

def findfiles(path, *callbacks):
for root, dirs, names in os.walk(path):
for name in names:
filename = os.path.join(root, name)
info = tuple(x(filename) for x in callbacks)
yield (filename,)+info

def addString(filename, timestr):
font = ImageFont.truetype(os.path.join(os.environ['windir'], 'Fonts', 'AGENCYB.TTF'), 108)
im = Image.open(filename)
x, y = im.size
draw=ImageDraw.Draw(img)
#draw.ink = 0 + 255*256 + 0*256*256
draw.text((x-640,y-128), timestr, font=font)
img.save(filename)

def addTimeString(filename, mtime):
timestr = time.strftime("%Y-%m-%d %H:%M", time.localtime(mtime))
addString(filename, timestr)
os.utime(filename, (time.time(), mtime))

if __name__ == '__main__':
for filename, mtime in findfiles(sys.argv[1], os.path.getmtime):
if filename.lower().endswith(('.jpg', '.jpeg')):
addTimeString(filename, mtime)

Thursday, June 23, 2011

停车技巧

停车技巧:

非字形停车位:右侧车身 距离车位线1.5m,向后倒车; 在驾驶位位于隔一个停车位正中央时,向内侧打满轮,至车正,回正。

一字形停车: 右侧车身 距离车位线0.5m,向后倒车;在后视镜和前车B柱平行时,向内侧打满轮,继续倒车,至车呈45度角,反向打满轮,至车正,回正。

斜线停车位:后视镜对停车位近端边线时,向外侧打满轮,至车身和车位平行,回正,入车位。

自动档驾驶学习

N档的作用:
转自http://club.autohome.com.cn/bbs/thread-c-413-824998-1.html

1、被拖车时用: (拖行距离不超过50公里)。

2、长时间(超过1分钟至数分钟内)等红灯时用: (在我们这里,红绿灯都有数字递减显示。就可以根据上述原则,采取“①挂N,拉手闸。②保持D档,拉手闸。”)

3、汽车启动、熄火时: (所有汽车说明书都是讲点火要挂在P档,但问题在于: 当在P档点火后,要挂入D档前,是一定要经过R(倒车档)档,当经过R档时,车辆会自然震动一下,这是挂R档的缘故,从P档到D档过程中,等于先入了R档再入D档,无形中多了一次入R档的组合和磨擦,

我的做法是:踩着刹车打开钥匙第一级--挂N档--打火--挂D档--松手刹、放脚刹起步。
自动档熄车也有讲究,我是这样操作的: 熄火前踩着刹车挂N档--拉手刹--放开脚刹--关钥匙第一级--入P档--关钥匙第二级并取出钥匙。 其道理是:停车时,当踩着刹车入P档,拉手刹放开脚刹时,车辆会惯性地向前或向后移动一点位置,这是因为停车场不平整或有少许斜坡而造成的,不要小看这一点点移动,它会对自动变速箱中的锁止栓有一定的冲击,日积月累会对锁止栓有损害,就会出现过锁止栓断开的故障)。

Sunday, June 12, 2011

cache - set associative

Cache Associative:

Full-Associative
If the replacement policy is free to choose any entry in the cache to hold the copy, the cache is called fully associative.
Direct-Mapped
At the other extreme, if each entry in main memory can go in just one place in the cache, the cache is direct mapped.
N-Way-Associative
Many caches implement a compromise in which each entry in main memory can go to any one of N places in the cache, and are described as N-way set associative.

If there are N places to which the replacement policy could have mapped a memory location, then to check if that location is in the cache, N cache entries must be searched. Checking more places takes
*PROs: caches with more associativity suffer fewer misses
*CONs: more power, chip area, and potentially time.


From direct mapped to 2-way, or from 2-way to 4-way, has about the same effect on hit rate as doubling the cache size.
Associativity increases beyond 4-way have much less effect on the hit rate


Example:
An 4K cache is often organized as a set of 256 lines(slots) of 16 bytes each.
Accordingly, a 4-way associative 4K cache has 64 sets, each set having 4 lines mapped.

A 32b address is divided into
[31:10] [9:4] [3:0]
tag set offset

For a given physical addr, first find the set with A[9:4] in cache.
Then search in all 4 slots to see if the tag A[31-10] matches the tag in the slot.

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


Monday, March 7, 2011

decorator

Definition
A decorator is a function whose primary purpose is to wrap another function or class.
Purpose
The primary purpose of this wrapping is to transparently alter or enhance the behavior
of the object being wrapped.
Basic usage
Syntactically, decorators are denoted using the special @ symbol as follows.  More than one decorator can also be applied.
@trace1
@trace0
def square(x):
    return x*x
The preceding code is shorthand for the following:
def square(x):
    return x*x
square = trace1(trace0(square))

Using parameters
A decorator can also accept arguments. Here’s an example:
@eventhandler('BUTTON')
def handle_button(msg):
    ...
The semantics of the decorator are as follows:
def handle_button(msg):
    ...
temp = eventhandler('BUTTON') # Call decorator with supplied arguments
handle_button = temp(handle_button) # Call the function returned by the decorator

Class decorator
Decorators can also be applied to class definitions. For example:
@foo
class Bar(object):
    def __init__(self,x):
        self.x = x
    def spam(self):
        statements

For class decorators, you should always have the decorator function return a class object
as a result.

decorator

how to release python program/lib

To distribute Python programs to others, you should use the distutils module.
1. As preparation, you should first cleanly organize your work into a directory that has a
README file, supporting documentation, and your source code.
Typically, this directory will contain a mix of library modules, packages, and scripts. Modules and packages refer to source files that will be loaded with import statements. Scripts are programs that will run as the main program to the interpreter (e.g., running as python scriptname).
Here is an example of a directory containing Python code:
spam/
    README.txt
    Documentation.txt
    libspam.py # A single library module
    spampkg/ # A package of support modules
        __init__.py
        foo.py
        bar.py
    runspam.py # A script to run as: python runspam.py



2. After you have organized your code, create a file setup.py in the top most directo-
ry (spam in the previous examples). In this file, put the following code:
# setup.py
from distutils.core import setup
setup(name = "spam",
    version = "1.0",
    py_modules = ['libspam'],
    packages = ['spampkg'],
    scripts = ['runspam.py'],
)

3.Type the following shell command to make a source distribution:
% python setup.py sdist
...
This creates an archive file such as spam-1.0.tar.gz or spam-1.0.zip in the directo-
ry spam/dist.

If you type 'python setup.py bdist', a binary distribution is created in
which all of the .py files have already been precompiled into .pyc files and placed into
a directory structure that mimics that of the local platform.
  If you run 'python setup.py bdist_wininst' on a Windows machine, an .exe file will be created.
4. To install, a user simply unpacks the archive and performs these steps:
% unzip spam-1.0.zip
...
% cd spam-1.0
% python setup.py install

This installs the software into the local Python distribution and makes it available for
general use. Modules and packages are normally installed into a directory called
"site-packages" in the Python library.

5. alternative install option
 Python software is often distributed in the form of an .egg file.This format is created by the popular setuptools
extension (http://pypi.python.org/pypi/setuptools).To support setuptools, you can
simply change the first part of your setup.py file as follows:
# setup.py
try:
    from setuptools import setup
    except ImportError:
    from distutils.core import setup
    setup(name = "spam",
        ...
    )

6. Appendix:
list of setup arguments:
Parameters to setup()Parameter Description
name Name of the package (required)
version Version number (required)
author Author’s name
author_email Author’s email address

maintainer Maintainer’s name
maintainer_email Maintainer’s email
url Home page for the package
description Short description of the package
long_description Long description of the package
download_url Location where package can be downloaded
classifiers List of string classifiers

TurboGears

Sunday, March 6, 2011

游泳学习

踩水
保持双大腿在前,两脚呈摇橹状
1. 小臂平面向后划

2. 小腿收回状态时,脚往外侧翻,指向蹬出方向
3. 蹬出双腿
4. 收回。过程中双脚垂直于收回方向

蛙泳 - 简单分为5步:
划(臂)/收(臂)/伸(臂)、蹬(腿)/漂

1. 划臂至与肩同宽时,向下压水,使头部浮出水面。
2. 收臂至胸前
3. 先伸臂,然后向侧后方蹬腿。蹬腿前,把脚掌向外翻,以增加划水面积。
4. 直体漂滑

自由泳 -

Thursday, February 24, 2011

opera menu configuration

standard_menu.ini
1. reason to change
a) disable unwanted "translate" menu
b) disable unwanted Inspect Item
c) move "copy" to first for Selection mode
d) use uniform shortcut for image property access.

2. changes to make

[Hotclick Popup Menu]

Item, MI_IDM_DOCCOPY = Copy
Item, M_COPY_TO_NOTE = Copy to note
Platform Win2000-Unix-Mac, Feature Voice, Item, M_HOTCLICK_MENU_ITEM_SPEAK = Speak selection
--------------------1
Item, MI_IDM_SELSEARCH = Hotclick search, 200,,, "Search Web"
Submenu, MI_IDM_SEARCH_DUMMY_PARENT, Internal Search With
--------------------2
Item, MI_IDM_SELDICTIONARY = Hotclick search, 50
Item, MI_IDM_SELENCYCLOPED = Hotclick search, 51
--------------------3
Item, M_HOTCLICK_POPUP_MENU_GOTO_URL = Go to page, "%t"
Item, MI_IDM_SELMAIL = Send text in mail


[Image Popup Menu]
Item, M_OPEN_IMAGE = Open image
Item, M_MENU_RELOAD_IMAGE = Load image
Item, MI_IDM_COPY_FIG_ADDRESS = Copy image address
--------------------1
Item, MI_IDM_SAVE_FIGURE = Save image
Item, M_DOCUMENT_BACKGROUND_MENU_COPY_TO_CLIPBOARD = Copy image
--------------------2
Platform Windows-Mac, Item, M_DOCUMENT_BACKGROUND_MENU_USE_ON_DESKTOP = Use image as desktop background
Item, M_IMAGE_MENU_USE_ON_SPEEDDIAL = Use image as speed dial background
--------------------3
; GhostItem, M_INSPECT_ELEMENT = Inspect element
GhostItem, M_FOLLOW_LONGDESC = Follow Image Description URL
Item, MI_IDM_SHOW_FIGURE_PROPERTIES = Show image properties