Skip to content

Instantly share code, notes, and snippets.

@Configuration
public class ExecuteServiceConfiguration {
@Bean
public ExecutorService executorService() {
return new ThreadPoolExecutor(
20,
50,
60, TimeUnit.SECONDS,
new ArrayBlockingQueue<>(2000), r -> {
Thread thread = new Thread(r);
@cloudhuang
cloudhuang / SequenceGenerator.java
Last active July 11, 2024 09:38
Generating unique IDs in a distributed environment at high scale
import java.net.NetworkInterface;
import java.security.SecureRandom;
import java.time.Instant;
import java.util.Enumeration;
/**
* Distributed Sequence Generator.
* Inspired by Twitter snowflake: https://github.com/twitter/snowflake/tree/snowflake-2010
*
version: '3'
services:
zookeeper:
image: zookeeper
ports:
- 2181:2181
redis:
image: redis
ports:
- 6379:6379
@cloudhuang
cloudhuang / Vagrantfile
Created January 10, 2018 03:45 — forked from adeubank/Vagrantfile
Vagrantfile for setting up Ubuntu 14.04 with Java 8 and Tomcat 8
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure(2) do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# replace old_string with new_string in the path recursively
sed -i '' 's/old_string/new_string/g' $( find /path -name file_name )
@cloudhuang
cloudhuang / installJDK8.sh
Last active August 29, 2015 14:24
Install JDK8 on ubuntu
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
@cloudhuang
cloudhuang / SimpleRubyHttpServer
Created December 18, 2014 09:03
ruby SimpleHttpServer
ruby -run -e httpd . -p 5000
@cloudhuang
cloudhuang / download_lets_code.rb
Last active August 29, 2015 14:04
Download all episodes from http://download.orfjackal.net/lets-code/ for TDD learning
# Required for windows:
# Download wget utlity for windows
require 'nokogiri'
require 'open-uri'
# Get a Nokogiri::HTML::Document for the page we’re interested in...
doc = Nokogiri::HTML(open('http://download.orfjackal.net/lets-code/'))
@cloudhuang
cloudhuang / URLClassLoader.java
Last active December 26, 2015 02:19
URL class loader
URLClassLoader classLoader = null;
try {
// create url class loader to load the servlet class
URL[] urls = new URL[1];
URLStreamHandler urlStreamHandler = null;
File classPath = new File(Constents.WEB_ROOT);
String repository = (new URL("file", null, classPath.getCanonicalPath() + File.separator)).toString();
# update & upgrade ubuntu
sudo apt-get update
sudo apt-get upgrade
# install fcixt fcitx-googlepinyin
sudo add-apt-repository ppa:fcitx-team/nightly -y
sudo apt-get update
sudo apt-get install fcitx fcitx-googlepinyin
# cinnamon