Skip to content

Instantly share code, notes, and snippets.

View khotyn's full-sized avatar
😌
Focusing

Khotyn Huang khotyn

😌
Focusing
View GitHub Profile
@khotyn
khotyn / eclipsePluginMirroring.sh
Created May 14, 2012 05:15
A simple shell script to mirroring a eclipse plugin repository to local.
#!/bin/sh
eclipseHome="/home/khotyn/softwares/eclipse_java/"
pluginName="$1"
updateSiteURL="$2"
localRepositoryHome="/home/khotyn/softwares/eclipse_plugins/"
cd $eclipseHome
./eclipse -application org.eclipse.equinox.p2.metadata.repository.mirrorApplication -source $updateSiteURL -destination "$localRepositoryHome$pluginName"
./eclipse -application org.eclipse.equinox.p2.artifact.repository.mirrorApplication -source $updateSiteURL -destination "$localRepositoryHome$pluginName"
echo "path=$localRepositoryHome$pluginName" > "$localRepositoryHome$pluginName.link"
@khotyn
khotyn / asm_notes.md
Created March 4, 2012 14:24
ASM Notes

ASM Notes

Core API

  • The ASM library is designed to work on compiled Java classes. It was also designed to be as fast and small as possible.
  • ASM provides tools to read, write and transfrom such byte arrays by using higher level concepts then bytes such as numeric constants, strings, Java identifiers, Java types, Java class structure elements.
  • The ASM is just a reference to the __asm__ keyword in C.
  • The core API provides an event based representation of classes, while the tree API provides an object based representation.
  • The CheckClassAdapter class could be used to check if the bytecode generated by ASM is valid.
  • The ASMifier class could be usedd to generate the source code of ASM for generating a specific class.
@khotyn
khotyn / Javassist学习笔记.md
Created February 22, 2012 16:21
Javassist学习笔记

Javassist学习笔记

创建一个新类

private static void makeNewClass() throws IOException, CannotCompileException {
    ClassPool classPool = ClassPool.getDefault();
    CtClass cc = classPool.makeClass("Test");
    byte[] bytes = cc.toBytecode();
    FileOutputStream fos = new FileOutputStream("/Users/apple/Desktop/Test.class");
@khotyn
khotyn / ConditionCompile.md
Created January 16, 2012 13:42
Example of conditional compile in Java

Conditional Compile in Java

Considering the piece of the code above:

public class ConditionalCompile {
	private static final boolean DEBUG = false;

	public static void main(String args[]) {
 if(DEBUG){
@khotyn
khotyn / ClassUtil.java
Created December 27, 2011 11:32
Read all the classes in the class path.
package com.khotyn.test;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
@khotyn
khotyn / GarbageCollectors.java
Created December 26, 2011 11:26
Garbage collectors used in HotSpot JVM under different VM Options
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.util.Set;
import javax.management.MBeanServer;
import javax.management.ObjectName;
/**
* Print the Collector used in the program.
* @author khotyn
@khotyn
khotyn / cmd.sh
Created December 19, 2011 07:07
Default CMSInitiatingOccupancyFraction value
java -XX:+UseConcMarkSweepGC -XX:+PrintFlagsFinal Main | grep -P "CMSInitiatingOccupancyFraction|CMSTriggerRatio|MinHeapFreeRatio"
@khotyn
khotyn / HexStringtoInt.java
Created December 7, 2011 02:20
Signed hex String to int.
public static int hexStringToInt(String str) {
if (str.length() == 8) {
int firstBit = Integer.valueOf(str.substring(0, 1), 16);
if (firstBit >= 8) {
return Integer.valueOf((firstBit - 8) + str.substring(1), 16) - 0x80000000;
} else {
return Integer.valueOf(str, 16);
}
} else {
@khotyn
khotyn / AnnoMethod.java
Created December 6, 2011 06:03
What is AnnotationDefault in Java class file.
import java.lang.annotation.*;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface AnnoMethod {
int id() default 9;
String value() default "Hello, world";
}
@khotyn
khotyn / Anno.java
Created December 2, 2011 03:19
RuntimeVisibleAnnotations and RuntimeInvisibleAnnotations
package com.khotyn.test;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.CLASS)
@Target(ElementType.TYPE)
public @interface Anno {