`
Mr.Chris
  • 浏览: 83226 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论
收藏列表
标题 标签 来源
ZooKeeper客户端连接远程服务器 zookeeper http://www.cnblogs.com/phinecos/archive/2012/02/15/2353007.html
zkCli.cmd –server zookeeper服务器地址1:端口
将Groovy加入到Maven工程 maven, groovy
<plugin>
	<artifactId>maven-compiler-plugin</artifactId>
	<version>2.3.2</version>
	<configuration>
		<compilerId>groovy-eclipse-compiler</compilerId>
		<verbose>true</verbose>
	</configuration>
	<dependencies>
		<dependency>
			<groupId>org.codehaus.groovy</groupId>
			<artifactId>groovy-eclipse-compiler</artifactId>
			<version>2.6.0-01</version>
		</dependency>
	</dependencies>
</plugin>
<plugin>
	<groupId>org.codehaus.mojo</groupId>
	<artifactId>build-helper-maven-plugin</artifactId>
	<version>1.7</version>
	<executions>
		<execution>
			<id>add-source</id>
			<phase>generate-sources</phase>
			<goals>
				<goal>add-source</goal>
			</goals>
			<configuration>
				<sources>
					<source>src/main/groovy</source>
				</sources>
			</configuration>
		</execution>
		<execution>
			<id>add-test-source</id>
			<phase>generate-sources</phase>
			<goals>
				<goal>add-test-source</goal>
			</goals>
			<configuration>
				<sources>
					<source>src/test/groovy</source>
				</sources>
			</configuration>
		</execution>
	</executions>
</plugin>
java获取网络动态图片 java, io http://www.iteye.com/problems/14760
import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;


public class DynamicGetURLImage {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		try {
			//图片的http全路径
			String imgurl = "http://xxx:8080/xxx/seccode.php?update=6689";
			
			URL url = new URL(imgurl);
			
			BufferedInputStream  in = new BufferedInputStream(url.openStream());
			
                       //保存的图片文件名
			File img = new File("img.jpg");
			
			BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(img));
			
			byte[] buf = new byte[2048];
			
			while(in.read(buf) != -1)
			{
				out.write(buf);
			}
			
			in.close();
			out.close();
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}

}


CVS检出代码 cvs http://cafe.elharo.com/tools/cvs-tip-1-checking-out-an-entire-sourceforge-project/
cvs -z3 -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/project co .
常用Hadoop操作指令 hadoop
1、bin/hadoop dfsadmin -safemode leave  离开安全模式
常用Linux操作指令 linux
1、cd $(readlink .)     切换到软连接真实目录下
常用的VIM设置及操作 linux, vim
1、设置TAB制表符的宽度: set tabstop=4
2、设置自动缩进:        set indent(如果是C,还可set cindent)
3、设置语法高亮:        syntax on

----------------------------------------------
1、复制当前行:              yy
2、粘贴:                    p
3、进入可视模式,选定多行:  v(V是行选定模式)
4、拷贝与剪切:              y、d
5、折叠代码(先v选中块):   zf
6、打开折叠:                zo
7、关闭折叠:                zc(只要在被折叠的快中的任一个语句即可)
8、缩进代码(先v选中块):   <(左缩进)、>(右缩进)、=(自动格式化代码,自动缩进,内部的递归进行缩进)
9、跳到指定行:              :后边加行号
10、从大括号的开始移动到大括号的结束位置:   %
11、行左移与行右移:         <<、 >>
12、光标返回到以前与后来的位置:  Ctrl+O、Ctrl+I
13、列块选定:              Ctrl+V
模拟单点登录查询WEBSQL java
package com.taobao.wlb.mywlb;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;

/**  
 * Filename:    MockWebSQL.java  
 * Description:   
 * Copyright:   Copyright (c)2010  
 * Company:     taobao  
 * @author:     lanbo 
 * @version:    1.0  
 * Create at:   2011-9-21 下午02:58:31  
 *  
 * Modification History:  
 * Date         Author      Version     Description  
 * ------------------------------------------------------------------  
 * 2011-9-21      lanbo        1.0        Version  
 */
public class MockWebSQL {

	/**
	 * @param args
	 * @throws IOException 
	 * @throws ClientProtocolException 
	 */
	@SuppressWarnings("deprecation")
	public static void main(String[] args) throws ClientProtocolException, IOException {
		DefaultHttpClient httpclient = new DefaultHttpClient();
		HttpPost httpost = new HttpPost("https://backyard.seraph.taobao.com/login/?url=http://dba.tools.taobao.com:9999/workspace.htm");
		List<NameValuePair> nvps = new ArrayList<NameValuePair>();
		nvps.add(new BasicNameValuePair("id", "用戶名"));
		nvps.add(new BasicNameValuePair("pass_word", "密碼"));
		nvps.add(new BasicNameValuePair("url", "http%3A%2F%2Fdba.tools.taobao.com%3A9999%2Fworkspace.htm"));
		nvps.add(new BasicNameValuePair("action", "login"));
		httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
		HttpResponse response = httpclient.execute(httpost);
		HttpEntity entity = response.getEntity();
		System.out.println("Login form get: " + response.getStatusLine());
		if (entity != null) {
			entity.consumeContent();
		}
		//		System.out.println("Post logon cookies:");
		//		List<Cookie> cookies = httpclient.getCookieStore().getCookies();
		//		if (cookies.isEmpty()) {
		//			System.out.println("None");
		//		} else {
		//			for (int i = 0; i < cookies.size(); i++) {
		//				System.out.println("- " + cookies.get(i).toString());
		//			}
		//		}
		httpost = new HttpPost("http://dba.tools.taobao.com:9999/database/execute.jsn?_input_charset=UTF-8");
		nvps = new ArrayList<NameValuePair>();
		nvps.add(new BasicNameValuePair("dbId", "4682"));
		nvps.add(new BasicNameValuePair("sql", "select * from wlb_order where id = 1"));
		httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
		response = httpclient.execute(httpost);
		BufferedReader in = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "GBK"));
		StringBuffer sb = new StringBuffer("");
		String line = "";
		String NL = System.getProperty("line.separator");
		while ((line = in.readLine()) != null) {
			sb.append(line + NL);
		}
		in.close(); 
		System.out.println(sb.toString());
	}
}
Genius sorting algorithm: Sleep sort bash http://coolshell.cn/articles/4883.html
#!/bin/bash
function f() {
    sleep "$1"
    echo "$1"
}
while [ -n "$1" ]
do
    f "$1" &
    shift
done
wait
查看class真实归属的jar包位置 java webx_guide_book_p205
URL url = getClass().getClassLoader().getResource(Logger.class.getName().replace('.', '/') + ".class");
System.out.println(url.toString());
//output:jar:file:/D:/tb-repo/log4j/log4j/1.2.15/log4j-1.2.15.jar!/org/apache/log4j/Logger.class
扫描所有的classloader中的所有class java 两个OOM Cases排查过程的分享
ClassLoader classLoader = AnotherDemoBean.class.getClassLoader();
Field field = ClassLoader.class.getDeclaredField("classes");
field.setAccessible(true);
Object object = field.get(classLoader);
System.out.println(object.toString());
常见的AOP实作策略 java AOP里面3个概念Advice,PointCut,Advisor
/*动态代理是比较常见的AOP实作策略,在《Expert One-on-One J2EE Development WIthout EJB》 Rod Johnson、Juergen Hoeller中的第八章中有提到,AOP的实作有五个主要的策略: 
Dynamic Proxies 
Dynamic Byte Code Generation 
Java Code Generation 
Use of a Custon Class Loader 
Language Extensions*/
Vector是线程安全的 java, collections
//需要保证线程安全的时候,不要用List。
//见Junit源码中TestSuite类
private Vector<Test> fTests= new Vector<Test>(10); // Cannot convert this to List because it is used directly by some test runners
Java中文路径乱码的解决方法 java, io java中文路径乱码
//URI中提供URL的decode/encode方法
fileName = ClassLoader.getSystemResource(fileName).toURI().getPath();
Java获取JVM使用的所有内存 java, memory Get Total Memory Of Java Virtual Machine(JVM) Example
Runtime runtime = Runtime.getRuntime();
long totalMemory = runtime.totalMemory();
System.out.println(totalMemory + " bytes total in JVM");
设置JVM占用内存及堆大小 jvm, heap
java -Xms128m   //JVM占用最小内存
     -Xmx512m   //JVM占用最大内存
     -XX:PermSize=64m   //最小堆大小
     -XX:MaxPermSize=128m //最大堆大小
演示StackOverFlowError的例子 java, stackoverflow
public class StackOverFlowErrorMain {
	static class A {
		public void m() {
			System.out.println("this is A's m!");
		}
	}
	static class B extends A {
		public void m() {
			this.m();
		}
	}
	public static void main(String[] args) {
		A a = new B();
		a.m();
	}
}
Java反射获取父类的属性 java, reflection
public static void main(String[] args) throws Exception {
	A a = new B();
	a.name = "lanbo";
	Field field = a.getClass().getSuperclass().getDeclaredField("name");  
	field.setAccessible(true);
	System.out.println(field.get(a));
}
MySQL中以某字段分组,统计多个字段的SQL脚本 mysql, sql http://www.iteye.com/problems/65516
SELECT substr(createtime, 1, 10),  
       SUM(CASE  
               WHEN TYPE = '3' THEN  
                1  
               ELSE  
                0  
           END),  
       SUM(CASE  
               WHEN TYPE = '10' THEN  
                1  
               ELSE  
                0  
           END) c_date  
  FROM test_tb  
 GROUP BY substr(createtime, 1, 10)
Java中的正负无穷大怎么表示 java
System.out.println(1.0f / 0.0f);
System.out.println(Float.POSITIVE_INFINITY);
获取运行Jar包的实际路径 java, swing
String path = this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath(); //获取jar路径
String file = this.getClass().getProtectionDomain().getCodeSource().getLocation().getFile(); //获取jar文件名
JOptionPane.showMessageDialog(this, "路径:" + path + " - " + file);  
反射时将所有字段设为可访问 java, reflection
//See com.google.gson.ObjectNavigator.navigateClassFields
Field[] fields = clazz.getDeclaredFields();
AccessibleObject.setAccessible(fields, true);
Java方法是按值传递,没有按引用传递的概念 java http://www.iteye.com/problems/65390
public static void main(String[] args) {
	StringBuilder b1 = new StringBuilder("a");
	StringBuilder b2 = new StringBuilder("b");
	op(b1, b2);
	System.out.println(b1 + "," + b2); // 结果为 ab,b 为什么?? 
}

//op方法接收到的b2其实是b2指针的一份拷贝
public static void op(StringBuilder b1, StringBuilder b2) {
	b1.append(b2);
	b2 = b1;
}
汉字转Unicode java, unicode
public static String stringToUnicode(String str) {
	try {
		String ret = "";
		char c[] = str.toCharArray();
		for (int i = 0; i < c.length; i++) {
			ret += "\\u";
			ret += Integer.toString(c[i], 16);
		}
		return ret;
	} catch (Exception e) {
		return null;
	}
}

string = stringToUnicode(string);
Unicode转汉字 unicode, java
public static String unicodeToString(String str) {
	Pattern pattern = Pattern.compile("(\\\\u(\\p{XDigit}{4}))");    
	Matcher matcher = pattern.matcher(str);
	char ch;
	while (matcher.find()) {
		ch = (char) Integer.parseInt(matcher.group(2), 16);
		str = str.replace(matcher.group(1), ch + "");    
	}
	return str;
}

String string = unicodeToString("\u826f\u597d\u5e16");
Global site tag (gtag.js) - Google Analytics