Skip to content

Instantly share code, notes, and snippets.

View nomkhonwaan's full-sized avatar
💭
while(me.awake()) { me.code(); }

Natcha Luangaroonchai nomkhonwaan

💭
while(me.awake()) { me.code(); }
View GitHub Profile
@nomkhonwaan
nomkhonwaan / log.go
Last active May 7, 2022 15:43
go-solid-interface-segregation-5dfc2eada33fd7a8f2eebc5c
// WriteLog writes change log data into the file.
// A successful writing will return nil.
// When unable to write, an error will be returned.
func WriteLog(f *os.File, c ChangeLog) error
@nomkhonwaan
nomkhonwaan / graphql_after_refactor.go
Last active April 18, 2020 10:59
เว็บบล็อกเวอร์ชัน-2-1-code-refactoring-5e6b952d6f62018fc5b8ff23
/* schema.go */
// BuildSchema accepts build schema function(s) for applying to the schemabuilding.Schema object
func BuildSchema(buildSchemaFunc ...func(*schemabuilder.Schema)) (*graphql.Schema, error) {
s := schemabuilder.NewSchema()
for _, f := range buildSchemaFunc {
f(s)
}
return s.Build()
}
@nomkhonwaan
nomkhonwaan / main.go
Last active April 11, 2020 10:54
prototype-pattern-ใน-go-5e9088fc0e16fb18c1d56c13
package main
import (
"net/smtp"
"strings"
)
func main() {
s := NewNoAuthSender("localhost:25")
err := s.From("[email protected]").
package main
import (
"encoding/json"
"github.com/go-chi/chi"
uuid "github.com/satori/go.uuid"
"log"
"math/rand"
"net/http"
"time"
@nomkhonwaan
nomkhonwaan / fasthttp.go
Last active February 26, 2020 00:49
unit-testing-กับแพคเกจ-valyala-fasthttp-5e40801aaf437cc917f05226
package main
import (
"log"
"github.com/valyala/fasthttp"
)
func main() {
log.Println("fasthttp server is listening on :8080")
@nomkhonwaan
nomkhonwaan / arduino-rc-car-via-bluetooth.ino
Last active January 19, 2020 14:55
ทำรถบังคับผ่าน-bluetooth-ด้วย-arduino-uno-r3-5e167a97981019ba2e7cb395
// The L293D output parameters for controlling DC motor.
// Each DC motor will be controled by 3 parameters which are
// PxA, PyA for sending high or low value and PxyEN for sending enable or disable value.
#define P1A 4
#define P2A 5
#define P12EN 8
#define P3A 6
#define P4A 7
#define P34EN 9
@nomkhonwaan
nomkhonwaan / employee.go
Last active January 10, 2020 02:02
go-solid-single-responsibility-5dfc2e5da33fd7a8f2eebc59
// Money represents currency in Thai Baht
type Money float64
// Employee is a person employed by a company
type Employee struct {
// An amount to-be paid per working hour
salaryPerHour Money
// A total number of working hours of the employee
workingHours int
@nomkhonwaan
nomkhonwaan / main.go
Last active January 2, 2020 03:01
go-solid-open-closed-5dfc2e81a33fd7a8f2eebc5a
package main
import "fmt"
type square struct {
width, height int
}
func main() {
s := square{width: 10, height: 10}
@nomkhonwaan
nomkhonwaan / main.go
Last active December 27, 2019 07:26
repository-pattern-ใน-go-5dfc2ab8ec12f08f3649c983
package main
import (
"context"
"database/sql"
"fmt"
_ "github.com/go-sql-driver/mysql"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
@nomkhonwaan
nomkhonwaan / graceful-shutdown-worker-pool-with-cancel.go
Last active December 19, 2019 13:35
ต่อ-การทำ-graceful-shutdown-กับ-worker-pool-ใน-go-5df5070c8883fdeaea7306cb
package main
import (
"context"
"fmt"
"math/rand"
"os"
"os/signal"
"sync"
"syscall"