Skip to content

Instantly share code, notes, and snippets.

View bingoohuang's full-sized avatar
🎯
Focusing

bingoohuang bingoohuang

🎯
Focusing
View GitHub Profile
@bingoohuang
bingoohuang / DifferenceClassNamesTest.java
Last active December 19, 2015 07:09
In Java: What is the difference between: Object o1= .... o1.getClass().getSimpleName(); o1.getClass().getName(); o1.getClass().getCanonicalName();
/**
In Java: What is the difference between:
Object o1= ....
o1.getClass().getSimpleName();
o1.getClass().getName();
o1.getClass().getCanonicalName();
**/
@Test
public void testNames() throws Exception {
//primative
@bingoohuang
bingoohuang / IPToCountryCodeTest.java
Created July 3, 2013 09:42
find country code by ip using ip ranges implemented by TreeMap
/**
* This utility provides methods to either convert an IPv4 address to its long format or a 32bit dotted format.
*
* @author Aion
* Created on 22/11/12
*/
public static class IPv4 {
/**
* Returns the long format of the provided IP address.
@bingoohuang
bingoohuang / Dom4jDemo.java
Created September 16, 2013 07:35
how to let DOM4J to generate <name></name> other than <name/>
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;
import java.io.IOException;
import java.io.StringWriter;
@bingoohuang
bingoohuang / nginx_limit_by_cookie.conf.lua
Last active December 23, 2015 07:49
nginx limit by login user's cookie
@bingoohuang
bingoohuang / urlshortener.lua
Last active September 8, 2023 11:09
url shortener base on nginx lua and resty redis
local _M = {
_VERSION = '0.1'
}
local connect = function()
local redis = require "resty.redis"
local red = redis:new()
red:set_timeout(1000) -- 1 sec
local ok, err = red:connect("127.0.0.1", 6379)
if not ok then
@bingoohuang
bingoohuang / 0_reuse_code.js
Created June 15, 2014 23:51
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@bingoohuang
bingoohuang / TryLoadImages.js
Last active August 29, 2015 14:04
Try load images by sequence until 404 found
<html>
<body>
</body>
<script>
(function tryLoadImages(index) {
var img = document.createElement('img');
img.src = "http://127.0.0.1:7001/" + index + ".jpg";
img.onload = function() {
document.body.appendChild(img);
@bingoohuang
bingoohuang / SeckillingMeasure.java
Last active February 19, 2016 08:25
seckilling implementation using java springmvc
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.params.HttpClientParams;
import org.apache.commons.httpclient.params.HttpConnectionManagerParams;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
@bingoohuang
bingoohuang / dfawk
Created July 16, 2015 11:14
convert df output with awk
[root@iZ25p1jt074Z ~]# df -m|awk 'NR==1{for(i=1;i<=NF;i++){ix[i]=$i}} (NR>1){for(i=1;i<=NF-1;i++){printf "%s:%s,",ix[i],$i} printf "%s:%s\n",ix[NF],$NF}'
Filesystem:/dev/xvda1,1M-blocks:20158,Used:12464,Available:6671,Use%:66%,Mounted:/
Filesystem:tmpfs,1M-blocks:4096,Used:0,Available:4096,Use%:0%,Mounted:/dev/shm
Filesystem:/dev/xvdb1,1M-blocks:201581,Used:9433,Available:181909,Use%:5%,Mounted:/mnt
[root@iZ25p1jt074Z ~]#
package main
import (
"fmt"
"sync"
)
// more to see https://github.com/golang/go/wiki/CommonMistakes
func main() {
m := []string{"a", "b", "c", "d"}