Skip to content

Instantly share code, notes, and snippets.

@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",
@phstudy
phstudy / gist:08eb45fb1bfc941eb138
Created December 30, 2014 07:11
gradle invoke external command
task dockerPushImage(type: Exec, dependsOn: dockerBuildImage) {
environment 'DOCKER_HOST', 'tcp://127.0.0.1:2375'
commandLine "${project.dockercmd}", "push", "${project.dockerhub}/dmp-web:${dockerTagVer}"
}
@phstudy
phstudy / docker_machine_on_azure
Last active August 29, 2015 14:11
docker machine on azure
14:11:09 study-mbpr: Downloads$ ./darwin create -d azure --azure-publish-settings-file="Study Lab.-12-9-2014-credentials.publishsettings" --azure-password="------------" --azure-username="study" study-docker
INFO[0000] Creating Azure host...
INFO[0058] Waiting for SSH...
INFO[0143] Waiting for docker daemon on host to be available...
INFO[0194] "study-docker" has been created and is now the active machine. Docker commands will now run against that machine.
14:14:55 study-mbpr: Downloads$ ./darwin ls
NAME ACTIVE DRIVER STATE URL
study-docker * azure Running tcp://docker-host-87211309ea05.cloudapp.net:4243
@phstudy
phstudy / gist:4a637bcf87c5e7497d56
Created November 18, 2014 03:18
azure create vm
+ Creating VM
error: Windows Azure is currently performing an operation with x-ms-requestid c890872725eb3f6b8a763353e5a88296 on this deployment that requires exclusive access.
info: Error information has been recorded to azure.err
error: vm create command failed
./attach-disk.sh rtb-cassandra88 tenmaxdb2 4 100