Tuan Anh

container nerd. k8s || GTFO

Install io.js on Mac OS X

I believe iojs is not going to be a flop. Look at the current development rate, I would say iojs would replace nodejs eventually if Joyent not doing anything to turn it around.

I prefer to install iojs with nvm instead of the default installer package on iojs’s homepage since it allows me to switch between node version with a single command.

As of current, iojs is basically a dropin replacement for nodejs so you don’t have to worry much.

Install iojs

Install nvm - a node version manager with homebrew

curl https://raw.githubusercontent.com/creationix/nvm/v0.23.2/install.sh | bash

Install iojs with nvm

nvm install iojs

Add these lines to your .zshrc or .bashrc

export NVM_DIR=~/.nvm
source $(brew --prefix nvm)/nvm.sh%

Set iosjs as the default node version

nvm alias default iojs

You can check again with which node to see which version of node is using.

Things software developers wish they had known in their 20s

  1. The era in which a common career trajectory is to become a lifer at some software company and work one’s way up to higher and higher internal positions has been over for a long time (This era had already been over in the 1990s when I was a young programmer).

  2. You don’t owe the company you work for anything beyond what you put your name on when you signed the employee agreement.

  3. Don’t stick around too long if the place you are working for isn’t doing much for your bottom line, is not your dream job, and isn’t adding anything new to your resume; that is, the easiest way to get a promotion and a substantial raise is to switch jobs. Don’t switch jobs if you like what you are doing but also don’t stay somewhere only out of loyalty to a company.

  4. If you think 2. and 3. are cynical and if looking at things this way makes you feel like an asshole, console yourself with the knowledge that the company you work for views you in exactly the same way and will act on such a view in a second if it is in its interest to do so.

  5. You can usually skip all hands meetings even if they are supposedly mandatory.

  6. Keep an eye on corporate politics. Being a successful computer programmer is about social engineering as much as it is about software engineering.

  7. Make sure you are at the meetings at which the scope and/or requirements are defined for any piece of software for which you are going to be responsible.

  8. Don’t go dark. Check in code often – with stubs or whatever if necessary. It is better to check in code sooner rather than later despite the fact that doing so might entail dealing with transitory problems. A few hiccups now are better than a gigantic merge conflict down the line.

  9. Be careful about your estimates on dates and on how long things are going to take. Understand that the whole game is about dates. When in doubt just triple what you actually think even if it secretly sounds absurd to you.

  10. Don’t be religious about languages, libraries, or platforms.

  11. Except for Perl. Perl sucks.

  12. At a certain point it is you the programmer who will decide when things are done, even if it isn’t officially supposed to be your decision. Ultimately there is a point before releases when you have to push back at PM or whoever and say, “What you are asking for is not a bug fix – it is a feature request. We are way beyond the point at which we can even be considering introducing new features” It will always be you the programmer who does this because no one else will.

  13. Don’t check in a lot of code right before a vacation or long weekend.

  14. It is easier to not get assigned to something that you don’t want to work on than it is to get out of it after it has been assigned to you. Trust your instincts regarding death marches. If some project doesn’t feel right, don’t get assigned to it.

  15. If you find yourself working for a place at which there is a manager who is printing out burn-down charts and hanging them on the wall, start looking for another job.

  16. Working for big companies/name software companies can suck more than you can possibly imagine. Just because your friend who works for Company X is always bragging about the rock climbing wall doesn’t mean that Company X is a great place to work.

  17. For all but the simplest cases, prefer recursive descent parsers over regular expressions.

  18. Get good at debugging and learn to use a profiler.

  19. Focus on making your way into a position in which you are doing what you like software-wise while you are young and can more easily take risks.

  20. Don’t break the build. If you do break the build, don’t make a lot of excuses – no one cares – just fix it quickly.

Source: Quora.

In order to get link without Quora censoring stuff, just add any ?abc= in the url. My personal favorite is ?fuck=you, in the hope that it will be popular enough to show in their log someday :D

How the Other Half Works: an Adventure in the Low Status of Software Engineers

Bill had been a Wall Street quant and had “Vice President” in his title, noting that VP is a mid-level and often not managerial position in an investment bank. His current title was Staff Software Engineer, which was roughly Director-equivalent. He’d taught a couple of courses and mentored a few interns, but he’d never been an official manager. So he came to me for advice on how to appear more “managerial” for the VP-level application.

A fascinating read by Michael O. Church. Lots of advices on software development careers.

Great blog. Subscribed!

link bài gốc

How movies could change your perception

It’s interesting how much movies can change our perception: survey asking people in France who contributed the most to the defeat of Nazi Germany.

sondage nation contribue defaite nazis

link bài gốc

Fix WELD-001408 unsatisfied dependencies for type error when deploying to GlassFish

Took me half an hour today to figure this out when deploying to production servers. Apparently, the CDI extension loaded from a JAR in a WAR, thus different classloader, makes it uninjectable.

The problem can be fixed by simply disable implicit CDI on GlassFish

${GLASSFISH_HOME}/bin/asadmin set configs.config.server-config.cdi-service.enable-implicit-cdi=false

REST APIs made easy with StrongLoop

StrongLoop allows you to quickly create REST APIs using their graphic interface and CLI. SLC also supports debugging, profiling, tracing, deploying as well as monitoring features.

Creating REST APIs with slc is as easy as creating datasource and model. StrongLoop will do the rest for you.

I was very tempted to use StrongLoop for a recent project but I had to deal with a legacy database that use a very old odbc driver which force me to use node.js and express.

link bài gốc

Microsoft HoloLens

microsoft hololens

Microsoft is really on a roll lately. They are on the right track to regain their cool factor among devs. The device looks truly impressive and based on what we know so far, it looks a lot better than Google Glass and Oculus Rift.

When you change the way you see the world, you can change the world you see.

It’s interesting that Microsoft calls this holographic technology instead of augumented reality. Though it’s not technically correct, they’ve got themselves a better brand to distinguish their product.

There are zillions use case for this kind of technology: healthcare, entertainment, education; you name it. Just to name a few that pop up in my head real quick.

  • expert coaching

  • training

  • modelling

  • gaming

  • millitary applications

  • etc …

Not to mention, whenever a technology like this is introduce, people will find a way to use this in adult entertainment.

Let’s just hope that Microsoft will not overpromise like Google did and let it ended up where Google Glass is now.

link bài gốc

Create a contact form with jekyll

Since jekyll blog is static, we have to rely some some kind of service endpoint to send email to our mailbox. Good thing is that there are plenty of services for this purpose: heroku for free hosting and mailgun, mandrill or mailjet for sending email. Pick one of your choice.

I did a quick search before firing up Sublime Text to create a simple app for sending email and luckily, someone already wrote one. One less thing to do :)

Create Heroku and a Mandrill account

Sign up an account at Heroku. Download and install heroku toolbelt while you’re at it.

For sending email, you can go with Mandrill, Mailgun or Mailjet. They all come with free plan which is more than enough for personal use. If you pick something other than Mandrill, you will have to edit the app a bit use their own libraries. If you’re lazy, just go with Mandrill.

Install the app on heroku

heroku auth:login # enter your account credentials when asked

git clone https://github.com/ousenko/simple-contact-form.git
heroku create <YOUR_HEROKU_APP>
heroku config:set MANDRILL_API_KEY=<KEY>
heroku config:set USER_EMAIL=<YOUR EMAIL>
heroku config:set USER_SITE=<YOUR SITE>

git push heroku master # deploy

Create contact form on your website

Create a page with simple form like below. I’m using Bootstrap for my blog so styling is just a matter of adding a couple of CSS classes.

<form action="https://<YOUR_HEROKU_APP>.herokuapp.com/send">
  Email: <input type="text" name="name"><br>
  Name: <input type="text" name="email"><br>
  Subject: <input type="text" name="subject"><br>
  Message: <textarea name="message" cols="40" rows="5"></textarea>
  <input type="submit" value="Send Message">

Adding reCAPTCHA (optional)

Sign up for an API key pair and add it to your page. I don’t have a need for this, personally.

Here what’s mine like

contact form with jekyll

Fuck callbacks! Let's use generators

Let’s write a simple function hello that return a string when called.

var hello = function () { return 'Hello ' + name; }

Now convert it into a generator. Call hello() this time will return you an Object instead: the generator.

var hello = function *() { return 'Hello ' + name; }

Let’s consider the following snippet.

var hello = function *() {
  yield 'Stopped here!';
  return 'Hello ' + name;

var generator = hello('Clark Kent');
console.log(generator.next()); // {value: 'Stopped here', done: false}
console.log(generator.next()); // {value: 'Hello Clark Kent', done: true}

So what good can generators do for me? Generators can help eliminiating callbacks. Using callback for 1 or maybe 2 levels is fine. However, imagine if you have to use callbacks for 3 levels or more like the example below. URGH!!

func_1(arg, function(err, result) {
  if (err) { .... }
  else {
    func_2(result, function(err, result2) {
      if (err) { ... }
      else {
        func_3(result2, function(err, result3) {
          if (err) { ... }
          else {
            // LOST IN LIMBO !!!

Take an example: consider a scenario where you have to establish connection to a bunch of database servers at application startup. With generators, you can do something like this:

var init_all_connections = function *() {
  var result;
  result = yield init_connection(conn_str1);
  result = yield init_connection(conn_str2);
  result = yield init_connection(conn_str3);
  // ...


For the sake of conveniency, you can write a function to execute the generator until done is true, throw if an error occurs. So the whole thing looks as simple as this:

var init_all_connections = function *() {
  var result;
  result = yield init_connection(conn_str1);
  result = yield init_connection(conn_str2);
  result = yield init_connection(conn_str3);
  // ...

// execute

Look how the code is cleanly organized and so much readable compare with the callback hell above. Ain’t you glad you read this now ;)

IO performance benchmark on RamNode

Last update: 2015-01-18

I read a IO performance benchmark today comparing AWS vs DigitalOcean. It makes me curious about the IO performance on RamNode. Of course I wouldn’t expect something high since I’m running in one of the lowest tier offerred by them (It’s not even 100% SSD but just some kind of hybrid SSD-Cached). I will also ignore read test since all the VPS are container-based and read is probably heavily-cached anyway. As for the tool, I’m using fio for my IO benchmark.

Installing fio

sudo apt-get install fio
mkdir data # at ~ I suppose
nano testconfig.fio
# content of the file

numjobs=10 # check size and your free space left (df -h)


Result when blocksize=8k

Run status group 0 (all jobs):
   READ: io=2048.0MB, aggrb=6485KB/s, minb=6485KB/s, maxb=6485KB/s, mint=323357msec, maxt=323357msec

Result when blocksize=16k, bw peaks at 21249.

Run status group 0 (all jobs):
   READ: io=1024.0MB, aggrb=8154KB/s, minb=8154KB/s, maxb=8154KB/s, mint=128592msec, maxt=128592msec

Result interpretation

One thing to notice is the CPU load skyrocketted. Though I only went with numjobs=2 and size=1g, the CPU load hits 3.x (300%). This is expected behavior since I’m on their Massive VPS plan. Due to this CPU issue, this is probably not the highest write speed possible as well. I would have to try it on a higher plan where CPU is irrelevant to the test. Too bad, RamNode doesn’t allow me to quickly launch an instance to test and destroy after.

So overall, DigitalOcean > AWS > RamNode. RamNode is left behind by far margin, probably due to the CPU on their lowest plan. If your application is IO-heavy, you should probably look else where.