Skip to content

Instantly share code, notes, and snippets.

View iporsut's full-sized avatar
🏠
Working from home

Weerasak Chongnguluam iporsut

🏠
Working from home
View GitHub Profile
@iporsut
iporsut / mylist.erl
Created May 10, 2015 13:20
mylist flatten
-module(mylist).
-export([flatten/1]).
flatten(L) -> flatten(L, []).
flatten([], Acc) -> Acc;
flatten([H|T], Acc) when is_list(H) -> flatten(T, Acc ++ flatten(H));
flatten([H|T], Acc) -> flatten(T, Acc ++ [H]).
type IO interface {
Read() string
Write(string)
}
@iporsut
iporsut / gist:2a6fad40c682f11d4e85
Created May 4, 2015 09:53
Account use Deposit Method
func main() {
acc := Account{Name: "Weerasak", Balance : 1000.00 }
acc.Deposit(500.00)
fmt.Println(acc)
}
@iporsut
iporsut / gist:91039c160abd863f5be6
Created May 4, 2015 09:52
Account Deposit Method
func (acc *Account) Deposit(amount float64) {
acc.Balance += amount
}
@iporsut
iporsut / gist:c572df037a573adf6700
Created May 4, 2015 09:51
Account use String Method
func main() {
acc := Account{Name: "Weerasak", Balance : 1000.00 }
fmt.Println(acc.String())
pacc := &acc
fmt.Println(pacc.String())
}
@iporsut
iporsut / gist:774c85c3858a0c8403bd
Created May 4, 2015 09:49
Account String Method
func (acc Account) String() string {
return fmt.Sprintf("Account %s have balance %0.2f", acc.Name, acc.Balance)
}
type Account struct {
Name string
Balance float64
}
package main
import "fmt"
func space(ch rune, end rune) (side int, in int) {
if ch == 'A' {
in = 0
} else {
in = int((ch-'A')*2 - 1)
}
@iporsut
iporsut / gist:2f03a716833ea7bfa044
Created March 8, 2015 08:15
go test Example from json format
func ExampleJsonFormat() {
r := bytes.NewReader([]byte(`{"name":"Weerasak"}`))
formated, _ := From(r)
fmt.Println(formated)
// Output:
// {
// "name": "Weerasak"
// }
}
@iporsut
iporsut / gist:a727a0f7cfb8fbf751e8
Created March 7, 2015 13:39
Insert to MongoDB
package main
import (
"log"
"gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
)
func main() {