Skip to content

Instantly share code, notes, and snippets.

View up1's full-sized avatar

Somkiat Puisungnoen up1

View GitHub Profile
@up1
up1 / composer.json
Last active August 29, 2015 14:18
Demo :: PHP + CI
{
"require-dev": {
"phpunit/phpunit": "4.1.*"
},
"autoload": {
"classmap": ["web/"]
}
}
@up1
up1 / CalculateSize.java
Last active August 29, 2015 14:18
Demo :: java cast type
public class CalculateSize<T> {
public int sizeOf(Iterable<T> items) {
int size = 0;
if (items instanceof Collection) {
size = Collection.class.cast(items).size();
} else {
for (Object item : items) {
size++;
}
}
@up1
up1 / find.txt
Created April 6, 2015 05:39
Demo :: simplicity
find . -iname '*.jp*g' -print0 \
| xargs -0 -L 1 -I @ identify -format '%[EXIF:DateTime] %d/%f\n' @ \
| egrep '^[[:digit:]]{4}:04' \
| cut -d' ' -f3- \
| tar -cf april.tar -T -
@up1
up1 / example.txt
Created April 7, 2015 06:00
Demo :: Robot Framework => re-test
*** Settings ***
Library String
*** Testcases ***
Stable test
Should Be True ${True}
Unstable test
${bool} = random_boolean
Should Be True ${bool}
@up1
up1 / example.txt
Last active August 29, 2015 14:19
Elasticsearch :: Example of grouping data
//Step 1 :: Index data
DELETE demo
POST demo/product/
{
"brand": "BrandA",
"id" : "Pro 005",
"name": "Meo",
"barcode" : "000051",
"unit" : 1
@up1
up1 / readfile.java
Created April 21, 2015 06:41
Demo :: Bad code
BufferedReader reader = new BufferedReader( new FileReader (file));
String line = null;
StringBuilder output = new StringBuilder();
while( ( line = reader.readLine() ) != null ) {
output.append(line);
}
@up1
up1 / variable_01.txt
Last active August 29, 2015 14:19
Robot framework :: variable
*** Variables ***
${BASE_URL} url1
${BASE URL} url2
${BASEURL} url3
*** Testcases ***
Hello scalar variable
Log to console ${BASE_URL}
Log to console ${BASE URL}
Log to console ${BASEURL}
@up1
up1 / Employee.java
Last active August 29, 2015 14:19
Demo :: Composition over Inhertiance
abstract class Employee {
public int id;
public abstract void accept(EmployeeVisitor employeeVisitor);
}
class HourEmployee extends Employee {
@Override
public void accept(EmployeeVisitor employeeVisitor) {
@up1
up1 / problem.java
Last active August 29, 2015 14:20
Coding Dojo :: Diamond Print
Input :: A
OutPut
A
Input :: B
Output
A
B B
A
@up1
up1 / range.txt
Created April 29, 2015 10:22
Coding DOJO
Range has a lot of nifty issues.
integer range contains
[2,6) contains {2,4}
[2,6) doesn't contain {-1,1,6,10}
getAllPoints?
[2,6) allPoints = {2,3,4,5}
ContainsRange?
[2,5) doesn't contain [7,10)
[2,5) doesn't contain [3,10)