Friday, March 11, 2011

Asurion interview(write a code sample)

THe hiring procedure includes HR interview, Engineer interview, write three codes. I just descript 3 code questions and my answer below.

1. Write a function in JAVA, which input a int array and return a int. The result int  means one of the index of array. The index let the sum of left side equal with right side. The function can find a index. For example, intput a array{-1, 7, 3, 2,4} and result is 2. becasue array[2] = 3. The left side is –1+7 = 6. The right side is 2+4=6.

private int equi(int[] A){
   int left=0;
   int right = 0;
   int k=0;
   if(A.length ==1){
      return 0;
   }
 
   for(int i=1; i<A.length; i++){
       right += A[i]; 
    }
   for(int i=0; i< A.length; i++){
       if(left == right){
            return k;
       }
       left +=A[i];
       right = right-A[i+1];
       k=i+1;
     }
     return -1;
}



2. Write a function in JAVA. The function should find a gap in the binary array……

private int binary_gap(int n){
   Integer integer = new Integer(n);
   String binaryString= integer.toBinaryString(n);
   int length = binaryString.length();
   int gap=0;
   int gap_Max=0;
   for(int i=0; i<length; i++){
      if(binaryString.substring(i, i+1).equals("0")){   
         gap++;
      }else{
         if(gap>gap_Max){
            gap_Max = gap;
         }
         gap=0;
      }
   }
   return gap_Max;
}


3. write a function in Javascript. Input is a string. For example,
’asurion’
0 –> ’asurion’
1 –>’suriona’
2 –>’urionas’
3 –>’rionasu’
4 –>’ionasur’


function cyclic_automorphisms(ori) {
        var temp = ori;
        var automorphisms=0;
        for (i = 1; i < ori.length; i++) {
            temp = ori.substring(i, ori.length) + ori.substring(0, i);
            if (ori.match(temp) == ori) {
                automorphisms = i-1;
            }
        }
        return automorphisms;
 }

Friday, November 26, 2010

window7 使用者資料夾權限

進入使用者下的目錄如: Application Data, Local Settings等 會出現"無法存取,存取被拒",解決方法有二
第一種. 調整目錄的傭有者,預設是"system",調整為目前的使用者即可
資料夾上按右鍵,選"內容"->"安全性","進階"–>"擁有者"
第二種. 把everyone從目錄安全性內中刪除

Tuesday, May 25, 2010

subversion安裝使用

1. apache註冊為windows service
C:\Program Files\Apache Software Foundation\Apache2.2\bin>httpd.exe -k install

2. 分支
參考http://blog.yam.com/keithmin/article/8360958
http://blog.miniasp.com/category/Subversion.aspx

一般講到分支都會以trunk, tags, branches這三個名詞來解釋,但建立一個repository後,repository不會包含了trunk, tags, branches等三個虛擬目錄,之後在說一下怎麼建立,不過建起來後這三個目錄是包含在svn的DB中,在repository的file system中是看不到的。

httpd.conf的配置

   1: <Location /svn>


   2:     DAV svn


   3:     SVNParentPath "D:\projects"


   4: </Location>








專案區的配置



image















































先由專案區的trunk複製到repository的branches





Copy D:\test\trunk to http://localhost:8080/svn/project01/branches/kkk-branch


在TortoiseSVN中就是點選”branch/tag” 就會執行copy這個指令了,要注意的是branches這個虛擬目錄還未建立,這點我沒注意到,一直出現 '/svn/project01/!svn/bc/10/branches' path not found。可以用Copy D:\test\trunk to http://localhost:8080/svn/project01/branches 先建立了branches這個虛擬目錄,或是在Repository Browser中create director,在重新輸入Copy D:\test\trunk to http://localhost:8080/svn/project01/branches/kkk-branch,才建立好分支。




建立好分支後,再照著上面兩個參考網址,作就差不多。



選擇merge時,在tortoise中有三種type:

1. merge a range of revisions: 從trunk update至branch


2. reintegrate a branch: 把branch合併至trunk


    From URL: 填入branch的repository的位置


    working copy: 則是 trunk的工作區位置


3. merge two different trees:

Friday, May 21, 2010

windows 遠端連線

使用同一個帳號,不同電腦登入時會是兩個不一樣的環境,切換方法
1. run-> taskmgr –>“使用者” , 可以看到目前的使用者有哪些
    右鍵->連線,即可讓畫面切換過去

2. run->tsadmin, 可以看到目前的使用者有哪些
    右鍵->連線,即可讓畫面切換過去

不管是切換畫面或是強制登出都可以用這兩個指令

Monday, February 1, 2010

安裝Windows7

"遺失必要的CD/DVD磁碟裝置驅動程式”
安裝Windows7時出現"遺失必要的CD/DVD磁碟裝置驅動程式
安裝的時候卡卡的,換了一台外接光碟機就沒這問題….

切割硬碟的時候,多了˙一個系統檔案保留區約100MB

增加滑鼠右鍵選單
$ regedit  -> HKEY_LOCAL_MACHINE→SOFTWARE→Classes→*
在此新增一個〔機碼〕名為〔Shell〕
在〔Shell〕下再新增加一個〔機碼〕名為〔UltraEdit〕
將〔UltraEdit〕的預設值的數值資料改為〔UltraEdit開啟〕
再在〔UltraEdit〕下再新增一個〔機碼〕名為〔Command〕
將〔Command〕的預設值的數值資料改為〔c:/xxxxx/xxxx/uedit32.exe %1〕

Thursday, January 14, 2010

mysql秒數轉時間

秒數以1970-01-01 00:00:00為基準,在加上距離至現在的秒數

秒數轉時間:FROM_UNIXTIME(‘欄位名稱’)

時間轉秒數:SELECT UNIX_TIMESTAMP( '2010/01/01 11:11:11' )

Tuesday, September 1, 2009

jquery1.32- select, radio

1. 找到被選取的radio項目

val checkedvalue = $('input[name="namevalue"][checked="true"]:first).val();



2.由程式設定被選取的radio



$("input[name='namevalue']").each(function(){
if($(this).val() == somevalue){
$(this).attr('checked','true');
}
});



3. 由程式設定被選取的select,根radio差不多,checked改成selected



4. 找到被選取的select項目



var selectvalue = $("#selectID").val();