Tuan Anh

container nerd. k8s || GTFO

Metalsmith - a static site generator written in Node.js

An extremely simple, pluggable static site generator.

Metalsmith works in three simple steps:

  • Read all the files in a source directory.

  • Invoke a series of plugins that manipulate the files.

  • Write the results to a destination directory!

Very simple yet powerful. Metalsmith is like gulp but made for static website/content.

link bài gốc


Drag a window up to the menubar to maximize it, or drag a window to the side to resize it to the corresponding screen half.


link bài gốc

Possibly the easiest way to setup rtorrent/rutorrent

Installation script which is cumbersome, not very easy to use and sometimes goes unmaintained but you don’t know about that yet and ended messing up your VPS file system.

In this post, I will show you how to setup rtorrent/rutorrent with Docker. It’s rather easy and requires minimal knowledge about Linux in general.

Grab a KVM VPS from RamNode

I’m going with RamNode here but you can use any VPS provider you want. Be sure to select KVM because Docker is going to require a rather new kernel so OpenVZ won’t work. I select Ubuntu 14.04 in this tutorial. To make it easy to follow, you can do the same.

After finishing the payment, you will get an email containing your VPS information. You can perform some simple initial server setup to secure your VPS after this.

Install Docker

sudo apt-key adv --keyserver hkp://pgp.mit.edu:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D

sudo touch /etc/apt/sources.list.d/docker.list

sudo echo "deb https://apt.dockerproject.org/repo ubuntu-trusty main" > /etc/apt/sources.list.d/docker.list

sudo apt-get update

sudo apt-get install docker-engine

mkdir ~/rtorrent # folder for rtorrent docker

sudo usermod -aG docker <your-username> # use docker without sudo, if your user is in sudo group

Setup rtorrent/rutorrent

You will need to secure your rutorrent installation so that noone else except you can access it.

cd ~/rtorrent
printf "<username>:$(openssl passwd -apr1 "<your-passsword>")\n" > .htpasswd

Now we are going to use the Dockerfile made by diameter to simplify the whole process of setting up rtorrent/rutorrent/nginx. If you want to see the source code, you can check it out here on Docker Hub.

docker run -dt --name rtorrent-rutorrent -p 8080:80 -p 49160:49160/udp -p 49161:49161 -v ~/rtorrent:/downloads diameter/rtorrent-rutorrent:64

Let docker pull and build for awhile (1,2 mins at most) and you can navigate to http://<your-server-ip-address>:8080 to start using rutorrent.

rutorrent docker

Stuff you may not know about console


var Person = function(name, age) {
    this.name = name
    this.age = age

var person_list = [
    new Person('wayne', 10),
    new Person('cristiano', 20),
    new Person('david', 30),
    new Person('bastian', 40)

console.table(person_list, ['name', 'age']) // filtering columns

You’ll get a nice table like this



console.time('Operation A')
var arr = []
for (var i =0; i < 100000; ++i) {
console.timeEnd('Operation A')

> Operation A: 395.557ms


for (var i = 0; i < 100000; ++i) {
    console.assert(i % 1000, 'Iteration #%d', i)

This will only print when first arg (i % 1000) is false.


Group so that you can collapse/expand messages within a group.

console.group('Group A')
console.log('First line')
console.log('Second line')
console.log('Third line')

Node.js happy coding

I’ve been doing Node.js professionally for roughly 2 years. During that time, I’ve learnt a thing or two that keeps me away from troubles.

Use Promise instead of callback

ES6 gets native Promise already but if you prefer something more convenient that 3rd-party libraries offer, pick something like bluebird (it’s really really fast). Stay away from Q. I mean, just look at this.

Do not trust developer’s semver practice

use npm shrinkwrap instead

This command locks down the versions of a package's dependencies so that you can control exactly which versions of each dependency will be used when your package is installed.

Personally, i would prefer npm support something like --save-exact flag. That would be awesome.

Choosing the right dependency

You already have enough bug fixing jobs on your plate. Don’t import more from others’. There are several things that go into consideration when i need to install an extra package:

  • statistic on npm/github: popular is good

  • check if the project is active: last commit, etc..

  • check if the issues get resolved timely.

  • check unit testing is well covered?

  • check its dependencies: cover all things above. Personally, I wouldn’t want to use anything that depends on Q. It shows the author didn’t do the homework quite well, or at the very least, didn’t keep the package up to date with current situation in Node.js eco.

Use linter

Respect the code convention. The ultimate goal is having code written by different developers, looks as if they were written by the same person.

ES6 in Node.js

Get yourself ES6-ready in Node.js: arrow functions, map, generators, etc..

link bài gốc

Go Native - Calling C++ From NodeJS

I don’t usually have the need to do this but it would be fun practice to build a npm module by packaging some C++ libraries.

link bài gốc

Atom is slow but that's okay

I started using Atom from one of those early beta build. I wasn’t impressed. At that time, it was really slow (still is), taking several seconds just to load the app, freeze frequently when I tried to open log file (few MBs) and a bunch of other small bugs here and there. So I went back to Sublime and just keep an eye on Atom once in awhile (I left it in /Applications untouched)

Recently, a colleague of mine was trying to convince me to try Atom again. So I fire up terminal, rm -rf ~/.atom and update the app.

You should remove old Atom config since Atom is very actively developed and may have changed a lot since last you tried the app.

Atom feels much more polished this time. Despite the slow startup time still there, I feel very compelled to stick with Atom this time. I understand that Atom probably never going to achieve Sublime’s speed (due to its nature) but that’s ok. Here’s why:

Atom’s UI is closely resemble Sublime

The interface and everything is closely resemble Sublime so the learning curve is rather shallow. In fact, few people wouldn’t know they are looking at Atom or Sublime without glancing at the menubar.

Atom has done so many right things out of the box

Atom has done so many right things right out of the box. Stuff like keyboard shortcuts feel a lot more intuitive than Sublime.

I know, i know that we can re-map Sublime shortcuts as well. I did exactly that at first but working right out of the box still feels a lot nicer.

The older I get, the lazier I become when it comes to tinkering with settings to get it right. I remember my 18-yo self would plays with all kind of registry keys on Windows XP for the fun of it. I’m not like that anymore. I just want to forget about the editor and start coding.

Atom is very extensible

Most of the packages I used in Sublime is available on Atom as well; or at the very least, the equivalent exists.

I pretty much use vanilla Atom (default theme, default colorscheme) with a few packages installed: atom-alignment, atom-fuzzy-grep, auto-detect-indentation and highlight-selected. I highly recommend you to checkout atom-fuzzy-grep package. It allows you to use the_silver_searcher for fuzzy search your project. It’s freaking awesome and fast. Check it out.

Atom is actively developed by GitHub and community

It’s not that Sublime is abandoned but Atom development is much more active. It’s backed by GitHub and a huge open-source community vs few developers of Sublime. You know, the bus factors thing.

If you haven’t checked Atom in while (or at all), you should probably do. That’s my advice, coming from a hardcore Sublime fan.

Efficient branching workflow with git flow

Why aren’t you using git flow provides a nice overview on why you and your team should adapt using git flow in your workflow.

Keep this cheatsheet somewhere in case you need a quick reference.

link bài gốc

Hello, HotelQuickly!

hello HotelQuickly

I’m very excited to let you know that I’m joining HotelQuickly as Node.js developer, working on their next generation API. I’m totally psyched about this as I have a chance to work with great people, dealing with mind-boggling challenges.

This is going to be fun.

Meanwhile, you can download HotelQuickly now for iPhone, Android or BlackBerry 10; get 500 THB credit by redeeming voucher code TANHB9.