Tuan Anh

container nerd. k8s || GTFO

Build command line tools with Node.js

Everything you need to know about building command line tools with Node.js.

link bài gốc

Classic Programmer Paintings

Painters and Hackers: nothing in common whatsoever, but this are classical painters depictions of software engineering (techincally, might not be all classical but hey, this is just a tumblr)

The curators that created this Tumblr are genius. Here is one: “Frontend programmer” - a 16th century painting by Giovanni Battista Moroni.

Or this one: “Sysadmin grants sudo privileges to developer on production web server” - Andrea del Verrocchio and Leonardo da Vinci

link bài gốc

Google kick-starts engineering team in Singapore

Great news indeed! Now one can work at one of the most prestigious company in the world and stay close to his family. Singapore is only less than 2 hours away from Vietnam.

You can view all opening positions here

link bài gốc

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.