Skip to content

Instantly share code, notes, and snippets.

@charleehu
charleehu / GCUtils.java
Created November 21, 2011 08:46 — forked from rednaxelafx/GCUtils.java
HotSpot VM utils
public class GCUtils {
private static final String DISABLE_EXPLICIT_GC = "DisableExplicitGC"; // need to be "manageable" in VM
public static void forceGC() {
String oldValue = HotSpotUtils.getVMOption(DISABLE_EXPLICIT_GC);
if ("true".equals(oldValue)) {
HotSpotUtils.setVMOption(DISABLE_EXPLICIT_GC, "false");
System.gc();
HotSpotUtils.setVMOption(DISABLE_EXPLICIT_GC, oldValue);
} else {
@charleehu
charleehu / FileBitSort.java
Created December 2, 2011 11:44
编程珠玑-chapter1-磁盘文件排序
public class FileBitSort {
public static void generateData(String path, int max) throws Exception {
File f = new File(path);
if (f.exists()) {
f.delete();
} else {
f.createNewFile();
}
@charleehu
charleehu / plugin.js
Created December 21, 2011 08:10
jQuery extends
(function($) {
$.fn.visibility = function(status) {
this.css('visibility',status);
return this;
}
})(jQuery)
$('#someElement').visibility('visible')
$('#someElement').visibility('hidden')
@charleehu
charleehu / downloadPac.groovy
Created December 27, 2011 06:08
autoproxy2pac file download
def conn = new URL("http://autoproxy2pac.appspot.com/pac/u/cafebabe.hu").openConnection(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("10.22.198.188", 8118)));
print("begin transfer...")
def count = 0;
conn.getInputStream().withStream {
def of = new File("c:\\cafebabe.hu").newOutputStream()
it.eachByte {
bt -> of.write(bt);count++;if(count%1024==0)print(".");
}
@charleehu
charleehu / GetTrainTicket.js
Created January 5, 2012 10:08
Get train ticket
(function(){
var $$ = function(cmd){
return $("#main").contents().find(cmd);
};
$$("#seat_type_code").val("");
$$("#ticket_type_order_num").val("");
$$("#bed_level_order_num").val("000000000000000000000000000000");
$$("#cancel_flag").val("1");
$$("#orderRequest_id_mode").val("Y");
[root@NYSJHL102-239 ~]# /opt/j2sdk/bin/jmap -heap 24694
Attaching to process ID 24694, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 11.0-b15
using parallel threads in the new generation.
using thread-local object allocation.
Concurrent Mark-Sweep GC
@charleehu
charleehu / DirectMemorySize.java
Created January 30, 2012 09:05 — forked from rednaxelafx/DirectMemorySize.java
An Serviceability-Agent based tool to see stats of NIO direct memory, as an alternative on JDKs without JMX support for direct memory monitoring.
import java.io.*;
import java.util.*;
import sun.jvm.hotspot.memory.*;
import sun.jvm.hotspot.oops.*;
import sun.jvm.hotspot.debugger.*;
import sun.jvm.hotspot.runtime.*;
import sun.jvm.hotspot.tools.*;
import sun.jvm.hotspot.utilities.*;
public class DirectMemorySize extends Tool {
@charleehu
charleehu / main.user.js
Created March 23, 2012 09:58
Google Search Result Click Do Not Track
// ==UserScript==
// @name Google Search Result Click Do Not Track
// @description 去除Google搜索结果中的URL跟踪跳转
// ==/UserScript==
var b=document.body;
b.addEventListener("click",checkSingleLink);
b.addEventListener("mousedown",checkSingleLink);
setTimeout(function () {
var input=document.getElementById("lst-ib");
@charleehu
charleehu / log4j.properties
Created March 31, 2012 03:53
a bak for log4j.properties
#------------------------------------------------------------------------------
#
# The following properties set the logging levels and log appender. The
# log4j.rootCategory variable defines the default log level and one or more
# appenders. For the console, use 'S'. For the daily rolling file, use 'R'.
# For an HTML formatted log, use 'H'.
#
# To override the default (rootCategory) log level, define a property of the
# form (see below for available values):
#
@charleehu
charleehu / Case.java
Created May 5, 2012 11:06
BTrace sample
import java.util.Random;
public class Case1{
public static void main(String[] args) throws Exception{
Random random=new Random();
CaseObject object=new CaseObject();
boolean result=true;
while(result){
result=object.execute(random.nextInt(1000));
Thread.sleep(1000);