Skip to content

Instantly share code, notes, and snippets.

View zhanggang807's full-sized avatar
🤗

Dean Zhang zhanggang807

🤗
View GitHub Profile
@zhanggang807
zhanggang807 / 32.asm
Created May 10, 2017 04:53 — forked from FiloSottile/32.asm
NASM Hello World for x86 and x86_64 Intel Mac OS X (get yourself an updated nasm with brew)
; /usr/local/bin/nasm -f macho 32.asm && ld -macosx_version_min 10.7.0 -o 32 32.o && ./32
global start
section .text
start:
push dword msg.len
push dword msg
push dword 1
mov eax, 4
@zhanggang807
zhanggang807 / Subject.java
Created January 10, 2018 06:53
static proxy in java language
public interface Subject {
void request();
}
class RealSubject implements Subject {
public void request() {
System.out.println("RealSubject");
@zhanggang807
zhanggang807 / Service.java
Last active January 10, 2018 07:33
dynamic proxy of JDK
public interface Service {
//目标方法
public abstract void add();
}
class UserServiceImpl implements Service {
public void add() {
@zhanggang807
zhanggang807 / UserServiceImpl.java
Created January 12, 2018 05:55
dynamic proxy of CG lib
public class UserServiceImpl {
public void add() {
System.out.println("This is add service");
}
public void delete(int id) {
System.out.println("This is delete service?delete " + id);
}
@zhanggang807
zhanggang807 / MyClassGeneratorByASM.java
Created January 19, 2018 08:09
generator class with asm lib.
public class MyClassGeneratorByASM {
public static void main(String[] args) throws IOException {
System.out.println();
ClassWriter classWriter = new ClassWriter(0);
// 通过visit方法确定类的头部信息
classWriter.visit(Opcodes.V1_7,// java版本
Opcodes.ACC_PUBLIC,// 类修饰符
"Programmer", // 类的全限定名
@zhanggang807
zhanggang807 / MyClassGeneratorByJavassist.java
Created January 19, 2018 08:10
generator class with javassist lib.
public class MyClassGeneratorByJavassist {
public static void main(String[] args) throws Exception {
ClassPool pool = ClassPool.getDefault();
//创建Programmer类
CtClass cc= pool.makeClass("com.samples.Programmer");
//定义code方法
CtMethod method = CtNewMethod.make("public void code(){}", cc);
//插入方法代码
method.insertBefore("System.out.println(\"I'm a Programmer,Just Coding.....\");");
@zhanggang807
zhanggang807 / Makefile
Created January 26, 2018 07:03
im-select:change mac input method via command line. copied from https://github.com/CodeFalling/smart-im-osx
CC=/usr/bin/clang
NAME=im-select
INSTALL_PATH=/usr/local/bin/
OPTS=-framework foundation -framework carbon
all:
$(CC) $(OPTS) -o $(NAME) $(NAME).m
install:$(NAME)
cp $(NAME) $(INSTALL_PATH)
/*
* $Id$
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
@zhanggang807
zhanggang807 / hello.sh
Created February 5, 2018 08:04
shell function's parameter
echo use function hello
hello()
{
echo how many parameters in the function:$#;
echo what parameters in the function $@;
echo the name of this function is $0;
echo the first parameters is :$1;
echo the second parameters is :$2;
echo the second parameters is :$3;
@zhanggang807
zhanggang807 / TestGetClassFromWhichJarLocation.java
Created February 8, 2018 08:52
print a class in which jar file.
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.CodeSource;
import java.security.ProtectionDomain;
/**
* Creted on 2018/2/8.
*/
public class TestGetClassFromWhichJarLocation {