Tuan Anh

container nerd. k8s || GTFO

Why JSON doesn't support comments

“I removed comments from JSON because I saw people were using them to hold parsing directives, a practice which would have destroyed interoperability. I know that the lack of comments makes some people sad, but it shouldn’t. Suppose you are using JSON to keep configuration files, which you would like to annotate. Go ahead and insert all the comments you like. Then pipe it through JSMin before handing it to your JSON parser.” - Douglas Crockford

link bài gốc

Implement autocomplete with redis

Very nice implementation of doing autocomplete with redis. From antirez - redis author himself.

I tried it in Node.js and it works very well for this purpose, over 10x improvement over traditional SQL LIKE.

redis autocomplete

link bài gốc

Concurrency and parallelism

My interest shifted to Go lang these days. However, I didn’t want to jump right into coding but reading about its design first.

For example, this slide here is pretty fascinating on how golang deals with concurrency and parallelism, a concept I believe many people often make mistake and confuse between them.

link bài gốc

Welcome the second Pom to my family

47 days old. She’s the latest furry cute little addition to my family.

We haven’t named her yet though.


Setting up SSL certificate with Deis

Now that Let’s Encrypt offers free SSL, there is no reason not to use it to secure your apps. Setting up Deis to use SSL is easy too.

I haven’t yet figured it out how to renew the cert automatically. Last I checked, they (Deis) doesn’t support this yet. They may be integrated into deis-router in near future.


Search airport by city name

I recently came across a case where I have an airport list (my data), city list (input data) and I have to map them.

The thing is not all the airport and city have similar name. They can be very different like Vieux Fort city and Hewanorra International Airport (UVF). I need to come up with a small service that take city name as input and output their possible nearby airports.

What I did was

  • I use Google Maps Reverse Geocoding API to find the city’s longitude and latitude and cache it. Since Google Maps has a limit of 10 requests per second and 2,500 request daily. Without caching it, my app would crash within seconds. I used redis here.

  • Since this is one time thing, I will try to use the free tier of Google Maps API if possible without having to pay. I might take a look at using proxy for removing that free tier cap.

  • I will have to find distance between that input city and all the airports. Doing this would be super slow so you would want to consider all the city in that country only.

Few things to note here:

  • redis is awesome cache solution. Since I already use redis for caching, and it can do geo proximity calculation, I wonder why not.

  • Google Maps API is not very reliable. Occasionally, you will see many dumb data which played havoc to my service. Hence I’m only using this as last resort if I can’t map using other method.


How to install Discourse without Docker

I purchased a dead cheap VPS for 5$ a month which come with 2GB of memory, 80GB disk space and quite decent CPU. The downside is they uses a very old kernel (2.6.32-042stab108.8 to be specific) while the official Discourse installation guide use Docker which require a more recent one (3.x).

Docker sure makes it easy to install Discourse but it’s the only reason that newer kernel is required. After a quick research, I found this Ansible playbook. It looks well-maintained (last commit was Dec 2015).

It doesn’t work right out of the box for me but after some debugging, I was able to install Discourse just fine. There are few things to note though.

  • On default Ubuntu installation, Apache will use port 80, making nginx fails to start. You will have to stop/uninstall Apache2 in advance (sudo apt-get remove apache2)

  • On some VPS providers, IPv6 is not enabled so you will also need to tweak nginx configuration to bind to IPv4 only.

  • If locale is not set, the script will fail as well. This command localedef -v -c -i en_US -f UTF-8 en_US.UTF-8 fixes it.

Installing plugins

discourse is the default username if you use the above playbook. Replace it if needed.

cd /var/www/discouse/plugins
# git clone the plugin you want to install
sudo /home/discourse/.rbenv/shims/bundle exec rake db:migrate /var/www/discourse RAILS_ENV=production
sudo /home/discourse/.rbenv/shims/bundle exec rake assets:precompile /var/www/discourse RAILS_ENV=production
sudo systemctl reload discourse-unicorn.service

Bonus: btw, Let’s Encrypt offers free SSL. Setting it up is really easy too.


A look back at 2015

I kicked off 2015 with lots of anxiety. I reconnect with my best friend from secondary school (then; wife now). For the first time in years, I really wanted to move back to Vietnam.

Early in 2015, I went back to Thailand after Tet holiday, start looking around for a job in Vietnam or any job that accept remote workers to smooth the transition. I found one later in May-June. They only require me to work in Thailand for awhile (1 month) so that I can get accustom with how they work there.

me and my wife

Got married to a beautiful girl who also happens to be my best friend from secondary school.

me and my wife

Bought a beautiful Pomeranian. Named her Min.

my dog

My family and me during Tet 2016.

Grow a little garden on the balcony

2015 had been good to me and perhaps my most important year of my life. I’m looking forward to 2016 with many goals in mind. The difference is now I got my wife to back me up 👫.


MariaDB Raises $9M More, Michael Howard Named New CEO, Monty Widenius CTO

Michael “Monty” Widenius, the man who originally created MySQL and MariaDB, is now joining the startup as CTO.

This is better than the funding round news.

link bài gốc

Chuyện tiền nong

ngồi lẩm nhẩm: mình đi làm mấy năm, nhìn lại thấy tài chính rối tung, tài sản thì chả có gì; cơ hội thì bỏ qua 1 đống.

thôi thì bây giờ học cũng chưa quá muộn.

tránh mang nợ

nói chung có thì xài, không có thì đừng có vay nợ để xài. xài thẻ debit cũng có nhiều cái hay lắm. hết tiền rồi mà muốn mua món gì đó thì phải ra ngân hàng deposit hoặc chuyển khoản từ ngân hàng khác sang. rất mất thời gian. cái này là vật cản lớn lắm nha.

nhiều lúc mình tính mua món gì mà ngại chuyển tiền. tính ngủ 1 giấc rồi đi mua thì lại chẳng còn hứng mua xài tiền nữa. nếu mà như vậy thì thực sự bạn không cần món đó, chỉ là muốn thôi.

lỡ mang nợ rồi!?

bây giờ lỡ mang nợ rồi thì sao? có 2 cách trả nợ:

  1. trả cái nào lãi suất cao nhất trước. cách này là economical nhất vì số tiền phải trả cuối cùng là nhỏ nhất.

  2. trả cái nào nhỏ nhất. cái này là dựa về mặt tâm lý. dứt được 1 món nợ sẽ thoải mái tinh thần hơn nhiều và tạo thêm động lực. 1 dạng reward cá nhân.

kiếm đâu ra tiền để trả nợ?

cái này cũng có 2 cách:

  1. cày nhiều hơn.

  2. xài ít hơn.

dù có chọn cách nào thì cũng phải xài tiền khôn hơn 1 chút. xài ngu thì kiếm bao nhiêu cũng không đủ. lương tháng nào xài tháng đó hoặc còn xài lố (credit card) nữa thì thua.

làm giàu

cách đơn giản và an toàn nhất là bỏ vào 1 cuốn sổ tiết kiệm. giả dụ mỗi ngày bạn bỏ ra 100 nghìn, 10 năm sau bạn có 100k * 365 * 10 = 365 triệu. 30 năm sau là thành tỉ phú rồi.

một cách khác nữa là đầu tư vào cái gì đó. cái này mình cực ngu. một là do không có vốn (vì lỡ xài ngu như ở trên rồi), hai là không nhìn thấy cơ hội.

cách khác nữa là đầu tư vào bản thân. mua sách học, đăng kí các khóa học thêm, etc..


hehe nói vầy thui chứ mình không phải chuyên gia tài chính gì đâu, các bạn đừng có tin.

nếu làm được mấy cái này mình đã giàu rồi, ko phải ngồi đây viết lảm nhảm như vầy đâu haha.