diff --git a/CountMostImport/.classpath b/CountMostImport/.classpath new file mode 100644 index 0000000..fceb480 --- /dev/null +++ b/CountMostImport/.classpath @@ -0,0 +1,6 @@ + + + + + + diff --git a/CountMostImport/.project b/CountMostImport/.project new file mode 100644 index 0000000..6deeb54 --- /dev/null +++ b/CountMostImport/.project @@ -0,0 +1,17 @@ + + + CountMostImport + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/CountMostImport/.settings/org.eclipse.jdt.core.prefs b/CountMostImport/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/CountMostImport/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/CountMostImport/bin/CountMostImport.class b/CountMostImport/bin/CountMostImport.class new file mode 100644 index 0000000..414738e Binary files /dev/null and b/CountMostImport/bin/CountMostImport.class differ diff --git a/CountMostImport/src/CountMostImport.java b/CountMostImport/src/CountMostImport.java new file mode 100644 index 0000000..23867e1 --- /dev/null +++ b/CountMostImport/src/CountMostImport.java @@ -0,0 +1,76 @@ +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class CountMostImport { + private static Map out = new HashMap(); + public static void main(){ + String path = ""; + File new_file = new File(path); + DepthSearch(new_file, out); + CountMostImport10(out); + } + + + + private static void DepthSearch(File s, Map out){ + if(s.isDirectory()){ + File[] files = s.listFiles(); + if(files.length != 0){ + for(File file:files){ + DepthSearch(file,out); + } + } + } + else{ + try{ + CalImport(s, out); + }catch(Exception ex){ + System.out.println("error reading files!"); + } + + } + + } + + private static void CalImport(File file, Map out) throws IOException{ + BufferedReader in = new BufferedReader(new FileReader(file)); + String read_string; + while((read_string = in.readLine()) != null){ + if(read_string.startsWith("package")){ + continue; + } + if(read_string.startsWith("import")){ + String m_s = read_string.replaceAll("\\.", " "); + String regex = "import .+?(\\S+);"; + Matcher matcher = Pattern.compile(regex).matcher(m_s); + matcher.find(); + Integer count = out.get(matcher.group(1)); + if(count == null){ + out.put(matcher.group(1), 1); + }else{ + out.put(matcher.group(1), count++); + } + } + else break; + } + + } + + private static void CountMostImport10(Map out){ + int count = 0 ; + for(String i: out.keySet()) + { + if(count == 10) + break; + System.out.println(i + ":" + out.get(i)); + count++; + } + + } + +} diff --git a/EffectiveLines/.DS_Store b/EffectiveLines/.DS_Store new file mode 100644 index 0000000..7bc8fc8 Binary files /dev/null and b/EffectiveLines/.DS_Store differ diff --git a/EffectiveLines/EffectiveLines.class b/EffectiveLines/EffectiveLines.class new file mode 100644 index 0000000..ed8d997 Binary files /dev/null and b/EffectiveLines/EffectiveLines.class differ diff --git a/EffectiveLines/EffectiveLines.java b/EffectiveLines/EffectiveLines.java new file mode 100644 index 0000000..2ed4f5e --- /dev/null +++ b/EffectiveLines/EffectiveLines.java @@ -0,0 +1,37 @@ +import java.util.*; +import java.io.*; + +public class EffectiveLines +{ + public static void main(String[] args)throws IOException + { + System.out.println(read("test.java")); + } + public static String read(String filename) throws IOException + { + BufferedReader in = new BufferedReader(new FileReader(filename)); + String s; + int result = 0; + boolean comment = false; + + while((s = in.readLine()) != null) + { + s = s.trim(); + if(s.matches("^[//s&&[^//n]]*$")) { + continue; + } + else if(s.startsWith("/*") && !s.endsWith("*/")) { + comment = true; + }else if (true == comment){ + if (s.endsWith("*/")) { + comment = false; + } + }else if(s.startsWith("//")) { + continue; + }else{ + result++; + } + } + return Integer.toString(result); + } +} diff --git a/ExchangeRate/.DS_Store b/ExchangeRate/.DS_Store new file mode 100644 index 0000000..9b8e299 Binary files /dev/null and b/ExchangeRate/.DS_Store differ diff --git a/ExchangeRate/.classpath b/ExchangeRate/.classpath new file mode 100644 index 0000000..4e948f9 --- /dev/null +++ b/ExchangeRate/.classpath @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/ExchangeRate/.project b/ExchangeRate/.project new file mode 100644 index 0000000..0a703b9 --- /dev/null +++ b/ExchangeRate/.project @@ -0,0 +1,17 @@ + + + work2 + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/ExchangeRate/.settings/org.eclipse.jdt.core.prefs b/ExchangeRate/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..3a21537 --- /dev/null +++ b/ExchangeRate/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.8 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/ExchangeRate/bin/.DS_Store b/ExchangeRate/bin/.DS_Store new file mode 100644 index 0000000..3fd20e3 Binary files /dev/null and b/ExchangeRate/bin/.DS_Store differ diff --git a/ExchangeRate/bin/work2/my_work.class b/ExchangeRate/bin/work2/my_work.class new file mode 100644 index 0000000..8bd77f1 Binary files /dev/null and b/ExchangeRate/bin/work2/my_work.class differ diff --git a/ExchangeRate/out.xls b/ExchangeRate/out.xls new file mode 100644 index 0000000..0b1be85 Binary files /dev/null and b/ExchangeRate/out.xls differ diff --git a/ExchangeRate/src/.DS_Store b/ExchangeRate/src/.DS_Store new file mode 100644 index 0000000..89c4a31 Binary files /dev/null and b/ExchangeRate/src/.DS_Store differ diff --git a/ExchangeRate/src/work2/commons-codec-1.10.jar b/ExchangeRate/src/work2/commons-codec-1.10.jar new file mode 100644 index 0000000..1d7417c Binary files /dev/null and b/ExchangeRate/src/work2/commons-codec-1.10.jar differ diff --git a/ExchangeRate/src/work2/commons-io-2.5.jar b/ExchangeRate/src/work2/commons-io-2.5.jar new file mode 100644 index 0000000..107b061 Binary files /dev/null and b/ExchangeRate/src/work2/commons-io-2.5.jar differ diff --git a/ExchangeRate/src/work2/commons-lang3-3.4.jar b/ExchangeRate/src/work2/commons-lang3-3.4.jar new file mode 100644 index 0000000..8ec91d4 Binary files /dev/null and b/ExchangeRate/src/work2/commons-lang3-3.4.jar differ diff --git a/ExchangeRate/src/work2/commons-logging-1.2.jar b/ExchangeRate/src/work2/commons-logging-1.2.jar new file mode 100644 index 0000000..93a3b9f Binary files /dev/null and b/ExchangeRate/src/work2/commons-logging-1.2.jar differ diff --git a/ExchangeRate/src/work2/cssparser-0.9.19.jar b/ExchangeRate/src/work2/cssparser-0.9.19.jar new file mode 100644 index 0000000..91c4cbf Binary files /dev/null and b/ExchangeRate/src/work2/cssparser-0.9.19.jar differ diff --git a/ExchangeRate/src/work2/htmlunit-2.22.jar b/ExchangeRate/src/work2/htmlunit-2.22.jar new file mode 100644 index 0000000..e7cfe07 Binary files /dev/null and b/ExchangeRate/src/work2/htmlunit-2.22.jar differ diff --git a/ExchangeRate/src/work2/htmlunit-core-js-2.22.jar b/ExchangeRate/src/work2/htmlunit-core-js-2.22.jar new file mode 100644 index 0000000..6bc4c1c Binary files /dev/null and b/ExchangeRate/src/work2/htmlunit-core-js-2.22.jar differ diff --git a/ExchangeRate/src/work2/httpclient-4.5.2.jar b/ExchangeRate/src/work2/httpclient-4.5.2.jar new file mode 100644 index 0000000..701609f Binary files /dev/null and b/ExchangeRate/src/work2/httpclient-4.5.2.jar differ diff --git a/ExchangeRate/src/work2/httpcore-4.4.4.jar b/ExchangeRate/src/work2/httpcore-4.4.4.jar new file mode 100644 index 0000000..ac4a877 Binary files /dev/null and b/ExchangeRate/src/work2/httpcore-4.4.4.jar differ diff --git a/ExchangeRate/src/work2/httpmime-4.5.2.jar b/ExchangeRate/src/work2/httpmime-4.5.2.jar new file mode 100644 index 0000000..474670a Binary files /dev/null and b/ExchangeRate/src/work2/httpmime-4.5.2.jar differ diff --git a/ExchangeRate/src/work2/jetty-io-9.2.17.v20160517.jar b/ExchangeRate/src/work2/jetty-io-9.2.17.v20160517.jar new file mode 100644 index 0000000..7c6f8ea Binary files /dev/null and b/ExchangeRate/src/work2/jetty-io-9.2.17.v20160517.jar differ diff --git a/ExchangeRate/src/work2/jetty-util-9.2.17.v20160517.jar b/ExchangeRate/src/work2/jetty-util-9.2.17.v20160517.jar new file mode 100644 index 0000000..5337754 Binary files /dev/null and b/ExchangeRate/src/work2/jetty-util-9.2.17.v20160517.jar differ diff --git a/ExchangeRate/src/work2/jsoup-1.9.2.jar b/ExchangeRate/src/work2/jsoup-1.9.2.jar new file mode 100644 index 0000000..720b761 Binary files /dev/null and b/ExchangeRate/src/work2/jsoup-1.9.2.jar differ diff --git a/ExchangeRate/src/work2/jxl.jar b/ExchangeRate/src/work2/jxl.jar new file mode 100755 index 0000000..b210c06 Binary files /dev/null and b/ExchangeRate/src/work2/jxl.jar differ diff --git a/ExchangeRate/src/work2/my_work.java b/ExchangeRate/src/work2/my_work.java new file mode 100644 index 0000000..a91056a --- /dev/null +++ b/ExchangeRate/src/work2/my_work.java @@ -0,0 +1,220 @@ +package work2; + +import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.io.*; +import java.net.URI; + +import org.apache.http.HeaderIterator; +import org.apache.http.HttpEntity; +import org.apache.http.HttpHost; +import org.apache.http.HttpResponse; +import org.apache.http.client.ClientProtocolException; +import org.apache.http.client.ResponseHandler; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.client.protocol.HttpClientContext; +import org.apache.http.client.utils.URIUtils; +import org.apache.http.impl.client.CloseableHttpClient; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.impl.client.LaxRedirectStrategy; +import org.apache.http.util.EntityUtils; + +import org.jsoup.*; +import org.jsoup.helper.Validate; +import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; +import org.jsoup.select.Elements; + +import com.gargoylesoftware.htmlunit.WebClient; +import com.gargoylesoftware.htmlunit.html.HtmlPage; + +import jxl.Workbook; +import jxl.write.Label; +import jxl.write.WritableSheet; +import jxl.write.WritableWorkbook; + +public class my_work { + public static void main(String[] args)throws IOException + { +//htmlunit+jsoup + + final WebClient wc = new WebClient(); + wc.getOptions().setJavaScriptEnabled(true); //启用JS解释器,默认为true + wc.getOptions().setCssEnabled(false); //禁用css支持 + wc.getOptions().setThrowExceptionOnScriptError(false); //js运行错误时,是否抛出异常 + wc.getOptions().setTimeout(10000); //设置连接超时时间 ,这里是10S。如果为0,则无限期等待 + final HtmlPage pages = wc.getPage("http://www.pbc.gov.cn/zhengcehuobisi/125207/125217/125925/index.html"); + String pageXmls = pages.asXml(); //以xml的形式获取响应文本 + //System.out.println(pageXmls); + + //jsoup解析文档 + Document docs = Jsoup.parse(pageXmls); + Elements links = docs.select("[height = 22]").select("[align = left]").select("a[href]"); + //System.out.println(links.size()); + //System.out.println(" " + links2.size()); + + String[] out_href = new String[30]; + int i = 0; + for(Element link : links) + { + if(i > 29) + break; + + //System.out.println(link.toString()); + String linkhref = link.attr("href"); + //System.out.println(linkhref); + String new_link = "http://www.pbc.gov.cn"+linkhref; + //System.out.println(new_link); + out_href[i] = new_link; + i++; + } + + if(i != 29) + { + Elements link = docs.select("a[tagname]").select("[style=cursor:pointer]"); + //System.out.println(link.size()); + Element m_link = link.first(); + String m_href = m_link.attr("tagname"); + String new_m_href = "http://www.pbc.gov.cn" + m_href; + final HtmlPage page = wc.getPage(new_m_href); + String pageXml = page.asXml(); + Document doc = Jsoup.parse(pageXml); + Elements all_links = doc.select("[height = 22]").select("[align = left]").select("a[href]"); + for(Element tmp : all_links) + { + if(i > 29) + break; + String linkhref = tmp.attr("href"); + String new_link = "http://www.pbc.gov.cn"+linkhref; + out_href[i] = new_link; + i++; + } + } + + String[] output = new String[30]; + int out_put_i = 0; + + for(String new_link : out_href) + { + final HtmlPage page = wc.getPage(new_link); + String pageXml = page.asXml(); + Document doc = Jsoup.parse(pageXml); + //System.out.println(doc.toString()); + //System.out.println(doc.title()); + Elements contents = doc.select("[class = content]"); + //System.out.println(contents.size()); + //System.out.println(contents.text()); + output[out_put_i] = contents.text(); + out_put_i++; + } + + /* + for(String tmp:output) + { + System.out.println(tmp); + } + */ + + regex_analyse_excel_out(output); + + + + + +/* httpclient+jsoup test1 + CloseableHttpClient client = HttpClients.createDefault(); + String url = "http://www.pbc.gov.cn/zhengcehuobisi/125207/125217/125925/index.html"; + HttpGet httpGet = new HttpGet(url); + HttpResponse response = client.execute(httpGet); + + HeaderIterator it = response.headerIterator("Set-Cookie"); + while (it.hasNext()) { + System.out.println(it.next()); + } + + httpGet.addHeader("Set-Cookie","wzwsconfirm=798c50164cd669a4c1ccc40c1c759944; path=/"); + response = client.execute(httpGet); + + int statusCode = response.getStatusLine().getStatusCode(); + System.out.println("执行状态码 : " + statusCode); + HttpEntity entity = response.getEntity(); + System.out.println(EntityUtils.toString(entity,"UTF-8")); + httpGet.releaseConnection(); + + Connection conn = Jsoup.connect(url); // 建立与url中页面的连接 + Document doc = conn.get(); // 解析页面 + System.out.println(doc.toString()); + Elements links = doc.select("a[href]"); // 获取页面中所有的超链接 + System.out.println(links.size()); +*/ + + + + } + + private static void regex_analyse_excel_out(String[] ss) + { + try{ + OutputStream instream = new FileOutputStream(new File("out.xls")); + WritableWorkbook workbook = Workbook.createWorkbook(instream); + WritableSheet sheet = workbook.createSheet("First Sheet",0); + Label date = new Label(0,0,"日期"); + sheet.addCell(date); + Label meiyuan = new Label(0,1,"美元"); + sheet.addCell(meiyuan); + Label ouyuan = new Label(0,2,"欧元"); + sheet.addCell(ouyuan); + Label gangbi = new Label(0,3,"港币"); + sheet.addCell(gangbi); + + int i = 1; + + + for(String s:ss) + { + + + String regex1 = "(\\d+?.{1,4}元)对人民币(\\d+(\\.\\d+))元"; + Matcher matcher1 = Pattern.compile(regex1).matcher(s); + String regex2 = "(\\d{4}年\\d{1,2}月\\d{1,2}日)"; + Matcher matcher2 = Pattern.compile(regex2).matcher(s); + matcher2.find(); + Label new_date = new Label(i,0,matcher2.group(0)); + sheet.addCell(new_date); + + + int count = 0; + int j = 1; + while(matcher1.find()) + { + if(count == 4) + break; + if(count == 2) + { + count++; + continue; + } + //System.out.println(matcher.group(1)+":"+matcher.group(2)); + Label renmingbi = new Label(i,j,matcher1.group(2)); + sheet.addCell(renmingbi); + count++; + j++; + } + + i++; + + + + + } + workbook.write(); + workbook.close(); + }catch(Exception ex) + { + System.out.println(ex.toString()); + } + } + +} diff --git a/ExchangeRate/src/work2/neko-htmlunit-2.21.jar b/ExchangeRate/src/work2/neko-htmlunit-2.21.jar new file mode 100644 index 0000000..7d7e18a Binary files /dev/null and b/ExchangeRate/src/work2/neko-htmlunit-2.21.jar differ diff --git a/ExchangeRate/src/work2/sac-1.3.jar b/ExchangeRate/src/work2/sac-1.3.jar new file mode 100644 index 0000000..39b92b1 Binary files /dev/null and b/ExchangeRate/src/work2/sac-1.3.jar differ diff --git a/ExchangeRate/src/work2/serializer-2.7.2.jar b/ExchangeRate/src/work2/serializer-2.7.2.jar new file mode 100644 index 0000000..10c881c Binary files /dev/null and b/ExchangeRate/src/work2/serializer-2.7.2.jar differ diff --git a/ExchangeRate/src/work2/websocket-api-9.2.17.v20160517.jar b/ExchangeRate/src/work2/websocket-api-9.2.17.v20160517.jar new file mode 100644 index 0000000..255e140 Binary files /dev/null and b/ExchangeRate/src/work2/websocket-api-9.2.17.v20160517.jar differ diff --git a/ExchangeRate/src/work2/websocket-client-9.2.17.v20160517.jar b/ExchangeRate/src/work2/websocket-client-9.2.17.v20160517.jar new file mode 100644 index 0000000..bee67e9 Binary files /dev/null and b/ExchangeRate/src/work2/websocket-client-9.2.17.v20160517.jar differ diff --git a/ExchangeRate/src/work2/websocket-common-9.2.17.v20160517.jar b/ExchangeRate/src/work2/websocket-common-9.2.17.v20160517.jar new file mode 100644 index 0000000..7152250 Binary files /dev/null and b/ExchangeRate/src/work2/websocket-common-9.2.17.v20160517.jar differ diff --git a/ExchangeRate/src/work2/xalan-2.7.2.jar b/ExchangeRate/src/work2/xalan-2.7.2.jar new file mode 100644 index 0000000..abdabe3 Binary files /dev/null and b/ExchangeRate/src/work2/xalan-2.7.2.jar differ diff --git a/ExchangeRate/src/work2/xercesImpl-2.11.0.jar b/ExchangeRate/src/work2/xercesImpl-2.11.0.jar new file mode 100644 index 0000000..0aaa990 Binary files /dev/null and b/ExchangeRate/src/work2/xercesImpl-2.11.0.jar differ diff --git a/ExchangeRate/src/work2/xml-apis-1.4.01.jar b/ExchangeRate/src/work2/xml-apis-1.4.01.jar new file mode 100644 index 0000000..4673346 Binary files /dev/null and b/ExchangeRate/src/work2/xml-apis-1.4.01.jar differ diff --git a/Top10Ip.txt b/Top10Ip.txt new file mode 100644 index 0000000..2302b09 --- /dev/null +++ b/Top10Ip.txt @@ -0,0 +1 @@ +awk '{print $1}' apache_log |sort |uniq -c|sort -nr|head -n 10 \ No newline at end of file diff --git a/linux2.txt b/linux2.txt new file mode 100644 index 0000000..e8be9e0 --- /dev/null +++ b/linux2.txt @@ -0,0 +1 @@ +$scp /dir1/1.md 1-test.dev.cn1:/tmp \ No newline at end of file