Skip to content

Instantly share code, notes, and snippets.

View up1's full-sized avatar

Somkiat Puisungnoen up1

View GitHub Profile
@up1
up1 / flow.js
Last active August 29, 2015 14:02
Demo :: Javascript get Location
$(function () {
$.when(getPosition())
.then(lookupCountry)
.done(displayResults)
.fail(displayError)
});
@up1
up1 / demo01.js
Created June 22, 2014 18:27
Demo :: My Promise
var Up1 = function() {
var State = {
PENDING: 0,
FULFILLED: 1,
REJECTED: 2
};
}
@up1
up1 / example.java
Created June 27, 2014 01:08
ตัวอย่างการส่งข้อมูลจาก WebView กลับมายัง Native ผ่าน JavaScript
public class MyBrowser extends Activity {
private final String jsInjectCode =
"function parseForm(event) {" +
" var form = this;" +
" // make sure form points to the surrounding form object if a custom button was used
" if (this.tagName.toLowerCase() != 'form')" +
" form = this.form;" +
" var data = '';" +
" if (!form.method) form.method = 'get';" +
" data += 'method=' + form.method;" +
@up1
up1 / PeronTest2.java
Last active August 29, 2015 14:03
Demo :: DBUnit
private DataSource getDataSource() {
JdbcDataSource dataSource = new JdbcDataSource();
dataSource.setURL(JDBC_URL);
dataSource.setUser(USER);
dataSource.setPassword(PASSWORD);
return dataSource;
}
@up1
up1 / hello.yaml
Created July 2, 2014 05:03
Demo :: Stubby4j
- request:
method: GET
url: /hello-world
response:
status: 200
headers:
content-type: application/json
body: '{"id": 1, "name": "Up1"}'
@up1
up1 / before.java
Last active August 29, 2015 14:03
Demo :: Working with File system
@Before
public void createCSVFile() throws Exception {
file = temporaryFolder.newFile("input.txt");
PrintWriter out = new PrintWriter(file);
out.print("1,2,3,4,5");
out.close();
}
@up1
up1 / FizzBuzzTest.java
Last active August 29, 2015 14:03
Demo :: JUnit + Oleaster
import org.junit.runner.RunWith;
import static org.junit.Assert.*;
import static com.mscharhag.oleaster.runner.StaticRunnerSupport.*;
import com.mscharhag.oleaster.runner.OleasterRunner;
@RunWith(OleasterRunner.class)
public class FizzBuzzTest {
private FizzBuzz fizzBuzz;
@up1
up1 / EmailFormatRule.java
Last active August 29, 2015 14:04
Demo :: Validation input
public class EmailFormatRule implements RegisterRule {
public void validate(User user) {
String EMAIL_PATTERN = "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
Pattern validEmailPattern = Pattern.compile(EMAIL_PATTERN);
if( !validEmailPattern.matcher(user.getEmail()).matches() ) {
throw new IllegalArgumentException("Email is wrong format");
}
}
@up1
up1 / AbstractCSVReader.java
Last active August 29, 2015 14:05
Demo :: Using Template Method Pattern
public abstract class AbstractCSVReader<T> {
public List<T> getAll(File file) throws Exception {
List<T> returnData = new ArrayList<>();
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
String line = reader.readLine();
while (line != null && !"".equals(line.trim())) {
String[] tokens = line.split("\\s*,\\s*");
T data = unmarshall(tokens);
returnData.add(data);
@up1
up1 / array_sort.html
Created August 11, 2014 03:37
Demo :: Manage array with JavaScript
<script>
var arr = [];
function onAdd() {
arr.push({
key: Math.floor((Math.random() * 100) + 1),
cutomerCode: 1234,
clientCode: 2344
});