Category Archives: Uncategorized

Maven – different between -DskipTests and -Dmaven.test.skip=true

sometime when we build maven, junit will also be invoked to test code.

usually, these unit test will fail because of development machine configures are different.

there are two commands which could skip test.

1
2
$ mvn package -DskipTests
$ mvn package -Dmaven.test.skip=true

“-DskipTests” is to build test source code but don’t run them.
“-Dmaven.test.skip=true” don’t do anything for test source code, do not compile and do not run for test code.

google chart api for marker pin

In our project on google map, we have to display some custom marker pins use png.

google api provide great function for this purposes.
Here is a example URL
https://chart.googleapis.com/chart?chst=d_map_spin&chld=0.3|0|78909A|13|b|
you could change scale 0.3 to any size with fill in color 78909A,
font size 13 is for font to put into pin text

click on the url to view excellent markers.

radgrid

var grid = $find(“<%=RadGrid1.ClientID %>“);
var ctrl_hiddenfield = $telerik.findControl(grid.get_element(),”hiddenfield_name”);

http://docs.telerik.com/devtools/aspnet-ajax/controls/listbox/client-side-programming/overview

libtar and its api

libtar is small but effective library, although it has some bugs when dealing with long path.

The Steps are following:
download libtar-1.2.11 and uncompress it, the main path is /path/libtar-1.2.11

build with command “./configure && make”, if you want to debug, add “-g” for gcc to build.

make “test” folder “/path/libtar-1.2.11/test”. find header file and libtar.a file

put 1.c in “/path/libtar-1.2.11/test”

so finally, the build command will be “g++ 1.c -o 1 ../lib/libtar.a -I ../bin/libtar-1.2.11/include”

some important code, for example, char* subfile1 = “./sub1/1.txt”
this is for file under sub folder.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
 #include <tar.h>  
 #include <libtar.h>  
 #include <iostream>                                                             
 #include <fcntl.h>    
 
 using namespace std;                               
 
 int main(){                                                        
     // tar                         
     if(1){                                                          
         TAR* tar_handle;
         char* tar_fname = "test.tar";
         tar_open(&amp;tar_handle, tar_fname, NULL,  O_WRONLY | O_CREAT,  0644,  TAR_GNU);
         char* subfile1 = "./sub1/1.txt";
         tar_append_file(tar_handle, subfile1,  subfile1);
         char* subfile2 = "test1.c";
         tar_append_file(tar_handle, subfile2,  subfile2);
         tar_close(tar_handle);
     }
 
     // untar
     if(0){
         TAR* tar_handle;
         char* tar_fname = "test.tar";
         tar_open(&amp;tar_handle, tar_fname, NULL,  O_RDONLY,  0644,  TAR_GNU);
         char* savefold = "temp";
         tar_extract_all(tar_handle, "temp");
         tar_close(tar_handle);
     }
 
     return 0;
 }

example of jquery bxslider

Here is a full example of how to use bxslider to show image slider.

bxslider is also very good at fade in/out transition in div

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<html>
  <title></title>
  <head>
    <!-- jQuery library (served from Google) -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<!-- bxSlider Javascript file -->
<script src="jquery.bxslider.min.js"></script>
<!-- bxSlider CSS file -->
<link href="jquery.bxslider.css" rel="stylesheet" />
 
<script language="javascript">
$(document).ready(function(){
$('.bxslider').bxSlider({
  mode: 'fade',
  captions: true
});
});
</script>
  </head>
 
  <body>
    <ul class="bxslider">
  <li><img src="pic1.jpg" /></li>
  <li><img src="pic2.jpg" /></li>
  <li><img src="pic3.jpg" /></li>
</ul>
  </body>
</html>

rdesktop , RDP for linux

use rdesktop to connect to windows desktop

currently reading rdesktop source code to see RDP protocol. It is excellent stable in linux to control windows remotely.

1
   $ rdesktop -g 80% -x l ip-address &

-g 80% means the window of rdesktop will not pop up with full screen but with 80% of full screen.

PsExec remote Invoke Command

Without Configuration, PsExec could not execute successfully.

copy the following text and saved into .reg file in target machine:

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System]
“LocalAccountTokenFilterPolicy”=dword:00000001

 

Then PsExec could run successfully.

Repeated DNA Sequences

Repeated DNA Sequences Total Accepted: 8816 Total Submissions: 47451 My Submissions Question Solution
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: “ACGAATTCCG”. When studying DNA, it is sometimes useful to identify repeated sequences within the DNA.

Write a function to find all the 10-letter-long sequences (substrings) that occur more than once in a DNA molecule.

For example,

Given s = “AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT”,

Return:
[“AAAAACCCCC”, “CCCCCAAAAA”].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
 
import java.util.*;
public class RepeatedDNASequences {
    public static List<String> findRepeatedDnaSequences(String s) {
 
        ArrayList<String> result = new ArrayList<String>();
 
        if(s== null || s.length() == 0) return result;
 
        HashMap<Character,Integer> map = new HashMap<Character,Integer>();
        map.put('A',0);
        map.put('C',1);
        map.put('G',2);
        map.put('T',3);
 
        HashSet<Integer> hashSet = new HashSet<Integer>();
        Set<Integer> unique = new HashSet<Integer>();
 
        int temp = 0;
        for(int i=0;i<s.length();i++){
            /*temp = 0;
              for(int j=0;j<10;j++){
              temp = (temp<<2) + map.get(s.charAt(i+j));
              }*/
            if(i<9){
                temp = (temp<<2) + map.get(s.charAt(i));
                // System.out.println(temp);
            }
            else{
                temp = (temp<<2) + map.get(s.charAt(i));
                temp &amp;= (1<<20) - 1;
                System.out.println(temp);
                if(hashSet.contains(temp) &amp;&amp; !unique.contains(temp)){
                    result.add(s.substring(i-9,i+1));
                    unique.add(temp);
                }
                else {
                    hashSet.add(temp);
                }
            }
        }
 
        return result;
    }
 
    public static void main(String[] args) {
        String s = "AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT";
        System.out.println(findRepeatedDnaSequences(s));
    }
}