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,
@clozed2u
clozed2u / pyenv.sh
Last active Nov 10, 2020
Install python 2.7.10 with pyenv on centos 7
View pyenv.sh
# install python 2.7.10 with pyenv on centos 7
yum install -y gcc gcc-c++ make git patch openssl-devel zlib-devel readline-devel sqlite-devel bzip2-devel
git clone git://github.com/yyuu/pyenv.git ~/.pyenv
echo 'export PATH="$HOME/.pyenv/bin:$PATH"' >> .bashrc
echo 'eval "$(pyenv init -)"' >> .bashrc
pyenv install 2.7.10
pyenv global 2.7.10
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{
@clozed2u
clozed2u / rbenv.sh
Last active Sep 24, 2019
Install ruby 2.2.3 with rbenv and ruby-build on Ubuntu 14.04
View rbenv.sh
# install ruby 2.2.3 with rbenv on ubuntu 14.04
sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev
git clone git://github.com/sstephenson/rbenv.git ~/.rbenv
git clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
git clone https://github.com/sstephenson/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
exec $SHELL
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
}
@clozed2u
clozed2u / gist:4971506
Last active Sep 16, 2018
My .bash_profile setup on OS X. Modified from Mark Otto's bash style (http://markdotto.com/2013/01/13/improved-terminal-hotness/) by adding git color for status.
View gist:4971506
alias ls='ls -Glah'
alias web='open -a Safari.app'
alias mail='open -a Mail.app'
alias todo='open -a Reminders.app'
git_branch () {
if git rev-parse --git-dir >/dev/null 2>&1
then echo -e "" [$(git branch 2>/dev/null| sed -n '/^\*/s/^\* //p')]
else
echo ""
fi