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 / 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 / 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 / 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 / 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 / gist:2851303
Created June 1, 2012 11:12 — forked from zythum/gist:2848881
google收录的敏感词
@khotyn
khotyn / varamyr.py
Created June 12, 2012 12:31
A simple tool named Varamyr written in Python to add some css to the epub file so books written in Chinese can be read in Nook.
from xml.dom.minidom import getDOMImplementation, parse, parseString
import zipfile
import sys
font = """\n<style type='text/css'>\n
@page {\n
margin-bottom: 5pt;\n
margin-top: 5pt\n
}\n
@font-face {\n
@khotyn
khotyn / IntegerTest.java
Created September 4, 2012 13:01
Integer Caching
/**
* {@link Integer} will cache the integers between -128 and 127 (inclusive). See
* {@link Integer#valueOf(int)} for detail implementation.
*
* @author khotyn
*
*/
public class IntegerTest {
public static void main(String[] args) {
@khotyn
khotyn / ConditionalExpressionTest.java
Created September 4, 2012 13:20
Conditional Expression Type Oddity
/**
* Conditional Expression Test. The result is
*
* <pre>
* 114.0
* class java.lang.Double
* </pre>
*
* So why the result is 114.0, the ASCII value of <code>'r'</code>? First, the
* <code>new Double(0)</code> is convert to primary type <code>double</code>,
@khotyn
khotyn / CircularArray.java
Created October 18, 2012 14:00
一个无限容量的用于 Work Steeling 的 DEQueue 的实现
package com.khotyn.test;
/**
* Created with IntelliJ IDEA.
* User: khotyn
* Date: 12-10-18
* Time: 下午9:14
* To change this template use File | Settings | File Templates.
*/
public class CircularArray {
@khotyn
khotyn / AgentInstall.java
Created December 6, 2012 14:45
Adding an annotation to a class then redefine it
package com.khotyn.test;
import java.lang.instrument.Instrumentation;
public class AgentInstall {
public static void premain(String agentArgs, Instrumentation inst) {
InstrumentationHolder.setInstrumentation(inst);
}
}