Tuan Anh

container nerd. k8s || GTFO

How to import csv file in MySQL

If your MySQL server started with --secure-file-priv option, you will have to move your csv file to that specific folder first.

To check where that folder is, first run SHOW VARIABLES LIKE "secure_file_priv";

Move your csv file to that folder and issue the following command in MySQL console. Remember to replace /var/lib/mysql-files/ with your secure_file_priv path variable.

LOAD DATA INFILE "/var/lib/mysql-files/data.csv" \
INTO TABLE my_table \
COLUMNS TERMINATED BY ',' \
OPTIONALLY ENCLOSED BY '"' \
ESCAPED BY '"' \
LINES TERMINATED BY '\n' \
IGNORE 1 LINES;

Do’s and Don’ts of AWS Lambda

TJ Holowaychuk writes about Do and Don’ts of AWS Lambda.

link bài gốc

No More Vietnam

Nixon’s retrospective on Vietnam war, 10 years later.

link bài gốc

Mildly interesting npm modules

Not in any particular order

thenBy is a javascript micro library that helps sorting arrays on multiple keys

You use Node.js for speed? You process XML streams? Then you want the fastest XML parser: libexpat!

Lightweight fuzzy-search, in JavaScript, with zero dependencies

js ex machina - finite state machines in JavaScript http://machina-js.org/


AWS Lambda

So a few months back, when I read of AWS lambda, I instantly fell in love with it though not having any immediate use with it.

AWS lambda is perfect for those wish to build microservices. There are many benefits of doing this such as independent deployment, security and scability. But I’m not going to talk about this within this post. This post is merely my experience with AWS Lambda.

Enter AWS Lambda: great product, works like magic and requires no dev ops which is a huge plus at where I work. However, there are a few cons:

Testing locally

There is no easy way to do this locally. Looks like there isn’t many alternative out there except maybe lambda-local

Building native packages

I’ve yet to come across a service that build native node.js package for AWS lambda deployment. For now, I have to spin up a EC2 instance, install nodejs and gcc just to build a package, zip it and download it to my local machine in order to prepare for deployment.

Error handling

This isn’t a problem with AWS lambda particular but more like with microservice. However, AWS lambda doesn’t introduce any solution to deal with this either.


As much as I like to use aws lambda in production, i haven’t yet to see any use cases for that at work to put all these in real world test. I’m sure the future of “function as a serivce” is much more and I would love to go into greater details about it in future posts if I have a chance to put it to production. For now though.. Phew


Flynn 1.0

Flynn 1.0 released. Another thing to consider aside with Deis.

I’ve tried this before but it was far from production-ready back then. Hopefully that has changed.

link bài gốc

Open-source PaaS on AWS

Something to consider along side with deis. To be honest, deis offers more choice of deployment ranging from AWS, DigitalOcean, etc.. to bare metal. The choice is complete yours. Also, you don’t get vendor lockdown to AWS.

link bài gốc

Work hard and go home

I don’t get ping pong table or hanging out during workday. Believe it or not, many of us have family and prefer to spend time with them after work.

T-shirt, ping pong table, or free lunch, etc…, I am way pass that.

link bài gốc

Refined Twitter

An extension that makes Chrome always use the mobile web version of Twitter, which is much faster and better looking than the old desktop web version. When you open a link that would normally be to desktop Twitter, this extension redirects you to the mobile web version and makes it wider.

Good thing about this is when clicking back button in browser, mobile Twitter get you back to where you were, unlike the desktop version.

They also offer a desktop version - Anatine.

link bài gốc

Geo dynamic upstream with nginx

I recently had to setup nginx as load balancer at work. Due to the reason that one of our customer is in China, we have to add few China servers to our load balancer and route everything from China to those instead.

Turn out it’s quite easy to do it with nginx and geo package. You will need nginx-full or compile nginx yourself with geo package.

After setting nginx with geoip. Create a new configuration in site-available, symlink to site-enabled to enable it.

The content of the fie should look like this

upstream first_upstream  {
    ip_hash; # for sticky session
    server <first-01>;
    server <first-02>;
}

upstream second_upstream {
    ip_hash;
    server <second-01>;
    server <second-02>;
}

map $geoip_country_code $preferred_upstream {
    default first_upstream;
    CN second_upstream; # use second_upstream for those from China (CN)
}

server {
    ...
    location / {
        proxy_pass http://$preferred_upstream/;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
    ...
}