Skip to content

Instantly share code, notes, and snippets.

View up1's full-sized avatar

Somkiat Puisungnoen up1

View GitHub Profile
@up1
up1 / PersonValidator.java
Created January 13, 2015 03:11
Java 8 Stream :: Validate
public class PersonValidator {
public boolean validate(Person person) {
boolean valid = person != null;
if (valid) {
valid = person.getName() != null;
}
if (valid) {
valid = person.getEmail() != null;
}
@up1
up1 / FizzBuzzFluentTest.java
Last active August 29, 2015 14:14
Demo :: given-when-then
@RunWith(JunitSuiteRunner.class)
public class FizzBuzzFluentTest {
{
describe("FizzBuzz game", it -> {
it.should("say Fizz", expect -> {
FizzBuzz fizzBuzz;
Given:
fizzBuzz = new FizzBuzz(3);
@up1
up1 / elasticsearch.yml
Last active August 29, 2015 14:14
Scaling Elasticsearch
# As it is a name used to identify clusters, use a name with uniqueness and a meaning.
cluster.name: ElasticSearch-cluster
# A node name is automatically created but it is recommended to use a name that is discernible in a cluster like a host name.
node.name: "Elasticsearch.my01"
# The default value of the following two is all true. node.master sets whether the node can be the master, while node.data is a configuration for whether it is a node to store data. Usually you need to set the two values as true, and if the size of a cluster is big, you should adjust this value by node to configure three types of node. More details will be explained in the account of topologies configuration later.
node.master: true
node.data: true
@up1
up1 / q4.sql
Created February 12, 2015 04:54
Demo :: Google BigQuery
select
repository_language,
type,
count(distinct(repository_url)) as active_repos_by_url,
count(repository_language) as events,
YEAR(created_at) as year,
QUARTER(created_at) as quarter
from [githubarchive:github.timeline]
where
(
@up1
up1 / myday.java
Created February 17, 2015 06:57
Demo :: What How When
public void aboutMyDay() {
boolean isWakeUp = wakeUp();
if( isWakeUp ) {
boolean isShower = shower();
if( isShower ) {
boolean isClothe = putClothe();
if( isClothe ) {
...
}
}
@up1
up1 / 1.java
Last active August 29, 2015 14:15
If-Else
if (x < 0) {
throw new Exception("ข้อมูลไม่สามารถติดลบได้นะ");
} else {
System.out.println("แจ่ม ทำงานได้");
}
@up1
up1 / Money.java
Last active August 29, 2015 14:16
Unit Test :: Demo
public class Money {
private int amount;
private String currency;
public Money(int amount, String currency) {
this.amount = amount;
this.currency = currency;
}
public int amount() {
@up1
up1 / Money.java
Last active August 29, 2015 14:16
Unit test :: demo 2
public class Money {
...
public Money add(Money money) {
return new Money(amount() + money.amount(), currency());
}
...
}
@up1
up1 / 1.java
Last active August 29, 2015 14:16
Java8 :: String Join
private static final String COMMA_DELIMITER = ",";
//แบบที่ 1
String[] names = {"I", "love", "You"};
System.out.println( String.join(COMMA_DELIMITER, names) );
//แบบที่ 2
System.out.println(String.join(COMMA_DELIMITER, "I", "love", "You"));
@up1
up1 / build.gradle
Created March 11, 2015 10:29
Unit test on Android application
evaluationDependsOn(":app")
apply plugin: 'java'
dependencies {
def androidModule = project(':app')
testCompile project(path: ':app', configuration: 'debugCompile')
def debugVariant = androidModule.android.applicationVariants.find({it.name == 'debug'})