Monday, December 31, 2012

常用Unix命令

常用Unix命令:
1. 在某文件夹下递归查找字符
$ find . -name "*"|xargs grep "MiFID"

or
$find . -name \*.cpp -exec grep -q "debug" '{}' \; -print
./mytest/test.txt:MiFID_Result.lst
2. 修改某文件夹下所有文件属性
find . -type f -exec chmod u+xwr {} \;
3. 在当前目录下查找文件长度大于1 M字节的文件:
$ find . -size +1000000c -print
批量删除空文件(大小等于0的文件)的方法:
find . -name "*" -type f -size 0c | xargs -n 1 rm -f
4. 当前进程状态
echo %ERRORLEVEL%       --Windows
echo $?                         --Unix
5.
find . -name *stone* -ls

JSP note

<%@ page isThreadSafe="false" %>
<%
String item = request.getParameter("item");
int howMany = new Integer(request.getParameter("units")).intValue();
%>
response.sendRedirect("http://www.txw100.com/");
<%
response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
String newLocn="/newpath/index.html";
response.setHeader("Location",newLocn);
%>
<%
response.setHeader("Cache-Control","no-store"); //HTTP 1.1
response.setHeader("Pragma","no-cache"); //HTTP 1.0
response.setDateHeader ("Expires", 0); //prevents caching at the proxy server
%>
<%
Cookie mycookie = new Cookie("aName","aValue");
response.addCookie(mycookie);
%>
When you want to preserve the current request/response objects and transfer them to another resource WITHIN the context, you must use getRequestDispatcher or getNamedDispatcher.
If you want to dispatch to resources OUTSIDE the context, then you must use sendRedirect. In this case you won't be sending the original request/response objects, but you will be sending a header asking to the browser to issue a request to the new URL.
If you don't need to preserve the request/response objects, you can use either.

Eclipse tips

Debug
Error: -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket;server=y,suspend=n,address=5001  IE will auto exit.
Right: -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5001

Proxy
D:\eclipse\eclipse-SDK-3.1M4-win32\eclipse\eclipse.exe -vmargs -Xmx256M -DproxySet=true -Dhttp.proxyHost=asproxy.cai.com -Dhttp.proxyPort=80 -Dhttp.proxyUser=truep -Dhttp.proxyPassword=<PASSWORD>


Shortcut
Alt+左箭头,右箭头        以在编辑窗口切换标签
Alt+上下箭头,                以自动选择鼠标所在行,并将其上下移动
Ctrl+f6                            可以弹出菜单,上面列出可以切换的编辑窗口,这样不用鼠标也可切换
Ctrl+f7                            可以在视图之间切换 ,如编辑视图,输出视图,工程视图
Ctrl+f8                            可以在不同的观察视图中切换,就是在java视图,调试视图,等之间切换
Ctrl+m                            可以在最大化当前窗口和还原当前窗口之间切换
Ctrl+e                              弹出输入窗口,可以输入你想要编辑的代码窗口,和Ctrl+f6的功能相同,只不过一个是选择的方式,一个是输入的方式,切换窗口
Ctrl+T                              可以直接显示光标所在内容的类图,可以直接输入,并跳到输入内容部分
按住Ctrl键,然后鼠标指向变量名,方法名,类名       在源代码中快速跳转
Ctrl + F11                      快速执行程序
Ctrl+Shift+F                   程序代码自动排版
Ctrl+Shift+O                 自动加入引用。说明: 假设我们没有Import任何类别时,当我们在程序里打入: ResourceAttirbute ra =new ResourceAttribute();  Eclipse会提示说没有引用类别,这时我们只要按下Ctrl+Shift+O ,它就会自动帮我们Import这个类别。 非常方便
Ctrl+/                            将选取的块注释起来:在Debug时很方便。
Alt + /                           就是大家都应该最常用的代码辅助了
Ctrl+h                           搜索,打开搜索对话框
Ctrl+Shift+Space          参数提示,如果此时位于方法体中,就会出现方法的参数提示,当前光标所在位置的参数会用粗体显示

moving lines up or down (Alt+Arrow Up and Alt+Arrow Down)
converting to lowercase or uppercase (Ctrl+Shift+Y and Ctrl+Shift+X).
Navigate > Go to Last Edit Location (Ctrl+Q)
Incremental Find Next (Ctrl+J)
Alt+Shift+W
Ctrl+F6 for switching between editors, Ctrl+F7 for switching between views
You can quickly switch editors using the Ctrl+E keybinding
Alt+/ (Edit Content Assist)
Ctrl+1 (Quick fix)
Alt+? (Parameter Hints)
You can quickly select Java code syntactically using the Structured Selection feature.
Highlight the text and press Alt+Shift+Arrow Up (Keep press and view)
Press Ctrl+O or Ctrl+F3
press Ctrl+T (Navigate > Quick Hierarchy) (too slow)

Oracle PL/SQL Collection

Nested tables can be stored in a database column, but associative arrays cannot.
Nested tables are appropriate for important data relationships that must be stored persistently.

Varrays are a good choice when the number of elements is known in advance, and when the elements are usually all accessed in sequence. When stored in the database, varrays retain their ordering and subscripts.
Each varray is stored as a single object, either inside the table of which it is a column (if the varray is less than 4KB) or outside the table but still in the same tablespace (if the varray is greater than 4KB). You must update or retrieve all elements of the varray at the same time, which is most appropriate when performing some operation on all the elements at once. But you might find it impractical to store and retrieve large numbers of elements this way.

android note

0. Install JDK6 and eclipse (classic eclipse-SDK-3.7.1-win32.zip).
1. Download the Android SDK starter package and unzip the package.
http://dl.google.com/android/android-sdk_r15-windows.zip
D:\android\sdk\android-sdk_r15-windows\android-sdk-windows
2. Run SDK Manager.exe to add Android platforms and other components to your SDK.
3. Install ADT Plugin
  Start Eclipse, then select Help > Install New Software....
  Click Add, in the top-right corner.
  Browse and select the downloaded zip file.
  Enter a name for the local update site (e.g., "Android Plugin") in the "Name" field.
  Click OK/Next/Finish.
  When the installation completes, restart Eclipse.
4. Configuring the ADT Plugin
  Window > Preferences -> Android
  For the SDK Location in the main panel, click Browse... and locate your downloaded SDK directory.
  
All applications are written using the Java programming language.
The Android SDK tools compile the code—along with any data and resource files—into an Android package, an archive file with an .apk suffix. All the code in a single .apk file is considered to be one application and is the file that Android-powered devices use to install the application.
Each process has its own virtual machine (VM), so an application's code runs in isolation from other applications.
Dalvik has been written so that a device can run multiple VMs efficiently. The Dalvik VM executes files in the
Dalvik Executable (.dex) format which is optimized for minimal memory footprint. The VM is register-based, and runs classes compiled by a Java language compiler that have been transformed into the .dex format by the included "dx" tool.   

Android applications are composed of one or more application components (activities,
services, content providers, and broadcast receivers)
The manifest file must declare all components in the application and should also declare all application requirements, such as the minimum version of Android required and any hardware configurations required.

However, there are ways for an application to share data with other applications and for an application to access system services:

It's possible to arrange for two applications to share the same Linux user ID, in which case they are able to access each other's files. To conserve system resources, applications with the same user ID can also arrange to run in the same Linux process and share the same VM (the applications must also be signed with the same certificate).
An application can request permission to access device data such as the user's contacts, SMS messages, the mountable storage (SD card), camera, Bluetooth, and more. All application permissions must be granted by the user at install time.
An activity represents a single screen with a user interface.
A service is a component that runs in the background to perform long-running operations or to perform work for remote processes. A service does not provide a user interface.
A content provider manages a shared set of application data.Through the content provider, other applications can query or even modify the data (if the content provider allows it).
A broadcast receiver is a component that responds to system-wide broadcast announcements. Many broadcasts originate from the system—for example, a broadcast announcing that the screen has turned off, the battery is low, or a picture was captured. Although broadcast receivers don't display a user interface, they may create a status bar notification to alert the user when a broadcast event occurs.
When the system starts a component, it starts the process for that application (if it's not already running) and instantiates the classes needed for the component. For example, if your application starts the activity in the camera application that captures a photo, that activity runs in the process that belongs to the camera application, not in your application's process. Therefore, unlike applications on most other systems, Android applications don't have a single entry point (there's no main() function, for example).

Three of the four component types—activities, services, and broadcast receivers—are activated by an asynchronous message called an intent.
An intent is created with an Intent object, which defines a message to activate either a specific component or a specific type of component—an intent can be either explicit or implicit, respectively.

The other component type, content provider, is not activated by intents. Rather, it is activated when targeted by a request from a ContentResolver. The content resolver handles all direct transactions with the content provider so that the component that's performing transactions with the provider doesn't need to and instead calls methods on the ContentResolver object. This leaves a layer of abstraction between the content provider and the component requesting information (for security).

Activities, services, and content providers that you include in your source but do not declare in the manifest are not visible to the system and, consequently, can never run. However, broadcast receivers can be either declared in the manifest or created dynamically in code (as BroadcastReceiver objects) and registered with the system by calling registerReceiver().

An Activity is simply a class that can run and do work. It can create a UI if it chooses, but it doesn't need to.

Working with korn shell

Working with korn shell
1.
Following are the built-in shell variables and their descriptions:

  • # : Specifies the number of arguments allocated to the current process.
  • : Shows the option specified to the shell when it is invoked.
  • ? : Shows the exit status of a specified command.
  • $: Shows the process ID of a shell process.
  • !: Shows the process ID of the last background command.
  • CDPATH: Shows the list of directories to search the cd command.
  • COLUMNS: Shows the width of the display in columns and lets you edit modes.
  • EDITOR: Lets you edit modes.
  • ERRNO: Shows the error number of a failed system call.
  • ENV: Shows the name of the file run as an environment file.
  • FCEDITL: Shows the default editor for the fc command.
  • FPATH: Let's you search a path for an automated function.
  • Internal Field Separator (IFS): Shows the list of symbols that act as word delimiters, such as space, tab, or a new line.
  • HISTFILE: Shows the name of the command history file.
  • OLDPWD: Shows the previous working directory.
 
2.

Input Mode Commands for the vi Editor
Command Key CombinationCommand NameDescription
IInsert modeInserts text before the current cursor position.
aAppend modeInserts text after the current cursor position.
rReplace modeReplaces the character at the cursor, one character at a time.
sReplace and insert modeDeletes the character on which the cursor is placed and overwrites it.
IBeginning lineInserts text at the beginning of the line pointed by the cursor.
AEnding lineInserts text at the end of the line pointed by the cursor.
ROverwriteOverwrites the existing text.
OBlank line belowInserts a single blank line below the line on which the cursor is currently placed. Enters the insert mode.
OBlank line upInserts a single blank line above the line on which the cursor is currently placed. Enters the insert mode.

 

Commands to Control the Cursor in vi Editor
Command KeyCommand NameDescription
hMove leftMoves the cursor one character left.
lMove rightMoves the cursor one character right.
eMove wordMoves the cursor to the end of the current word.
wMove wordMoves the cursor to the beginning of the next word towards the right.
bMove wordMoves the cursor to the beginning of the previous word towards the left.
kMove upMoves the cursor to the previous line, one line at a time.
jMove downMoves the cursor to the next line, one line at a time.
0Move beginningMoves the cursor to the beginning of the line.
^Move beginningMoves the cursor to the beginning of the first word of the line.
$Move endMoves the cursor to end of the current line.
1GMove first lineMoves the cursor to the beginning of the first line.
NGMove lineMoves the cursor to line n.
GMove last lineMoves the cursor to the beginning of the last line.
{Scroll upScrolls up half the page.
}Scroll downScrolls down half the page.

 

Scrolling Commands in vi Editor
Command Key CombinationDescription
Ctrl + fScrolls through the contents of the file one page up.
Ctrl + bScrolls through the contents of the file one page down.
Ctrl + uScrolls through the contents of the file half page up.
Ctrl + dScrolls through the contents of the file half page down.

 

Deletion Commands for vi Editor
Command Key CombinationDescription
dhDeletes previous character, one character at a time. Enters the input mode after deletion.
dlDeletes next character, one character at a time. Enters the input mode.
dbDeletes previous word, one word at a time. Enters the input mode.
dwDeletes next word, one word at a time. Enters the input mode.
ddDeletes entire line, one line at a time. This line is stored in the buffer and you can place it at the cursor position by the copy command. Enters the input mode.
nddDeletes n lines. N numbers of lines are deleted. Enters the input mode.
d$Deletes characters from the current cursor position until the end of line. Enters the input mode.
d0Deletes characters form the current cursor position until the beginning of the line. Enters the input mode.

 
 
Undo and Redo commands in vi Editor
Command Key combinationDescription
uUndoes all the previous changes in the line.
UUndoes a single previous change in the line.
. (period)Redoes last change at current cursor position.
yCopies the text in the line on which the cursor is placed.
pCopies the line selected by the copy command after the cursor.
PCopies the line selected by the copy command before the cursor.

 

Commands for Searching Text in the vi Editor
Command key CombinationDescription
?stringMatches the string with the text in the file, in back direction from the current cursor position. You need to place the string to match with the contents of the file after the question mark (?).
/stringMatches the string with the text in the file, in forward direction from the current cursor position. You need to place the string to match with the contents of the file after the back slash (/).
nRepeats the search in the same direction as that of the previous search.
NRepeats the search in the opposite direction as that of the previous search.

 
3.
In the Korn shell, an array variable is also called an indexed array. The Korn shell does not perform array-bound checks, which implies that an array can hold more array variables as the size of an array increases. Unlike other programming languages, such as C and C++, the Korn shell does not hold any junk value for an un-initialized array variable.
An index number represents each element of an array. The index number of the first element in an array is zero (0). The upper limit of the index is the total number of elements that an array variable can hold.
$ typeset -u number[6]
$ number[0]=70
$ echo ${number[0]}
$ firstname[0]="John"
$ echo ${firstname[0]}
Another method to assign values to an array is to assign all the values in a single statement. The syntax to assign values to multiple elements of an array in a single statement is:
$ set  -A firstname "John" "Paul" "Smith"

You can access more than one value from an array in a single statement. The syntax to access multiple values from an array in a single statement is:
${variablename[*]}
The command to access the elements of an array is:
$ echo ${firstname[*]}
 ksh histroy 列出所有历史命令
然后,r 命令号 即可执行选定的历史命令
Esc+k 列出上一条  Esc+\ 补齐
for username in $(cat $PASSWORD_FILE | cut -f1 -d:)
do
  print $username
done
查看Solaris CPU个数:
prtdiag -v (还可看内存 top)
psrinfo -v
uname -X
sed -e '/^#/d' /etc/services | more
sed -e 's/foo/bar/g' myfile.txt

vi
w b 单词往前/后移动
{ } 句子往前/后移动
向前重复搜索,按 n 键。要向后搜索,按 N 键
输入 :w filename.txt 便可另存为 filename.txt
J 命令将下一行接到当前行行末。现在,将光标移到一个字符并敲 r,然后输入新字符;您将看到原字符被替换掉
3dd dw 4J
O (大写)在当前行上面生成一空行
d3w 将删除光标后 3 个单词,d2j 将删除当前行和下两行

对于 Korn Shell 用户,文件名完成取决于 EDITOR 变量的值。如果 EDITOR 设置为 vi,那么您键入部分名称,然后按 Esc 键,后跟反斜杠 (\) 字符。如果 EDITOR 设置为 emacs,那么您键入部分名称,然后按两次 Esc 键以完成文件名。
怎么拼? how do you spell?
查看操作系统是64位还是32位         isainfo -kv

Visual Studio弱项

Visual Studio弱项:
C#:
1. 一次为所有属性添加get set,挨个添加后属性和方法被隔离
2. 无法自动移除所有不用的using

VI --From Solaris 10: The Complete Reference

VI
--From Solaris 10: The Complete Reference
The following commands can be executed in command mode:

  • /  Performs a forward search for a text string.
  • ?  Performs a backward search for a text string.
  • :  Runs an ex editor command on the current line.
  • !  Executes a shell within vi.
  • ZZ  Saves a file and exits.
  • h  Moves the cursor left.
  • j  Moves the cursor down.
  • k  Moves the cursor up.
  • l  Moves the cursor right.
  • nG  Moves the cursor to line n.
  • w  Moves to next the word.
  • b  Moves back one word.
  • dw  Deletes words.
  • ndw  Deletes n words.
  • d^  Deletes all words to the beginning of the line.
  • dd  Deletes the current line.
  • dG  Deletes all lines to the end of the file.
  • D  Deletes all words to the end of the line.
  • x  Deletes the current character.
  • nx  Deletes the n characters to the right.
  • nY  Yanks n lines into the buffer.
  • p  Pastes to the right of the cursor.
  • P  Pastes to the left of the cursor.
A separate set of commands, called the ex commands, can be run by using the colon in conjunction with one of these commands:
  • :n  Moves the cursor to line n.
  • :$  Moves the cursor to the end of the file.
  • : s/a/b/g  Replaces all occurrences of string a with string b on the current line.
  • :%s/a/b/g  Replaces all occurrences of string a with string b in the entire file.
  • :wq  Saves the modified file and quits.
  • :q!  Quits without saving any changes.
  • :set  Sets a number of different options.