Skip to content

Instantly share code, notes, and snippets.

View zhanggang807's full-sized avatar
🤗

Dean Zhang zhanggang807

🤗
View GitHub Profile
@zhanggang807
zhanggang807 / ExternalizableDemo.java
Created March 22, 2018 01:52
java Externalizable interface demo
import java.io.*;
/**
* reference link
* https://mp.weixin.qq.com/s/QS9e_lVxr5vuphql5O3xhA
* https://www.cnblogs.com/chenfei0801/archive/2013/04/06/3002146.html
* 对一个实现了Externalizable接口的类进行序列化及反序列化
*/
public class ExternalizableDemo1 {
@zhanggang807
zhanggang807 / KMP.java
Created March 9, 2018 01:36
KMP算法
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class KMP {
public static void main(String[] args) {
//Scanner sc = new Scanner(System.in);
//String str1 = sc.nextLine();//主串
String str1 = "ababbabababbbab";//主串
//while (sc.hasNext()) {
@zhanggang807
zhanggang807 / KeyStoreTest.java
Created March 2, 2018 08:03
key store of java security
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
@zhanggang807
zhanggang807 / KeyTest.java
Last active March 2, 2018 07:37
key generator of java security
import java.security.KeyFactory;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.spec.DSAPrivateKeySpec;
import java.security.spec.InvalidKeySpecException;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
@zhanggang807
zhanggang807 / JosephusCircle.java
Created February 11, 2018 05:53
Josephus Circle Solution
public class JosephusCircle {
public static void main(String[] args) {
int n = 0;
int m = 0;
int i = 0;
int s = 0;
Scanner scanner = new Scanner(System.in);
@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 {
@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;
/*
* $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 / 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)
@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.....\");");