Skip to content

Instantly share code, notes, and snippets.

View up1's full-sized avatar

Somkiat Puisungnoen up1

View GitHub Profile
@up1
up1 / call.php
Last active August 29, 2015 14:07
PHP 5.6
<?php
class Variadic {
function say(...$messages) {
foreach ($messages as $message) {
echo $message . " ";
}
echo "\n";
}
}
@up1
up1 / Data.java
Last active August 29, 2015 14:07
Conditional Branch
class Data {
public String format(List<String> datas) {
StringBuilder result = new StringBuilder();
boolean first = true;
for(String data : datas) {
if(first) {
first = false;
} else {
result.append(", ");
@up1
up1 / FizzBuzzTest.java
Last active August 29, 2015 14:07
DEmo :: clean test
public class FizzBuzzTest {
FizzBuzz fizzBuzz = new FizzBuzz();
@Test
public void countOneSayOne() {
String said = fizzBuzz.say(1);
assertEquals("1", said);
}
@up1
up1 / factory.java
Last active August 29, 2015 14:07
Demo :: No-IF
public static RegisterRule newInstance(String validatorRule) {
if ("NameEmptyRule".equals(validatorRule)) {
return new NameEmptyRule();
} else if ("NameFormatRule".equals(validatorRule)) {
return new NameFormatRule();
} else if ("EmailEmptyRule".equals(validatorRule)) {
return new EmailEmptyRule();
}
return null;
}
@up1
up1 / mymusic.json
Last active August 29, 2015 14:07
Demo :: Kibana
{
"title": "My Music",
"services": {
"query": {
"list": {
"0": {
"query": "*",
"alias": "",
"color": "#7EB26D",
"id": 0
@up1
up1 / app.log
Last active August 29, 2015 14:07
DEmo :: logstash
[WARN] 2014-02-19 19:26:03.175 [pool-2-thread-8] com.example.logstash.Starter - Sleeping for 9457ms
[WARN] 2014-02-19 19:26:03.176 [pool-2-thread-2] com.example.logstash.Starter - Sleeping for 1584ms
[INFO] 2014-02-19 19:26:05.687 [main] com.example.logstash.Starter - Result null
[INFO] 2014-02-19 19:26:05.687 [main] com.example.logstash.Starter - Result null
[ERROR] 2014-02-19 19:26:08.695 [main] com.example.logstash.Starter - null
java.util.concurrent.TimeoutException: null
at java.util.concurrent.FutureTask$Sync.innerGet(FutureTask.java:258) ~[na:1.7.0_13]
at java.util.concurrent.FutureTask.get(FutureTask.java:119) ~[na:1.7.0_13]
at com.example.logstash.Starter.main(Starter.java:43) ~[classes/:na]
[ERROR] 2014-02-19 19:26:11.696 [main] com.example.logstash.Starter - null
@up1
up1 / 1.txt
Last active August 29, 2015 14:07
Demo :: Zero downtime on Elasticsearch
$curl -XPOST http://localhost:9200/demo/post/1
{
"author": "Somkiat",
"title": "My first post"
}
@up1
up1 / 1.java
Last active August 29, 2015 14:08
Demo :: Tell, Dont' Ask
Widget w = getMyWidget();
if (w.getParent() != null) {
Panel parent = w.getParent();
parent.remove(w);
}
@up1
up1 / devices.txt
Last active August 29, 2015 14:08
R Demo :: Twitter
[1] "coderwall-protips-bot"
[2] "NoSQLDigest"
[3] "Twitter for Websites"
[4] "mikutter"
[5] "TweetDeck"
[6] "Tweetbot for iΟS"
[7] "Mobile Web (M5)"
[8] "Hootsuite"
[9] "TweetDeck"
[10] "Twitter Web Client"
@up1
up1 / Email.java
Last active August 29, 2015 14:08
Demo :: DI
public class Email {
public void send() {
}
}