Skip to content

Instantly share code, notes, and snippets.

@phstudy
phstudy / Iterables.java
Last active June 4, 2016 16:59 — forked from popcornylu/Iterables.java
Iterable transformation
import org.apache.commons.collections4.IterableUtils;
import java.util.function.Function;
public class Iterables {
public static <F, T> Iterable<T> map(
Iterable<F> iterable,
Function<F, T> mapper) {
return IterableUtils.transformedIterable(iterable, (x) -> mapper.apply(x));
}
@phstudy
phstudy / crash.log
Created February 5, 2016 09:30
2016-02-05 azure sg vm crash
Feb 5 09:01:01 localhost systemd: Started Session 81 of user root.
Feb 5 09:01:01 localhost systemd: Starting Session 81 of user root.
Feb 5 09:01:01 localhost systemd: Removed slice user-0.slice.
Feb 5 09:01:01 localhost systemd: Stopping user-0.slice.
Feb 5 10:01:01 localhost systemd: Created slice user-0.slice.
Feb 5 10:01:01 localhost systemd: Starting user-0.slice.
Feb 5 10:01:01 localhost systemd: Started Session 82 of user root.
Feb 5 10:01:01 localhost systemd: Starting Session 82 of user root.
Feb 5 10:01:01 localhost systemd: Removed slice user-0.slice.
@phstudy
phstudy / create_docker_vm.ps1
Created April 25, 2015 04:13
create docker vm
azure vm docker create -e 22 -l 'West US' VM_NAME "b39f27a8b8c64d52b05eac6a62ebad85__Ubuntu-14_04-LTS-amd64-server-20140618.1-en-us-30GB" ACCOUNT PASSWORD
@phstudy
phstudy / install_windows_azure-cli.ps1
Created April 25, 2015 02:12
install azure-cli and download certificate
npm install azure-cli -g
azure account download
@phstudy
phstudy / install_windows_docker_client.ps1
Last active August 29, 2015 14:19
install windows docker client
iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))
choco install docker -y
choco install nodejs.install -y
choco install rsync -y
choco install openssl.light -y
@phstudy
phstudy / 5postgres.sh
Created April 25, 2015 00:29
run 5 postgres container
for i in 1 2 3 4 5; do
sudo docker run --name="postgres-$i" -d postgres
done
@phstudy
phstudy / Vagrantfile
Created April 25, 2015 00:27
run 5 vms
Vagrant.configure("2") do |config|
config.vm.define "vm1" do |vm1|
vm1.vm.box = "puppetlab-centos-64-nocm"
end
config.vm.define "vm2" do |vm2|
vm2.vm.box = "puppetlab-centos-64-nocm"
end
config.vm.define "vm3" do |vm3|
@phstudy
phstudy / AwsSignatureV4Utils.java
Created April 21, 2015 17:32
AWS Signature Version 4 Utils for Java
import java.io.UnsupportedEncodingException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import org.apache.shiro.codec.Hex;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@phstudy
phstudy / MapApplication.java
Created March 13, 2015 08:58
side effect mapUsingReduce
public class MapApplication {
// case 1
public static <I, O> List<O> mapUsingCollect(Stream<I> stream, Function<I, O> mapper) {
return stream.collect(ArrayList::new, (acc, element) -> acc.add(mapper.apply(element)), ArrayList::addAll);
}
// case 2
public static <I, O> List<O> mapUsingReduce(Stream<I> stream, Function<I, O> mapper) {
return stream.reduce(new ArrayList<>(), (acc, element) -> {
@phstudy
phstudy / gist:32686673db55c4213364
Created January 23, 2015 10:40
logstash-logback-encoder.json
{
"@timestamp": "2015-01-23T10:38:18.065+00:00",
"@version": 1,
"@message": "0:0:0:0:0:0:0:1 - - [2015-01-23T10:38:18.065+00:00] \"GET /t HTTP/1.1\" 200 43",
"@fields.method": "GET",
"@fields.protocol": "HTTP/1.1",
"@fields.status_code": 200,
"@fields.requested_url": "GET /t HTTP/1.1",
"@fields.requested_uri": "/t",
"@fields.remote_host": "0:0:0:0:0:0:0:1",