Skip to content

Instantly share code, notes, and snippets.

@hujj0615
hujj0615 / gist:4343345
Created December 20, 2012 06:43
shell: read first N bytes from file and display as hex
hexdump -n 1024 -x sourcepush.gzip
@hujj0615
hujj0615 / server.xml
Created December 20, 2012 06:29
config compress in tomcat
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
URIEncoding="utf-8"
acceptCount="100"
maxThreads="250"
compression = "on"
compressableMimeType="application/json"
compressionMinSize="1024000"
redirectPort="8443" />
@hujj0615
hujj0615 / gist:4342714
Created December 20, 2012 03:31
file checksum and md5 by Shell
cksum $FILENAME #output the checksum and bytes
md5sum $FILENAME #output the md5
@hujj0615
hujj0615 / gist:4335186
Created December 19, 2012 08:05
python calculate time cost
import datetime
start=datetime.datetime.now()
end=datetime.datetime.now()
cost=end-start
print type(cost)
@hujj0615
hujj0615 / gist:4335167
Created December 19, 2012 08:00
httpclient set http head
HttpRequestBase r;
r.setHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; InfoPath.2; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)");
r.setHeader( "Accept","image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash," +
" application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-ms-application," +
" application/x-ms-xbap, application/vnd.ms-xpsdocument, application/xaml+xml, */*");
r.setHeader("Accept-Encoding", "gzip, deflate");
r.setHeader("Accept-Language", "zh-cn");
r.setHeader("Content-Type", "application/x-www-form-urlencoded");
r.setHeader("Cache-Control", "no-cache");
@hujj0615
hujj0615 / TaskThreadFactory.java
Created December 4, 2012 10:36
make threads have same name prefix
class TaskThreadFactory implements ThreadFactory {
final ThreadGroup group;
final AtomicInteger threadNumber = new AtomicInteger(1);
final String namePrefix;
TaskThreadFactory(String namePrefix) {
SecurityManager s = System.getSecurityManager();
group = (s != null) ? s.getThreadGroup() : Thread.currentThread().getThreadGroup();
this.namePrefix = namePrefix;
}
@hujj0615
hujj0615 / GZipTest.java
Created December 4, 2012 07:36
java gzip compress example
private static void compress(byte[] in) throws IOException {
System.out.println("before compress size: " + in.length);
byte[] out = null;
ByteArrayInputStream bi = new ByteArrayInputStream(in);
ByteArrayOutputStream bo = new ByteArrayOutputStream();
GZIPOutputStream go = new GZIPOutputStream(bo);
byte[] bb = new byte[1024];
@hujj0615
hujj0615 / PostMain.java
Created December 4, 2012 07:30
httpclient post example
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost post = new HttpPost("http://localhost:8086/filter.s");
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
nvps.add(new BasicNameValuePair("title", "test_" + ns.getTitle()));
nvps.add(new BasicNameValuePair("source", ns.getSource()));
nvps.add(new BasicNameValuePair("category", ns.getCategory()));
nvps.add(new BasicNameValuePair("content", ns.getContent()));
post.setEntity(new UrlEncodedFormEntity(nvps, "gbk"));
@hujj0615
hujj0615 / submit.py
Created December 4, 2012 07:12
python urllib http post exapmle
import urllib
url = "http://localhost:8080/test"
def postNews(title, source, category, content):#gbk encoding
params=urllib.urlencode({"title":title, "source":source, "category":category, "content":content})
resp = urllib.urlopen(url, params)
print resp.readlines()
resp.close()