Skip to content

Instantly share code, notes, and snippets.

Avatar

Lattapon Yodsuwan clozed2u

View GitHub Profile
View sol.js
const input = ["ab", "aabbcc", "ababab", "abaabcca"];
const sol = (words) =>
words.map(
(word) =>
word.split("").reduce(
(prev, cur) =>
prev.lastChar === cur
? {
...prev,
View poc.go
package main
import (
"github.com/labstack/echo/v4"
"net/http"
)
type Response struct {
Data interface{} `json:"data,omitempty"`
Status string `json:"status,omitempty"`
View r.go
package main
import (
"fmt"
"math/rand"
"time"
)
func main() {
candidates := []string{
View log.md

#todayilearned #onunixandgo

  • log เป็นสิ่งจำเป็น เอาไว้ debug, track, alert พวก monitoring ทั้งหลายถ้าไม่ส่องจาก log เอาเองก็ต้องมี plugin เป็น forwarder ซึ่งก็มาเกาะจาก log อยู่ดี
  • ใน unix มี system log (syslog on mac, rsyslog on linux) ส่วนใหญ่เก็บไว้ใน /var/log แล้วแต่ config
  • System log เป็น client - server อยาก write log ก็ forward message with severity via udp/tcp/socket ไปหา facilities
  • facilities ประกอบไปด้วย kernel, user, auth, mail, etc...
  • severity ก็พวก debug, info, warning, error, etc...
  • ใน Go มี standard package log เอาไว้ write log
  • ใน Go มี standard package syslog เอาไว้ write system log
View tmux-cheatsheet.markdown

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
View bingap.go
package main
import (
"fmt"
"strconv"
)
func binaryGap(n int) int {
binStr := string(strconv.FormatInt(int64(n), 2))
longestGap := 0
View hangman.go
func hangman(secretWord string, letters []string) bool {
lettersMap := make(map[string]bool)
for _, v := range letters {
lettersMap[v] = true
}
for _, v := range secretWord {
_, ok := lettersMap[string(v)]
if !ok {
return false
}
View product.json
[
{
"name": "Children of Blood and Bone (Legacy of Orisha)",
"id": 1,
"description": "With five starred reviews, Tomi Adeyemi’s West African-inspired fantasy debut, and instant #1 New York Times Bestseller, conjures a world of magic and danger, perfect for fans of Leigh Bardugo and Sabaa Tahir.",
"price": 11.39,
"img_url": "https://images-na.ssl-images-amazon.com/images/I/61SB-c0mHGL._SX329_BO1,204,203,200_.jpg"
},
{
"name": "Girl, Wash Your Face: Stop Believing the Lies About Who You Are so You Can Become Who You Were Meant to Be",
View json_custom_time.go
package main
import (
"encoding/json"
"fmt"
"strings"
"time"
)
const messageTimeLayout = "2006/01/02 15:04:05 -0700"
@clozed2u
clozed2u / json_time.go
Last active Apr 16, 2018
Custom time format in json
View json_time.go
package main
import (
"encoding/json"
"fmt"
"time"
)
type Message struct {
Text string