This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Protocol : //[user: password]@host[:port]/path /[?query][#fragment] | |
| public static Pattern UrlPatt = Pattern | |
| .compile( | |
| "(?<protocol>.*?)://(?<loginfo>(?<user>.*?):(?<pwd>.*?)@)?(?<host>[^/]+)(?:(?<path>/[^\\?#]*)(?<query>\\?[^#]+)?)?(?<frag>#.*)?", | |
| Pattern.CASE_INSENSITIVE); | |
| public static void testUrlPatt() { | |
| String[] urls = { | |
| "https://www.google.com.hk/search?q=named+group+regex+java&oq=named+group+regex+java&aqs=chrome.0.57.5777j0&sourceid=chrome&ie=UTF-8#abc", | |
| "http://wfwei.github.io/posts/regex/#abc", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ArrayList<String> list = new ArrayList<String>(); | |
| list.add("a"); | |
| list.add("b"); | |
| list.add("c"); | |
| System.out.println(list.size()); | |
| // This will fail | |
| // for (String item : list) { | |
| // list.remove(item); | |
| // } | |
| Iterator<String> iter = list.iterator(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| static class WordToName implements Comparable<WordToName> { | |
| private String word; | |
| private List<String> docNames; | |
| public WordToName(String word) { | |
| this.word = word; | |
| this.docNames = new ArrayList<String>(); | |
| } | |
| @Override |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static void changIP() { | |
| try { | |
| System.out.println("Disconnecting..."); | |
| Runtime.getRuntime().exec("rasdial myVpn /disconnect"); | |
| System.out.println("Sleep for 10 seconds"); | |
| Thread.sleep(10000); | |
| System.out.println("Connectiong.."); | |
| Runtime.getRuntime().exec("rasdial myVpn wfwei wangfengwei"); | |
| System.out.println("Over"); | |
| } catch (Exception e) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include<stdio.h> | |
| #include<stdlib.h> | |
| // return random num:0-6 | |
| int Rand7(){ | |
| return rand()%7; | |
| } | |
| int Rand10(){ | |
| int rand71, rand72, rand10; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include<stdio.h> | |
| #define bitVal(n, i) (((n) & (1 << (i)))>0?1:0) | |
| void findTwoSingleNum(int *A, int len, int fiterBit, int filterVal, int AorB){ | |
| int i, j, Aval=0, Bval=0; | |
| for(j=0; j<sizeof(int); j++){ | |
| if(bitVal(AorB, j)) | |
| break; | |
| } | |
| for(i=0; i<len; i++){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "stdio.h" | |
| #include "stdlib.h" | |
| // 判断一个数字序列是BST后序遍历的结果 | |
| // 认为没有重复元素 | |
| bool isBST(int *A, int s, int e){ | |
| if(A==NULL) | |
| return 0; | |
| bool bst = true; | |
| int root = A[e], ls, le, rs, re; | |
| rs = e; re = e-1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "stdio.h" | |
| #include "stdlib.h" | |
| int getMaxIdx(int *A, int len){ | |
| int low=0, high=len-1, mid; | |
| while(low<high){ | |
| mid = low + (high-low + 1)/2; | |
| if(A[mid]>A[low]) | |
| low = mid; | |
| else |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "stdio.h" | |
| #include "stdlib.h" | |
| int * merge(int*A, int *B, int len){ | |
| int *C = (int *)malloc(sizeof(int)*len*2); | |
| int ai, bi, ci; | |
| if(A==NULL || B==NULL || C==NULL) | |
| return NULL; | |
| for(ai=0, bi=0, ci=0; ai<len&&bi<len; ){ | |
| if(A[ai]<=B[bi]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include<stdio.h> | |
| #include<math.h> | |
| #define THRESHOLD 0.0000001 | |
| bool found = false; | |
| void swap(double *a, double *b){ | |
| double tmp = *a; | |
| *a = *b; |