Skip to content

Instantly share code, notes, and snippets.

View up1's full-sized avatar

Somkiat Puisungnoen up1

View GitHub Profile
@up1
up1 / fibomacci.go
Last active August 29, 2015 14:01
Go :: Benchmark
package demo
func Fibonacci(number int) int {
if number < 2 {
return number
}
return Fibonacci(number-1) + Fibonacci(number-2)
}
@up1
up1 / index.go
Last active August 29, 2015 14:01
ElasticSearch with Go
package main
import "github.com/mattbaird/elastigo/api"
import "github.com/mattbaird/elastigo/core"
func main() {
type Address struct {
ProvinceName string `json:"province_name"`
}
@up1
up1 / demo_http_request.go
Last active August 29, 2015 14:01
Demo=> Interface in Go
package main
import (
"fmt"
"net/http"
)
type Counter struct {
n int
}
@up1
up1 / index.txt
Last active August 29, 2015 14:02
ElasticSearch with Auto suggestion
curl -XPUT http://localhost:9200/suggestion -d '{
"mappings": {
"address": {
"properties": {
"province_id": {"type": "integer"},
"province_code": {"type": "string"},
"province_name": {"type": "string"},
"province_name_suggest" : {
"type" : "completion"
}
@up1
up1 / add.go
Last active August 29, 2015 14:02
ElasticSearch with Payload
type Payload struct {
ProvinceID int `json:"province_id"`
}
type Suggest struct {
Input string `json:"input"`
Output string `json:"output"`
Payload Payload `json:"payload"`
}
@up1
up1 / MyResource.java
Last active August 29, 2015 14:02
Demo :: Create RESTful Web Service with Jersey
package com.rest.demo;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Path("myresource")
public class MyResource {
@up1
up1 / counter01.go
Last active August 29, 2015 14:02
Go => Using expvar
package main
import (
"expvar"
"log"
)
var (
counter = expvar.NewInt("counter for my program")
)
@up1
up1 / Exception.java
Last active August 29, 2015 14:02
Demo :: Develop RESTful web service with Spark
exception(IllegalArgumentException.class, (e, req, res) -> {
res.status(400);
res.body(toJson(new ResponseError(e)));
});
@up1
up1 / hack.php
Created June 17, 2014 06:28
Hack :: Demo
<?hh
function sayHello(string $name): string {
return "Hello ". $name . "! ". PHP_EOL;
}
echo sayHello("Up1");
@up1
up1 / demo01.js
Last active October 25, 2016 04:26
Demo :: Asynchronous
var fs = require("fs");
fs.readFile("mydata.json", function(err, content) {
if (err) {
console.error("Got an error", err);
} else {
console.log("Got result");
}
});
console.log("After call readFile")