Skip to content

Instantly share code, notes, and snippets.

@seveniu
seveniu / BoundedExecutor.java
Created January 15, 2018 12:47
java BoundedExecutor
package com.lavector.concurrency;
import java.util.concurrent.*;
/**
* @author seveniu
* @date 2017-01-09
* @Description
*/
public class BoundedExecutor {
@seveniu
seveniu / GuavaCacheTest.java
Last active August 23, 2018 05:58
guava cache test refresh
public static void testRefresh() throws ExecutionException, InterruptedException {
LogTime logTime = new LogTime();
AtomicInteger value = new AtomicInteger();
LoadingCache<String, String> cb = CacheBuilder.newBuilder()
.maximumSize(1000)
.refreshAfterWrite(6, TimeUnit.SECONDS)
.removalListener((RemovalListener<String, String>) notification -> {
logTime.log("remove key : " + notification.getKey() + ", value : " + notification.getValue() + ", cause " + notification.getCause());
})
.build(new CacheLoader<String, String>() {
@seveniu
seveniu / MongoDB.dockerfile
Created August 4, 2016 11:47
MongoDB Dockerfile
#
# MongoDB Dockerfile
#
# https://github.com/dockerfile/mongodb
#
# Pull base image.
FROM ubuntu:14.04
# Install MongoDB.
@seveniu
seveniu / getResouces.java
Last active July 18, 2016 14:20
java 中获取 resource ,适用于 jar 内资源
InputStream in = getClass().getClassLoader().getResourceAsStream("ParseResult.groovy");
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
StringBuilder builder = new StringBuilder();
String aux = "";
while ((aux = reader.readLine()) != null) {
builder.append(aux);
}
String text = builder.toString();
@seveniu
seveniu / readFile.js
Created March 25, 2016 02:34
nodejs read file
var fs = require('fs');
var filePath = process.argv[2];
fs.readFile(filePath, {encoding: 'utf-8'}, function(err,data){
if (!err){
console.log('received data: ' + data);
}else{
console.log(err);
@seveniu
seveniu / listToTree.js
Created December 4, 2015 14:01
javascript list to tree
function ListToTree(data,deep,getChildren) {
this.stackListLength = deep -1-1; //不包含 root
this.stackList = [];
// 初始化 root
this.root = {id: 0};
// 初始化 栈
@seveniu
seveniu / run.sh
Last active September 25, 2015 06:42
用于创建一个MySQL docker 容器,用的 docker file 是官方的 https://github.com/docker-library/mysql
#!/bin/bash
######## eg.
#./run.sh mysql-test password /home/java/conf-files/mysql 3306 official/mysql:5.7 /data/mysql/test/
########
name=$1
password=$2
confDir=$3
port=$4
@seveniu
seveniu / country.json
Last active September 15, 2015 05:09
country list . with: code, english, Chinese, pinyin, pinyin first letter
[
{
"id": 1,
"value": "AD",
"zh": "安道尔共和国",
"en": "Andorra",
"py": "andaoergongheguo",
"pyf": "adeghg"
},
{
@seveniu
seveniu / util.js
Last active August 29, 2015 14:27
javascript util
var util = {
getDomain:function (url) {
var a = document.createElement('a');
a.href = url;
return a.hostname;
},
isNumber:function (n) {
return !isNaN(parseFloat(n)) && isFinite(n);
public static String xorString(String text,String key) {
byte[] textBytes = text.getBytes();
byte[] keyBytes = key.getBytes();
byte[] newCharArray = new byte[textBytes.length];
for (int i = 0; i < textBytes.length; i++) {
byte c = textBytes[i];
int strIndex = i%(keyBytes.length);
newCharArray[i] = (byte)(c ^ keyBytes[strIndex]);
}
return new String(newCharArray);