"Life is all about sharing. If we are good at something, pass it on." - Mary Berry

database/sql: never ignore errors

2019-10-16

I’m reading Building RESTful Web Services with Go. And in chapter 4, there is an example to play around with SQLite:

 1db, err := sql.Open("sqlite3", "./books.db")
 2if err != nil {
 3	log.Fatal(err)
 4}
 5
 6statement, err := db.Prepare("CREATE TABLE IF NOT EXISTS books (id INTERGER PRIMARY KEY, isbn INTEGER, author VARCHAR(64), name VARCHAR(64) NULL)")
 7if err != nil {
 8	log.Fatal(err)
 9} else {
10	log.Println("Created table books successfully")
11}
12statement.Exec()
13
14statement, err = db.Prepare("INSERT INTO books (name, author, isbn) VALUES (?, ?, ?)")
15if err != nil {
16	log.Fatal(err)
17}
18statement.Exec("Life is a joke", "The Javna brothers", 123456789)
19log.Println("Inserted first book into db")
20rows, err := db.Query("SELECT id, name, author FROM books")
21var tempBook Book
22for rows.Next() {
23	rows.Scan(&tempBook.id, &tempBook.name, &tempBook.author)
24	log.Printf("ID: %d, Book: %s, Author: %s\n", tempBook.id, tempBook.name, tempBook.author)
25}

Read More...


Lên xuống dòng đời

2019-10-14

Wien Hauptbahnhof Austria Wien Hauptbahnhof, Austria.

Vừa đáp chuyến tàu đêm từ Zurich sang. May mà lần này mỗi khi tàu dừng, điều hoà không tắt thì phải. Cuốc bộ tiếp 1,5 km nữa để về khách sạn. Hồn nhiên đưa mail booking cho nhân viên, đang định hỏi xem có cho check in sớm không.

Read More...


How do I build this blog?

2019-10-11

Raspberry Pi 4

Recently, I decided to find a new job as a Golang developer. So, I updated my resume, sent to my friends to ask for review. Then I submitted it enclosed herewith a cover letter to recruiters. Some didn’t reply, and the other replied with a message like this “You are so good, but I’m so sorry…”.

What is the reason?

As you can see in my resume, I started my career as a .NET developer, then my passionate on Linux and open source lead me to a different direction: system administrator. And I followed this nearly in 9 years before switching back to work as a Golang developer 2 years ago.

Read More...


Resume

2019-09-30

Quan Tong Anh
quantonganh@gmail.com
github.com/quantonganh

Experience


Software Engineer, CIC Data
Oct 2019 - Sep 2021

Read More...


Command-line autocomplete for Go documentation

2019-09-26

Go has a great, well documented standard library. You may find yourself spending a fairly significant chunk of your Go programming time digging in stdlib docs, which is reasonable to expect at least for novice Go coders.

https://eli.thegreenplace.net/2018/command-line-autocomplete-for-go-documentation/


Auto reload your Go webserver with Gulp

2019-09-20

When you developp a webserver with Go, you must compile each time you do an update in your code. Well.. this is redundant. With Gulp you can automatize this task… Indeed, when a go file is modified, a task compile the application in the “bin” folder (“gopath/bin”) then another launch the executable (the webserver).

https://medium.com/@etiennerouzeaud/autoreload-your-go-webserver-with-gulp-ee5e231d133d

 1const gulp     = require('gulp'),
 2      util     = require('gulp-util'),
 3      notifier = require('node-notifier'),
 4      child    = require('child_process'),
 5      os       = require('os'),
 6      path     = require('path');
 7
 8var server = 'null'
 9
10function build() {
11    var build = child.spawn('go', ['install']);
12
13    build.stdout.on('data', (data) => {
14        console.log(`stdout: ${data}`);
15    });
16
17    build.stderr.on('data', (data) => {
18        console.error(`stderr: ${data}`);
19    });
20
21    return build;
22}
23
24function spawn(done) {
25    if (server && server != 'null') {
26        server.kill();
27    }
28
29    var path_folder = process.cwd().split(path.sep)
30    var length = path_folder.length
31    var app = path_folder[length - parseInt(1)];
32
33    if (os.platform() == 'win32') {
34        server = child.spawn(app + '.exe')
35    } else {
36        server = child.spawn(app)
37    }
38
39    server.stdout.on('data', (data) => {
40        console.log(`stdout: ${data}`);
41    });
42
43    server.stderr.on('data', (data) => {
44        console.log(`stderr: ${data}`);
45    });
46
47    done();
48}
49
50const serve = gulp.series(build, spawn)
51function watch(done) {
52    gulp.watch(['*.go', '**/*.go'], serve);
53    done();
54}
55
56exports.serve = serve
57exports.watch = watch
58exports.default = gulp.parallel(serve, watch)

Read More...


About

2019-09-19

Hello. I’m Quan. I started my career as a .NET developer. Then my passionate on Linux and open source led me to a different direction, a system administrator. With a strong background in Linux system administration, I was gradually moving to backend. I’m currently working as a software engineer. In spare time, I teach my wife to program to automate her office tasks.

I enjoy working in the fields that can make a different in people’s lives or allow me to help others.

Read More...


Lavender

2019-06-17

Lavender in Provence Lavender in Provence, France.

Marseille -> Provence: 150km

Xe lạ. Lái không mới nhưng sợ đi số sàn, nhất là đề-pa. Có lần dừng đèn đỏ, cứ “côn ra ga vào” là chết máy, đằng sau bóp còi inh ỏi, người toát mồ hôi. Bình tĩnh nhìn lại thì hóa ra… chưa hạ phanh tay.


Đến những nơi bạn chưa từng đến.
Làm những điều bạn chưa từng làm.
Để có được những trải nghiệm bạn chưa từng có.

Read More...


France

2019-06-15

Eiffel tower Eiffel tower, Paris, France.

Champs-Elysees Boulevard Champs-Elysees boulevard, Paris, France.

X


Hà Nội

2019-02-01

K9 Bách khoa K9 Bach khoa, Hanoi.

Long Bien bridge Long Bien bridge, Hanoi.

Fishing on the West lake West lake, Hanoi.

L’etage cafe L’etage cafe, Hanoi.

Đêm nằm mơ thấy đi tu
Sáng ra tỉnh dậy mùa thu đã về

Ô Quan Chưởng Quan Chuong gate, Hanoi.