Git End-of-Line Normalization by AutoCRLF with Input

Using Vagrant file provision in a Windows host, the line endings are not converted from CRLF to LF (Linux systems). So, code cannot be executed properly in the guest Linux system. And also this is a frequently occurred message for working with Windows:

1
2
warning: LF will be replaced by CRLF in README.md.
The file will have its original line endings in your working directory.

One solution is to use UNIX line ending (LF) even in Windows, hence no conversion is needed. This is done by setting:

1
$ git config --global core.autocrlf input

Which means when committing the code to a remote repository, the line ending will be convert from CRLF to LF if any, but when checking out from the remote directory, no conversion from LF to CRLF is performed.

Install Docker and then Run Docker Commands without Sudo

Commands:

1
2
3
4
$ curl -sSL https://get.docker.io/ubuntu/ | sudo sh
$ sudo usermod -a -G docker $USER
$ sudo service docker restart
$ logout

Explanation:

  1. One line command installation
  2. Add the user to the group docker
  3. Restart the daemon
  4. Make sure to logout and log back in, in order to sudoless Docker taking effect.

How to Correctly Use Environment Variables on the Command Line

I always forget about how to use shell environment variable correctly. I think because I did not grasp the key concept. For example, here is the wrong approach:

1
2
$ FOO=foo BAR=bar echo foo is ${FOO} and bar is ${BAR}
foo is and bar is

The correct answer I was hoping for is:

1
foo is foo and bar is bar

Because what I frequently do is use environment variable inside shell script:

1
2
3
4
5
#!/usr/bin/env bash
#
# script.sh
echo foo is ${FOO} and bar is ${BAR}

then do:

1
2
$ FOO=foo BAR=bar ./script.sh
foo is foo and bar is bar

This works as expected because the environment variables are passed into the subshell that executing the script.

But why not the first or the wrong approach?

The reason is that shell expands the variable before the command being executed. To shell, the first approach looks like:

1
$ FOO=foo BAR=bar echo foo is and bar is

The environment variables FOO and BAR were expanded before the command was executed. Hence, no values were printed.

Launch Byobu Automatically on Vagrant SSH

I can use SSH directly instead of Vagrant SSH command for interactive programs such as top or running tmux sessions. But I frequently just want to run Tmux or Byobu upon login. I can do:

1
$ ssh -F ssh-config vagrant -t byobu

But still too much trouble to go through all SSH configuration steps. So, I ended up with two-step process:

1
$ vagrant ssh

Now inside the guest machine, I immediately type:

1
$ byobu

To bring up new Tmux session or attach existing sessions.

Docker Save, Load and Deploy

Need to deploy private Docker containers without a private registry? Try docker save and docker load.

Working set:

1
2
3
4
5
$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
realguess/jq latest 1f3f837970bf 3 months ago 6.107 MB
realguess/jq 1.4 6071e18eae76 3 months ago 6.107 MB
busybox ubuntu-14.04 f6169d24347d 6 weeks ago 5.609 MB

Actions to perform:

  1. Save an image with a single tag
  2. Save an image with multiple tags
  3. Save multiple images

Save a single tagged image:

1
$ docker save realguess/jq:latest > realguess-jq-latest.tar

Save a single image with all tags:

1
$ docker save realguess/jq > realguess-jq.tar

The tagged one is slightly less in size:

1
2
3
$ ls -lh realguess*.tar
-rw-rw-r-- 1 chao chao 6.0M Feb 1 12:00 realguess-jq-latest.tar
-rw-rw-r-- 1 chao chao 6.5M Feb 1 12:00 realguess-jq.tar

Save multiple images:

1
$ docker save busybox realguess/jq > busy-realguess-jq-box.tar

The size is almost twice as much comparing to a single image tar:

1
2
$ ls -lh busy*
-rw-rw-r-- 1 chao chao 12M Feb 1 12:00 busy-realguess-jq-box.tar

Compress it:

1
$ out=busy-realguess-jq-box.tar && docker save busybox realguess/jq > $out && gzip $out

Much better in size:

1
2
$ ls -lh busy*
-rw-rw-r-- 1 chao chao 5.7M Feb 1 12:00 busy-realguess-jq-box.tar.gz

Do the reverse, load the tarred Docker images with docker load.

Statistics in January 2015

In January 2015, there are 956 unique visitors making 1,111 visits resulting in 1,320 pageviews, about 43 daily pageviews, about 17% increase comparing to last month.

As today, my blog is still estimated by Alexa. It ranks my blog 880,218 globally and 177,784 in the United States. Lower than last month, but these are estimates.

Where are my visitors located?

27.63% of visits are from the United States, almost 1.64% drop compare to last month. The second place is from India with 6.57%, that is more than 2% drop.

Where do my visitors come from?

Google is the top traffic source with 86.05% of all visits, more than 4% increase comparing to last month. Social is still almost non-existing.

What devices and operating systems are my visitors using?

43.02% are using Windows, then followed closely by Macintosh with 37.62%. And 96.58% visitors are using desktop devices, a slight drop.

What is the top post?

The most popular post is still Split a Large JSON File into Smaller Pieces, it is even more popular than the site’s main index page.

How is my site speed?

The average page load time is 3.26 seconds. The slowest is sampled at 6.95 seconds.

Is my blog getting more and more visitors?

Yes! The month-to-month gain is 14.22%, and year-to-year gain is 646.88%, more than a half of thousdand fold.

Use CLI s3api to Retrieve Metadata of Amazon S3 Object

In Amazon S3 CLI, there are only a handful commands:

1
cp ls mb mv rb rm sync website

We can use cp command to retrieve S3 object:

1
$ aws s3 cp s3://mybucket/myfile.json myfile.json

But if only the metadata of the object, such as ETag or Content-Type is needed, the S3 CLI does not have any command to do that.

Now enter S3API CLI. Not only the CLI commands can retrieve S3 objects, but also associated metadata. For example, retrieve S3 object similar to aws s3 cp:

1
$ aws s3api get-object --bucket mybucket --key myfile.json

Just need the metadata of the object, use head-object, which retrieves metadata without the object itself, as HTTP HEAD method:

Passage of Time 2014

In 2014, there are 6,409 unique visitors making 7,497 visits resulting in 8,711 pageviews, about 24 daily pageviews.

Where are my visitors located?

33.37% of visits are from the United States. The second place is from India with 6.87%.

Where do my visitors come from?

Google is the top traffic source with 87.47% of all visits. Social is almost non-existing.

What devices and operating systems are my visitors using?

44.14% are using Windows, then followed closely by Macintosh with 36.63%. And 96.77% visitors are using desktop devices.

What is the top post?

The most popular post is still Split JSON File into Multiple Parts.

How is my site speed?

The average page load time is 4.33 seconds and the slowest is sampled at 19.71 seconds from 56 samples.