2011年1月24日星期一

jQuery Plugin Tutorial 2 Pattern

The main jQuery object
=================================================
var jQuery = window.jQuery = window.$ = function(selector, context)
    {
       // ...
       // other internal initialization code goes here
    };
   
=================================================

Internal definition of a jQuery plugin
=================================================
<script type = "text/javascript">
    (function($){ ... })(jQuery);
</script>
=================================================

jQuery Plugin Design Pattern `A`
==================================================
// plugin-name.js - define your plugin implementation pattern
(function($)
             // The $ here signifies a parameter name
             // As you can see from below, (jQuery) is
             // immediately passed as the $ param
{
    $.vari = "$.vari";
    $.fn.vari = "$.fn.vari";

    // 1.) Add a custom interface `DoSomethingLocal`
    //     Which will modify all selected elements!
    //     If you are a software engineer, think about this as
    //     a member function of the main jQuery class
    $.fn.DoSomethingLocal = function()    {
        // return the object back to the chained call flow
        return this.each(function() // This is the main processor
                                    // function that executes on
                                    // each selected element
                                    // (e.g: jQuery("div"))
        {
            // this     ~ refers to a DOM element
            // $(this)  ~ refers to a jQuery object
            // Here, the `this` keyword is a self-refence to the
            // selected object `this.vari` is `undefined` because
            // it refers to selected DOM elements. So, we can do
            // something like: var borderStyle = this.style.border;
            // While $(this).vari, or jQuery(this).vari refers
            // to `$.fn.vari`
            // You would use the $(this) object to perform
            // any desired modification to the selected elements
            // $(this) is simply a reference to the jQuery object
            // of the selected elements
            alert(this.vari);    // would output `undefined`
            alert($(this).vari); // would output `$.fn.vari`
        });
    };
})(jQuery);

// pass the jQuery object to this function
// 2.) Or we can add a custom interface to the global jQuery
//     object. In this case, it makes no sense to enumerate
//     through objects with `each` keyword because this function
//     will theoretically work in the `global` scope. If you are
//     a professional software engineer, think about this
//     as a [static function]
$.DoSomethingGlobal = function(){
    // this will output this.vari = $.vari
    alert("Do Something Globally, where `this.vari` = " + this.vari);
};

// index.html - test the plugin
$(document).ready(function()
{
    $("div").DoSomethingLocal();
    $.DoSomethingGlobal();
});

There are two different types of interfaces you can add to the main jQuery object that is already defined by the framework. Please take a look at the example above where we have just added the function DoSomethingLocal and DoSomethingGlobal.
1.) DoSomethingLocal is defined as $.fn.DoSomethingLocal. You can add as many custom functions to the jQuery.fn (or simply $.fn) object as required by your plugin implementation. Any function you add to the $.fn object is assumed to work on references to an instance of an element/object that was selected. This is what the $.fn syntax means - we are simply adding a custom interface to a jQuery object that assumes selected elements.
2.) DoSomethingGlobal is applied directly to the global jQuery object as $.DoSomethingGlobal. A function attached to the jQuery framework in such way assumes that it will not work on selected elements but rather it will work in the global scope and contain practically any implementation.


jQuery Plugin Design Pattern `B`
==================================================
//It must assume that this plugin functions will not be returning a jQuery object.
// Plugin base object
$.gShuffle = function()
{
}
// Initializes plugin
$.gShuffle.initialize = function()
{
}
// Runs the plugin
$.gShuffle.run = function()
{
};
---------------------------------------------------------
<script type = "text/javascript">
    // One way to initialize plugin code
    $(document).ready(function()    { // on document loaded, it's ready, and next will do the function as
                                                          //  a event handler
        jQuery.Shuffle.initialize( "monalisa.jpg", 5, 8, 67, 1500);
        jQuery.Shuffle.run();
    }
</script>
==================================================

2011年1月17日星期一

XCOPY命令简要

1./E: 目录阶层COPY
      /S:   空目录除外,目录和文件一起COPY
      /T: 只COPY目录结构

 XCOPY FROM_PATH DEST_PATH /E


2./H: 隐藏文件/系统文件 一起COPY

 XCOPY  FROM_PATH DEST_PATH  /H

3./? help

 XCOPY /?

4./EXCLUDE: 除外过滤指定,可以将过滤内容写入文件,指定过滤文件。

 XCOPY FROM_PATH DEST_PATH /EXCLUDE:c:\exclude.txt

除外文件exclude.txt内容(支持后缀和目录):

\obj\
.vb
.scc
.bak
.pdb
.txt
c:\対象外\

————————————————————————————
set module=%1
set frRoot=C:/develop/ut
set toRoot=z:/develop/UT
set logfile=xcopy.log
echo %DATE% %TIME% "======= rsync" %module%>> %logfile%
 
xcopy "%frRoot%/%module%"  "%toRoot%/%module%" /D /S /E /H /C /Y /R >> %logfile%


 ・/D   新しいファイルだけをコピーする
 ・/S /E (空のものも含めて)サブフォルダもコピーする
 ・/H   隠しファイルもコピーする
 ・/C   エラーを無視してコピーする
 ・/Y   無条件上書きコピーする
 ・/R   読み取り専用ファイルもコピーする
    /EXCLUDE

cmdでVSS取得とソースのコンパイル

ソースコンパイル方法:
build Solution Cmd:
devenv.exe C:\TestSolution.sln /build Release /out c:\build.log

rebuild Solution Cmd:
devenv.exe C:\TestSolution.sln /rebuild Release /out c:\rebuild.log

VSS取得方法:
REM set vsserver path (srcsafe.ini path)  for ss.exe
set SSDIR=\\vssserver\vssdb1
REM set local file path
set GETPATH=C:\localVss
REM set rootPath on VSS

set VSSROOT=$/
REM get files from vss. -option pamameter has no space with param value,
ss.exe Get %VSSROOT% -GL%GETPATH% -R -I-Y -Q -Y[VSS_USER],[VSS_PASS]

-GL は取得するファイルを指定ローカルパス(ディフォルトパスではなく)に保存する。

オプション 説明
-C 指定されたすべての項目に共通のコメントを適用します。Directory コマンドでは、このオプションには別の機能が割り当てられています。
-O 結果情報の出力方法を、画面単位またはリダイレクトに指定します。
-V 項目の特定のバージョンを操作対象にします。
-R 指定された項目以下の全階層にコマンドを実行します。
-S SmartMode のオン/オフを切り替えます。
-G ローカル ドライブに取得したファイルを処理する Get コマンドの動作を変更します。
-W ローカル コピーを読み取り専用にするかどうかを指定します。
-N 長いファイル名または短いファイル名のどちらを使用するかを指定します。
-I- ユーザーへの入力要求が一切行われないようにします。
-Y ユーザー名とパスワードを指定します。
-?、-H オンライン ヘルプを表示します。-? と -H のいずれかを指定します。


SAMPLE:
REM ==============================
@echo off
echo 作業ディレクトリを作成中...
set workdir=C:\Work\App
REM /s 指定したディレクトリとそのすべてのサブディレクトリを、
REM    その中のすべてのファイルも含めて削除します。ツリーを削除するには /s を使用します。
REM /q rmdir を Quiet モードで実行します。確認メッセージを表示せずに、ディレクトリを削除します。
if exist %workdir% rmdir %workdir% /s /q
mkdir %workdir%
cd "%workdir%"
echo ソリューションの取得中...
set path=%path%;C:\Program Files\Microsoft Visual Studio\VSS\win32\
set ssUser=wang.xiaoguang
set ssPwd=
set ssDir=\\Server\VSS\App
REM バージョンラベルを指定してソリューションを取得する
REM ss Get "$/Root/App" -W -R -I-Y -GL%workdir% "-VL Version 1.1 Beta"
ss Get "$/Root/App" -W -R -I-Y -GL%workdir%
if errorlevel 100 goto VssBigErr
if errorlevel 1 goto VssSmallErr
echo ソリューションの取得が完了しました!
echo ビルドの実行中...
set path=%path%;C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\
devenv %workdir%\App.sln /rebuild Release  /out %workdir%\build.log
REM errlorlevelを返さないためReleaseフォルダが作成されたかで確認
if not exist %workdir%App1\bin\Release goto vsneterr
if not exist %workdir%App2\bin\Release goto vsneterr
echo 正常にソリューションのビルドが完了しました!
pause
exit 0
REM -------------------------------------------
:VssBigErr
echo ss.exe エラーレベル=100。問題が発生しました。データ ファイルが見つからない、
echo チェックアウトしようとしたファイルが既にチェックアウトされている、などの原因が考えられます。
echo ソリューションの取得でエラーが発生したので処理を中断しました!
pause
exit 100
:VssSmallErr
echo ss.exe エラーレベル=1。軽度のエラーです。これは、次のいずれかの状況で起こります。
echo ss Dir を実行しても項目が見つからない場合。
echo ss Status を実行したとき、少なくとも 1 つの項目がチェックアウトされている場合。
echo ss Diff を実行したとき、少なくとも 1 つのファイルが異なっている場合。
echo いずれの場合も、このコマンドが正常終了しても、次のコマンドが失敗するおそれがあります。
echo ソリューションの取得でエラーが発生したので処理を中断しました!
pause
exit 200
:vsneterr
echo ソリューションのビルドでエラーが発生したので処理を中断しました!
pause
exit 300

REM ==============================

2011年1月14日星期五

PowerShell 文件系统处理命令

文件系统处理命令集

命令简化命令说明
Get-ChildItemgci, ls, dir  指定目录的文件一览列表

命令简化命令说明
Add-Contentac向指定文件追加内容
Clear-Contentclc清除文件内容
Get-Contentgc, cat, type取得文件内容
Set-Contentsc覆盖文件内容
New-Itemni做新文件

命令简化命令说明
Move-Itemmi, mv, move移动文件
Remove-Itemri, rm, rmdir, del, erase, rd删除文件
Copy-Itemcpi, cp, copy复制文件
Rename-Itemrni, ren文件重命名

命令简化命令说明
Get-Locationgl, pwd取得现在目录
Pop-Locationpopd目录堆栈推出pop
Push-Locationpushd目录堆栈压入push
Set-Locationsl, cd, chdir目录变更

2011年1月13日星期四

DataTable的列顺序调整

DataTable的Columns属性是DataColumnColllection,
有个方法是SetOrdinal(int index),可以调整列顺序或者位置。
应该注意的是,index应该是从0开始的。

2011年1月12日星期三

Oracle/PLSQL: Execute an SQL script file in SQLPlus

Question: How do I execute an SQL script file in SQLPlus?



Answer: To execute a script file in SQLPlus, type @ and then the file name.

SQL > @{file}

For example, if your file was called script.sql, you'd type the following command at the SQL prompt:

SQL > @script.sql

The above command assumes that the file is in the current directory. (ie: the current directory is usually the directory that you were located in before you launched SQLPlus.)



If you need to execute a script file that is not in the current directory, you would type:

SQL > @{path}{file}

For example:

SQL > @/oracle/scripts/script.sql

This command would run a script file called script.sql that was located in the /oracle/scripts directory.

2011年1月7日星期五

Javascript Regex

JavaScriptのregexpオブジェクトfunctionオブジェクトの生成書式 用途 IE NN
var=new RegExp(patern[,flag]) 正規表現オブジェクトを生成。 4 4
例:
var reg = new RegExp(/display\s*:\s*none\s*;/i)
reg.ignoreCase = true;
if(reg.test(s))alert("OK");
フラグと正規表現部のチェック名前 用途 IE NN
var.ignoreCase iフラグ(/.../i)が指定されているかどうかを真偽値で返す。 5.5 4
var.global gフラグ(/.../g)が指定されているかどうかを真偽値で返す。
var.source 正規表現部(/.../)を示す文字列を返す。 4 4
マッチング名前 用途 IE NN
var.(str) マッチングにマッチした部分の文字列を返す。
gフラグ指定時は配列を返す。 × 4
var.exec([str]) strを省略した場合は、
RegExp.inputで指定された文字列にマッチングを行う。 4 4
str.match(regexp) var.(str)と同じ。
var.compile(patern[,flag]) 正規表現を内部表現形式にコンパイルし、高速化する。
RegExp.input exec()でマッチングの対象とする文字列を代入。省略記号は$_
var.test(str) マッチングにマッチしたかどうかを真偽値で返す。 × 4
RegExp.multiline 複数行に対するマッチング。省略記号は$* 5.5 4
マッチングの結果名前 用途 IE NN
RegExp.$n 直前の正規表現マッチングの、n番目の (...) に対応する文字列を返す。 4 4
RegExp.index マッチした開始位置を返す。 4 ×
RegExp.lastIndex マッチした部分の次の位置を返す。
var.lastIndex × 4
RegExp.lastMatch 直前のマッチングの、最後にマッチした文字列を返す。省略記号は$& 5.5 4
RegExp.leftContext 直前のマッチングの、マッチした部分よりも左側の文字列を返す。省略記号は$`
RegExp.rightContext 直前のマッチングの、マッチした部分よりも右側の文字列を返す。省略記号は$"
RegExp.lastParen 直前のマッチングの、最後の (...) に対応する文字列を返す。省略記号は$+
正規表現の書式正規表現 意味
X 文字X。
XYZ 文字列XYZ。
[XYZ] XYZのどれか1文字。
[X-Z] XからZまでの1文字。
[^XYZ] XYZのどれでもない任意の1文字。
. 任意の1文字。
X+ 1文字以上のX。
X* 0文字以上のX。
X? 0文字か1文字のX。
^X Xで始まる文字列。
X$ Xで終わる文字列。
XXX|YYY|ZZZ XXXかYYYかZZZ。
X{2} 2個のX。
X{2,} 2個以上のX。
X{2,3} 2個以上3個以下のX。
[\B] バックスペース。

記号 意味
\b スペースなどの単語の区切り。
\B \b以外の文字。
\cA Ctrl+A。
\d 任意の数値。
\D 数値以外の文字。
\f フォームフィード文字。
\n 改行文字。
\r 復帰文字。
\s 1文字の区切り文字。
\S \s以外の1文字。
\t タブ文字。
\v 垂直タブ文字。
\w 英数文字。
\W 英数文字。
\2 2番目の(...)にマッチした文字列。
\o033 8進数033の文字。
\x1b 16進数1bの文字。
\その他 その他の文字自身。

フラグ 意味
i 大文字・小文字を区別しない。
g 2番目、3番目...にマッチする部分も検索。
m 複数行に対して検索。