Skip to content

Instantly share code, notes, and snippets.

@lzxz1234
lzxz1234 / Java 栈 四则运算
Created September 26, 2012 03:28
Java 栈实现四则运算
public class StackTest {
private Stack<Character> oprStack = new Stack<Character>();
private Stack<Integer> numStack = new Stack<Integer>();
public static void main(String[] args) {
StackTest st = new StackTest();
System.out.println(st.calc("3+4*((4*10-10/2)+5)#"));
}
@lzxz1234
lzxz1234 / getCharset
Created October 10, 2012 07:35
即时判断字节编码类型
public static String getCharset(byte[] bytes) {
if(bytes == null || bytes.length < 2) return "GBK";
if(bytes[0] == (byte)0xFF && bytes[1] == (byte)0xFE) {
return "UTF-16LE";
} else if (bytes[0] == (byte)0xFE && bytes[1] == (byte)0xFF) {
return "UTF-16BE";
} else if (bytes[0] == (byte)0xEF && bytes[1] == (byte)0xBB && bytes[2] == (byte)0xBF) {
return "UTF-8";
}
@lzxz1234
lzxz1234 / StringTemplate
Last active June 8, 2017 02:17
模版解析进行String字符串组装
public class StringTemplate {
private List<Element> list = new ArrayList<Element>();
private StringTemplate(List<Element> list) {
this.list = list;
}
/**
* @param src 例:尊敬的${who}用户,您该月话费为${amount}元,谢谢${2}!!
* @return 解析生成的模版,调用 <code>replace</code> 方法即可生成结果
@lzxz1234
lzxz1234 / gist:4379241
Created December 26, 2012 09:53
Stevey's Google Platforms Rant
Stevey's Google Platforms Rant
I was at Amazon for about six and a half years, and now I've been at Google for that long. One thing that struck me immediately about the two companies -- an impression that has been reinforced almost daily -- is that Amazon does everything wrong, and Google does everything right. Sure, it's a sweeping generalization, but a surprisingly accurate one. It's pretty crazy. There are probably a hundred or even two hundred different ways you can compare the two companies, and Google is superior in all but three of them, if I recall correctly. I actually did a spreadsheet at one point but Legal wouldn't let me show it to anyone, even though recruiting loved it.
I mean, just to give you a very brief taste: Amazon's recruiting process is fundamentally flawed by having teams hire for themselves, so their hiring bar is incredibly inconsistent across teams, despite various efforts they've made to level it out. And their operations are a mess; they don't really have SREs and they make engi
#!/bin/bash
shelldir=$(cd $(dirname $BASH_SOURCE); pwd)
prjhome="$shelldir/web"
tomcathome="/var/apache-tomcat-7.0.54-8080"
webinfdir="$prjhome/WebContent/WEB-INF"
srcdir=("$prjhome/src" "$prjhome/conf")
libdir=("$webinfdir/lib/*.jar" "$tomcathome/lib/*.jar")
dstdir="$webinfdir/classes/"
@lzxz1234
lzxz1234 / Ugly.java
Created July 11, 2014 06:51
Unicode 版 Helloword
\u0070\u0075\u0062\u006c\u0069\u0063\u0020\u0020\u0020\u0020
\u0063\u006c\u0061\u0073\u0073\u0020\u0055\u0067\u006c\u0079
\u007b\u0070\u0075\u0062\u006c\u0069\u0063\u0020\u0020\u0020
\u0020\u0020\u0020\u0020\u0073\u0074\u0061\u0074\u0069\u0063
\u0076\u006f\u0069\u0064\u0020\u006d\u0061\u0069\u006e\u0028
\u0053\u0074\u0072\u0069\u006e\u0067\u005b\u005d\u0020\u0020
\u0020\u0020\u0020\u0020\u0061\u0072\u0067\u0073\u0029\u007b
\u0053\u0079\u0073\u0074\u0065\u006d\u002e\u006f\u0075\u0074
\u002e\u0070\u0072\u0069\u006e\u0074\u006c\u006e\u0028\u0020
\u0022\u0048\u0065\u006c\u006c\u006f\u0020\u0077\u0022\u002b
//
// _oo0oo_
// o8888888o
// 88" . "88
// (| -_- |)
// 0\ = /0
// ___/`---'\___
// .' \\| |// '.
// / \\||| : |||// \
// / _||||| -:- |||||- \
@lzxz1234
lzxz1234 / AutoSolveFileDao.java
Last active June 8, 2017 02:21
XCMS 自处理图标用DAO
import java.util.Enumeration;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.commons.io.FileUtils;
import org.nutz.lang.Mirror;
import org.nutz.lang.Strings;
import org.nutz.mvc.upload.TempFile;
package com.bj58.ecat.emc.diywebsite.message.utils;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.Semaphore;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.log4j.Logger;
import com.bj58.ecat.redis.utils.StringUtils;
@lzxz1234
lzxz1234 / ASTReference.java
Created January 22, 2016 10:20
Velocity 自动 escape 防 XSS 版
package org.apache.velocity.runtime.parser.node;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.velocity.app.event.EventHandlerUtil;
import org.apache.velocity.context.Context;
import org.apache.velocity.context.InternalContextAdapter;
import org.apache.velocity.exception.MethodInvocationException;
import org.apache.velocity.exception.TemplateInitException;
import org.apache.velocity.exception.VelocityException;
import org.apache.velocity.runtime.Renderable;