วันพฤหัสบดีที่ 1 มิถุนายน พ.ศ. 2560

การใช้งาน vim กับ golang

Memo ไว้หน่อยเดี๋ยวลืมวิธีการตั้งค่า vim กับ go

1. การที่จะทำให้ vim autocomplete ได้นั้นจะต้องเป็น vim version 7.4+  และควรจะ compile enable lua มาด้วย

บน OSX ใช้คำสั่ง

brew install vim --with-lua
จากนั้น set alias ให้ ใช้ vim บน vim ที่ติดตั้งใหม่ แล้วแต่ว่าใช้ shell ตัวไหน .zshrc หรือ .bashrc 


alias vi="/usr/local/Cellar/vim/8.0.0604/bin/vim"
alias vim="/usr/local/Cellar/vim/8.0.0604/bin/vim"


2. ติดตั้ง vim-go https://github.com/fatih/vim-go
ซึ่งมีวิธีติดตั้ง ง่ายๆดังนี้
https://github.com/fatih/vim-go-tutorial#quick-setup

curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
git clone https://github.com/fatih/vim-go.git ~/.vim/plugged/vim-go

3. set vimrc โดยการ สั่ง 
go get github.com/fatih/vim-go-tutorial
จะได้ vimrc template มาโดยจะอยู่ที่  GOPATH/src/github.com/fatih/vim-go-tutorial/   ให้ copy ไปแทน ~/.vimrc ได้เลย

4. ติดตั้ง plugin ทั้งหมด โดยการเปิด vim แล้วพิมพ์คำสังติดตั้ง plugin ดังนี้

:GoInstallBinaries

 5. ส่วนตัวผมใช้ wakatime ต้องลง plugin wakatime ซึ่งต้องใช้ Vundle ฉะนั้นจะต้องลง Vundle เพิ่ม

$ git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim

6. แก้ไข .vimrc เพิ่มคำสั่งดังนี้ต่อท้าย file 


set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'wakatime/vim-wakatime'
call vundle#end()

7. ติดตั้ง plugin ของ vbundle โดยเรียก vim แล้วใช้คำสั่ง

:PluginInstall

8. ติดตั้ง neocomplete


git clone https://github.com/Shougo/neocomplete.vim.git ~/.vim/neocomplete.vim

[สำคัญมาก] copy file ทุก file ที่อยู่ใน ~/.vim/neocomplete.vim/ ออกมาไว้ใน ~/.vim

จากนั้นแก้ไข file ~/.vimrc เพิ่มข้อมูลดังนี้ต่อท้าย file


let g:neocomplete#enable_at_startup = 1 
let g:neocomplete#enable_smart_case = 1 
let g:neocomplete#sources#syntax#min_keyword_length = 3 

9. การเรียกใช้คำสั่ง build run test ของ go สามารถเรียกผ่าน vim ได้เลย

:GoRun:GoInstall:GoTest

10. สามารถเรียก autocomplete เองได้ ถ้าไม่ได้ใช้ neocomplete โดยการกด CTRL+X+O หรือ CTRL+P

11. ติดตั้ง NERDTree
ใช้ Plug  เป็นตัวช่วยติดตั้งโดย edit ~/.vimrc เพิ่มบรรทัดนี้ลงไป


Plug 'scrooloose/nerdtree'

และเพิ่ม ให้กด CTRL+o ให้เปิด NERDTree


map <C-o> :NERDTreeToggle<CR>

ถ้าใครต้องการให้เข้า vim  แล้วเปิด NERDTree เลยก็สามารถทำได้โดยเพิ่มคำสั่งดังนี้


autocmd VimEnter * NERDTree

จากนั้นเข้า vim  แล้วพิมพ์คำสั่ง PlugInstall



วันพฤหัสบดีที่ 8 กันยายน พ.ศ. 2559

Apple Special Event. September 7, 2016

มีอะไรใหม่บ้างใน keynote คืนนี้

Nintendo ทำ mario ลงใน iOS

Design ให้เล่นได้บนมือเดียว (เหมาะสำหรับ คนที่เดินทางอยู่ เช่นโหนรถไฟอยู่)


จะมี Super Mario sticker ให้บน iMessage ด้วย


App สำหรับหัดให้เด็กเขียน code บน iPad 



iWork ทำงานร่วมกันได้หลายคนพร้อมๆกัน


Apple watch เล่น Pokemon ได้แล้ว !!!!!


จับ pokemon ไม่ได้  แต่ทำได้ทุกอย่าง ปั่น Poke stop ได้ เตือนเมื่อเจอ Pokemon ใกล้ๆ ดู item ใน กระเป๋าได้


ฟักไข่ก็ได้   (แล้ว Pokemon plus ก็จะขายในเดือนหน้า แบบนี้ใครมี apple watch ก็ไม่จำเป็นต้องซื้อ Pokemon plus เลย)


apple watch ตัวใหม่ ก็คล้ายๆเดิมคือ แรงขึ้น ทำอะไรได้เยอะขึ้น แต่ที่สำคัญ Build in GPS กันน้ำได้ และสามารถใส่ว่ายน้ำได้แล้ว

Apple Watch Nike Plus Design สำหรับนักกีฬาเลย

Best partner for runner Nike เค้าว่างั้น


iOS 10 map design ใหม่อีกละ
siri ฉลาดขึ้น
keyboard เดาเก่งขึ้น


iMessage ตัวใหม่ มี sticker พื้นหลังเปลี่ยนได้ ส่ง ดุ๊กดิ๊กๆด้

iPhone 7 (This is the best iPhone we ever made อีกแล้ว)

ปุ่ม Home ทำอะไรได้มากกว่าเดิม เขียนโปรแกรมต่อได้
 กันน้ำกันฝุ่นได้
กล้อง มีกันสั่นได้ในตัว




อันนี้น่าสนใจ มี chip process รุปโดยเฉพาะ ใช้ Deep learn process เป็น 100 billion opration ภายในเวลา 25 มิลลิวินาที
present ว่าถ่ายมาแทบจะไม่ต้อง retouch เลย




กล้องหน้า 7 ล้าน กล้องหลัง 12 ล้าน



iPhone 7 Plus มี กล้อง 2 ตัวมี zoom feture เพราะใช้กล้อง 2 ตัว
x2 zoom = hard ware zoom
x5 + = software zoom


ปรับสีแค่ลากมือจากข้างจอมา รูปที่แสดงจะ live update สีตาม location ที่นิ้วลาก

ก่อนจะพูดถึงหูฟัง ตัวเครื่อง ลำโพงเป็นแบบ สเตอริโอแล้ว เป็น iPhone ตัวแรกที่มีลำโพงติดเครื่องเป็นแบบ สเตอริโอ

หูฟัง ไร้สายแล้ว Air Pods
- มี chip ประมวลผล w1
- มี ir เชคว่า เสียบเข้าหูหรือยังถ้ายังไม่เสียบก็ไม่ทำงาน
- พูดกับ siri ได้เหมือนเดิมมี ระบบตรวจสอบการสั่นสะเทือนทำให้ ประมวลผลคำพูดแม่นขึ้น
- แตะๆ ที่หูฟัง มี sensor สั่นสะเทือนคอยรับคำสั่ง พวกเปลี่ยนเพลง เร่งเสียง เหมือน ปุ่มกดติดสาย ของเก่า
- มีแท่นชาตของตัวเอง




ขายราวๆตุลา

chip ใหม่ เร็วกว่า iPhone 6  40%

 Graphic chip เร็วขึ้นกว่า iPhone 6 50%


ภาพในเกมไม่ต้องบอกสวยยังกะเครื่อง play 2-3 เลย

แบตอึดขึ้นกว่า iPhone 6  6s ประมาณ 1-2 hr


iOS 10   13 กันยา


วันพฤหัสบดีที่ 18 สิงหาคม พ.ศ. 2559

วิธีการคำนวณ Damage ใน Pokemon Go

ชั่วโมงนี้ คงไม่มีอะไร Hot Hit ไปกว่า Pokemon Go เพราะไปที่ไหนที่ไหนก็เห็นแต่คนถือโทรศัพ ยิ่งจุดไหนมี rare pokemon เกิด คนรุ่มกันยังกะมีของแจกฟรี

ประเด็นของคนที่เล่นแบบจริงจังคือเน้นตี Gym เพื่อ Claim เอาเหรีญ Pokemon การที่จะได้มาซึ่ง Gym เราจะต้อง ต่อสู้ และในการต่อสู้ Damage ที่ทำได้นั้นสำคัญมาก วันนี้ผมขอพูดถึงวิธีการคำนวณหา damage ที่ Pokemon ของเรา จะทำได้ในการสู้กับ Pokemon ที่ตั้งรับอยู่


สมมุติให้ Pokemon ที่ตั้งรับอยู่คือ Eevee น้ำ


ข้อมูลที่เราหาได้คือ
[Defender]
- Trainer LV = 23
- Pokemon CP = 1967
- Pokemon IV (ATK/DEF/STA) = ?? / ?? / ??


Pokemon ทุก version ธาตุสำคัญมาก การจะทำ damage ให้ได้สูงๆนั้น จะต้อง เอาธาตุที่ชนะทางกันไปสู้ตามตารางด้านล่าง



จะเห็นได้ว่า Eevee ธาตุน้ำ แพ้ทาง Pokemon ประเภท พืช และสายฟ้า ในตัวอย่างนี้จึงขอเปรียบเทียบ  Damage ที่เกิดจาก Victreebel และ Eevee สายฟ้า

ข้อมูลฝั่ง Attacker ที่ได้คือ

[EeVee สายฟ้า]
- Trainer lv = 25 (lv ของผมเอง ณ.ขณะนี้)
- Pokemon CP = 1211
- Pokemon IV (ATK/DEF/STA) = 15/13/15

[Victreebel]
- Trainer lv = 25 (lv ของผมเอง ณ.ขณะนี้)
- Pokemon CP = 1338
- Pokemon IV (ATK/DEF/STA) = 13/13/15

สูตรในการคำนวณ Damage คือ

Damage = Floor(0.5*(ATK/DEF) * (CpM_ATK/CpM_DEF) * STAB * Type*MovePower ) +1

Floor = ปัดเศษทศนิยม
ATK = Base ATK + IV ATK    
DEF = Base DEF + IV DEF
*** Base ATK ,DEF หาได้จาก https://pokemongo.gamepress.gg/pokemon-list-advanced
*** ค่า IV หาได้จาก เว็บคำนวณ IV หรือ Application เช่น https://pogo.earthchie.com/#!/home/
CpM_ATK = ค่าคงที่ lv ของคนโจมตี
CpM_DEF = ค่าคงที่ lv ของคนป้องกัน
*** CpM_ATK , CpM_DEF หาได้จาก หาได้จาก https://pokemongo.gamepress.gg/cp-multiplier
STAB = Same Type Attack Bonus  x 1.25 ถ้า ท่าที่โจมตีตรงธาตุของตัวเอง
TYPE = Damage ระห่วางธาตุ ดูได้จากตารางด้านล่าง (Stack ได้)
MovePower = Damage ของท่าที่จะโจมตี



จากสูตรจะเห็นว่าเรายังมีตัวแปรที่ขาดหายไปคือค่า IV ของ คู่ต่อสู้ของเรา ให้เรา "เดาไปเลยว่าเค้ามี IV เต็ม 15 ทั้ง ATK และ DEF"
ฉะนั้น เราจะสรุปข้อมูลได้ประมาณนี้
--- Trainer LV CP Base(ATK/DEF)+IV(ATK/DEF) CpM_ATK/CpM_DEF
[DEF]EeVee น้ำ 23 1967 [ATK=186+15] [DEF=168+15] 0.647576426
[ATK1]EeVee สายฟ้า 25 1338 [ATK=192+15] [DEF=174+13] 0.667934
[Atk2]Victreebel 25 1211 [ATK=222+13] [DEF=152+13] 0.667934

EeVee สายฟ้า โจมตี EeVee น้ำ
STAB = 1.25
TYPE = 1.25 (Electric vs Water)
MovePower = 5 (Thunder Shock)
EeVee น้ำ โจมตี EeVee สายฟ้า
STAB = 1.25
TYPE = 1 (Water vs Electric)
MovePower = 6 (Water Gun)
Damage = Floor(0.5 * (207 / 183) * (0.667934 / 0.647576426) * 1.25 * 1.25 * 5) + 1
Damage = Floor(0.5 * 1.1311 * 1.0314 * 1.25 * 1.25 * 5) + 1
Damage = Floor(4.5570)+1
Damage = 4+1
Damage = 5
Damage = Floor(0.5 * (201 / 187) * (0.667934 / 0.647576426) * 1.25 * 1 * 6) + 1
Damage = Floor(0.5 * 1.0748 * 1.0314 * 1.25 * 1 * 6) + 1
Damage = Floor(4.1570)+1
Damage = 4+1
Damage = 5

EeVee สายฟ้า โจมตี EeVee น้ำ
STAB = 1.25
TYPE = 1.25 (Electric vs Water)
MovePower = 100 (Thunder)
EeVee น้ำ โจมตี EeVee สายฟ้า
STAB = 1.25
TYPE = 1 (Water vs Electric)
MovePower = 90 (Hydro Pump)
Damage = Floor(0.5 * (207 / 183) * (0.667934 / 0.647576426) * 1.25 * 1.25 * 100) + 1
Damage = Floor(0.5 * 1.1311 * 1.0314 * 1.25 * 1.25 * 100) + 1
Damage = Floor(91.1419)+1
Damage = 91+1
Damage = 92
Damage = Floor(0.5 * (201 / 187) * (0.667934 / 0.647576426) * 1.25 * 1 * 90) + 1
Damage = Floor(0.5 * 1.0748 * 1.0314 * 1.25 * 1 * 90) + 1
Damage = Floor(62.355)+1
Damage = 62+1
Damage = 63

Victreebel พืช โจมตี EeVee น้ำ
STAB = 1.25
TYPE = 1.25 (Grass vs Water)
MovePower = 15 (Razor Leaf)
EeVee น้ำ โจมตี Victreebel พืช
STAB = 1.25
TYPE = 0.8x1 (Water vs Grass)x (Water vs Poison)
MovePower = 6 (Water Gun)
Damage = Floor(0.5 * (235 / 183) * (0.667934 / 0.647576426) * 1.25 * 1.25 * 15) + 1
Damage = Floor(0.5 * 1.2841 * 1.0314 * 1.25 * 1.25 * 15) + 1
Damage = Floor(15.5205)+1
Damage = 15+1
Damage = 16
Damage = Floor(0.5 * (201 / 123) * (0.667934 / 0.647576426) * 1.25 * 0.8 * 6) + 1
Damage = Floor(0.5 * 1.6341 * 1.0314 * 1.25 * 0.8 * 6) + 1
Damage = Floor(5.0562)+1
Damage = 5+1
Damage = 6

Victreebel พืช โจมตี EeVee น้ำ
STAB = 1.25
TYPE = 1.25 (Grass vs Water)
MovePower = 55 (Leaf Blade)
EeVee น้ำ โจมตี Victreebel พืช
STAB = 1.25
TYPE = 0.8x1 (Water vs Grass)x (Water vs Poison)
MovePower = 90 (Hydro Pump)
Damage = Floor(0.5 * (235 / 183) * (0.667934 / 0.647576426) * 1.25 * 1.25 * 55) + 1
Damage = Floor(0.5 * 1.2841 * 1.0314 * 1.25 * 1.25 * 55) + 1
Damage = Floor(56.9087)+1
Damage = 56+1
Damage = 57
Damage = Floor(0.5 * (201 / 123) * (0.667934 / 0.647576426) * 1.25 * 0.8 * 90) + 1
Damage = Floor(0.5 * 1.6341 * 1.0314 * 1.25 * 0.8 * 90) + 1
Damage = Floor(75.8434)+1
Damage = 75+1
Damage = 76

ข้อมูลพวกนี้ก็เอามาจากเว็บต่างประเทศอีกที ถ้าผิดพลาดตรงไหน ชี้แนะได้นะครับ

วันเสาร์ที่ 23 กรกฎาคม พ.ศ. 2559

docker swarm2k with Chanwit

Yesterday I just join in awesome activity it is "swarm2k"
this activity focus on try to create docker swarm more than 2000 node and try to run service on it (in this activity +Chanwit Kaewkasi try to run 100k app

Let start

This activity have github project at https://github.com/swarm2k/swarm2k and follow this instruction https://github.com/swarm2k/swarm2k/blob/master/INSTRUCTIONS.md

I start create my machine with docker-machine in my Vultr account



but before use docker-machine with Vultr you must install Vultr driver

After that I start to create my machine on Vultr with docker-machine command
but from instruction we must use docker dev version then we must use option --engine-install-url "https://experimental.docker.com/" for fix version of docker


Option --vultr-api-key= --vultr-os-id= --vultr-region-id= --vultr-plan-id= you can find with Vultr API
https://www.vultr.com/api/

Now time to join swarm cluster


I'm very lucky after I finish setup my node +Chanwit Kaewkasi just start to deploy service on Cluster



Few minute after deploy service every node on cluster start app at my node start 41 container/node
and then data collector for Grafana die

and response after run cluster checking take about 12 sec


Cluster can't reach 100k app it running at 94k and start to have failed it try hard to make 100k but it can't pass 97k


This activity very fun have many ppl join all around the world I'm very happy to be a part of awesome activity Next time I will join again