Bridging a Wireless NIC?

In our previous post, we have setup Pi-hole in LXD through bridging of macvlan network adapter. Thus, our containers share the network segment with the host's machine network. The limitation of such setup is network bridging only works for Ethernet network adapter instead of Wifi network adapter. Because "many wireless cards don't allow spoofing of the source address" (shown in example later) and also a limitation of 802.11. Read this answer for more complete explanation.

Following this guide, I tried to create a bridge using Bridge Control tool, `brctl` and add the wireless network interface, `wlp3s0` to it.
$ sudo brctl addbr wbr0

$ brctl show wbr0
bridge name     bridge id               STP enabled     interfaces
wbr0            8000.000000000000       no

$ sudo brctl addif wbr0 wlp3s0
can't add wlp3s0 to bridge wbr0: Operation not supported

To resolve the shown error above, we need to enable `4addr` option to our Wifi adapter. The `4addr` is used so that "IEEE 802.3 (Ethernet) frame gets encapsulated in a IEEE 802.11 (WLAN) frame".
$ sudo iw dev wlp3s0 set 4addr on
$ sudo brctl addif wbr0 wlp3s0

Trying to obtain an IP from our bridge interface, `wbr0`.
$ sudo dhclient -d wbr0
Internet Systems Consortium DHCP Client 4.3.5
Copyright 2004-2016 Internet Systems Consortium.
All rights reserved.
For info, please visit

Listening on LPF/wbr0/12:34:56:78:90:01
Sending on   LPF/wbr0/12:34:56:78:90:01
Sending on   Socket/fallback
DHCPDISCOVER on wbr0 to port 67 interval 3 (xid=0x444ed350)
DHCPDISCOVER on wbr0 to port 67 interval 3 (xid=0x444ed350)

And suddenly, we lost connectivity to our Wifi connection and can't find any Wifi network adapter anymore. Because of security reason, it's hard to spoof source MAC address.

To undo this, let's remove all changes we've made. Also, we may need to reboot the machine to regain the Wifi connectivity.
$ sudo brctl delbr wbr0
bridge wbr0 is still up; can't delete it

$ sudo iw dev wlp3s0 set 4addr off
command failed: Device or resource busy (-16)

$ sudo brctl delif wbr0 wlp3s0
$ sudo iw dev wlp3s0 set 4addr off

$ sudo ifconfig wbr0 down
$ sudo brctl delbr wbr0

$ sudo systemctl restart NetworkManager

Nevertheless, there are still different ways to make this works although far more complicated. Since macvlan does not work with wireless adapter, there is an alternative way using ipvlan. However, this was proposed to be included to LXD but postponed since macvlan provides similar features. Furthermore, DHCP will not works in both methods anyway.

This Week I Learned 2018 - Week 50

Last week post or something else from the past instead.

What is the one crucial thing when buying insurance? Make sure it's guaranteed renewable. If not, after a big claim, the said issue will be exclude from your policy upon your renewal. If you have an insurance policy but not guarantee renewable, make it has unlimited coverage. Read the Bank Negara Malaysia (BNM)'s guidelines on this. Meanwhile, something related, when comes to insurance claims, you can claim from multiple insurer for Personal Accident (PA) or life. For medical, only can claim from one insurer.

Do we need to push so hard for Science, Technology, Engineering and Mathematics (STEM) education among young people? Yes and no. Yes, if we want to stay competitive in this industry. No, this will create oversupply of labour and thus wages are kept low. Thus, does not really justify for young people to go into STEM industry where wages are too low and education fee was too high for those looking for good university.

What are the best books of 2018? (via HN and Reddit) Well, you can go through the list from NPRGoodreads, The New Yorker, Science Friday, The Wall Street Journal (politics, children, science fiction, and mysteries), Esquire, Amazon Best Sellers or by category (note best seller), The Guardian, Powell, Five Books (science, fiction, and politics), Library Journal, People, Mental Floss, Indigo, Bill Gates himself (summer and winter), Barnes & Noble, Book Page, Financial Times, History Today, Space  (old and new), Smithsonian (history, science, travel, food, and children), and AV Club. There is one book that caught my attention and found in most of the recommended lists, Madeline Miller's Circe. If you don't have a good material to read for the new year, just check the best books of last year.

What happened when bad water quality and monsoon month (December) meet? Twenty dead fishes. Similar thing happened last year around December where some Betta fishes were dying in mass. Is it water hardness, pH level, ammonia level, nitrite level, or diseases? Our conclusion with  some googling suggested that all possible reason. Drastic water change (like 100%) during raining season will shock the fishes leading to low immune system. Furthermore, irregular water changes increases the possibility of ammonia poisoning overfeed without removing the remains will lead to nitrite poisoning.

One obvious symptom was group of Betta fishes cuddle together at the corner at the tank (see photo below). Last year, the same thing happened to our female sorority tank and we thought because these fishes were "bonding". Our naivety caused the total wipeout of all the female Bettas.

How do you troubleshoot DHCP issue within a container? Use tcpdump. `lxdbr0` is the default bridge network adapter used by LXD.
sudo tcpdump -ni lxdbr0 port 67

Using LXD's Instance Types to Emulate Public Clouds (Amazon, Google, or Azure) Specification

One of the challenges when developing using public clouds provides like Amazon, Google, or Azure is how do we emulate, to the closest specification of their cloud instance locally? LXD, the system container, does have a feature, where you can specify the instance-types during container creation. The public cloud specification is based on the mapping done by the instance type project. While this is not a full emulation of the actual public cloud environment, it's just the essential resource allocations like CPU, memory, disk size, or others. Nevertheless, it's a good and quick way to bootstrap your container to roughly match the resource allocated of these public cloud offering.

Before that, please check the available CPU cores and memory your machine have. In my lappy, we have 4 CPU cores and 7G of memory.
$ nproc && free -g
              total        used        free      shared  buff/cache   available
Mem:              7           6           0           0           1           0
Swap:             0           0           0

How does instance types works in LXD? Let's us create a container based on AWS t2.micro which have the specification of 1 CPU and 1 Gb RAM. All commands are equivalent but using different syntax.
$ lxc launch ubuntu:18.04 c1 -t aws:t2.micro # <cloud>:<instance type>
$ lxc launch ubuntu:18.04 c2 -t t2.micro # <instance type>
$ lxc launch ubuntu:18.04 c3 -t c1-m1 # c<CPU>-m<RAM in GB>

Check our specification of our created containers.
$ lxc config show c1 | grep -E "cpu|memory"
  limits.cpu: "1"
  limits.memory: 1024MB

Again, alternative way to get the config details of the container.
$ lxc config get c1 limits.cpu
$ lxc config get c1 limits.memory

Betta Spawn Log : BSL20181202 : HMPK Metallic Blue (S) x HMPK Metallic Blue (S)

Yet another sibling pair but this time a metallic blue pair. This is the continuity of the previous breeding pair BSL20181105 (Super Red) and BSL20181005 (Super Yellow). Again, the plan was to breed a sibling pair to produce as much fry as much so we can continue breeding multiple generation. If everything goes well and lucky, this will take several generations of breeding.

Male: HMPK Metalic Blue (S)
Age: 4+ months
Temperaments: Normal.
Size: Small (2.5cm body only)
Grade: C

Not the best one we can obtain but nevertheless, the male Betta was healthy and quite active. We fed it well and kept it within the Indian Almond leaves water just to make sure to quarantine it well. Nevertheless, this fish was fresh from the farm and bred in natural environment and fed with live food. Surely, it's better than those bred in house like us.

Female: HMPK Metalic Blue (S)
Age: 4+ months
Temperaments: Highly active.
Size: Small (2.5cm body only)
Grade: B

When we first bought this female Betta, it was so small but we've no choice, there were no female Betta available for this colour. Nevertheless, we decided to proceed ahead as we're confident to condition this female until it's ready to breed. Took us three months to make sure this female was well fed and always in Indian Almond leaves water. Just in case to prevent sickness. Luckily this female turned out to be healthy and very active.

Log Notes
Bought this pair from the Betta farm. The female was so small and we're worried that it may not be a female at all. Nevertheless, we trust the wisdom of the said Betta breeder.

2018-12-01 (1st week)
The pair mated. The female was immediately separated from the male and put into a plastic container. Since we don't have enough overnight water, the female will stay a while within the breeding box.

Female removed so it won't interfere with the male. The male moved the nest several times, most probably of interruption from us.

Black dot or hatched fry were seen in the bubble nest. Estimate the spawn size was roughly 100-plus.

2018-12-09 (2nd week)
Do plan in advanced when you want to breed the fish. The first two weeks are quite crucial as the fry needs to be fed constantly. Otherwise, the whole spawn will starve to death. Hence, if you need to travel, don't breed and also good to have hatch two batch of BBS, in case one batch does not hatch properly. Especially true if you're using expired BBS. We feed the fish two times per day and the growth and colour was noticeable.

2018-12-16 (3rd week)

1/ Always prepare backup food for the first two weeks in case the BBS did not hatch.

Pi-hole with Docker - Installation and Setup

In my previous post, I've covered Pi-hole installation and setup with LXD. For this post, we will try another installation approach, using Docker. Procedure wise, it's quite straightforward, just three steps.
$ docker pull pihole/pihole
$ wget
$ bash

One of the issue that encountered was that the mapped ports maybe have been used for other services. to resolve the port conflicts, especially those using Ubuntu, we have to identify those processes that bind to those ports and stop it.
$ sudo netstat -nltup | grep -E ":53|:67|:80|:443"

Port conflicts with Dnsmasq in Ubuntu can be resolved by disabling its service. However, this is not advisable if you're running services that depends on Dnsmasq like LXD or VPN.

If you like alternative way to properly manage (for example, restarting) the Pi-hole's container, you can write a wrapper shell script and manage it through Docker Compose.

The wrapper shell script based on the ``.
#!/usr/bin/env bash

IP_LOOKUP="$(ip route get | awk '{for(i=1;i<=NF;i++) if ($i=="src") print $(i+1)}')"
IPV6_LOOKUP="$(ip -6 route get 2001:4860:4860::8888 | awk '{for(i=1;i<=NF;i++) if ($i=="src") print $(i+1)}')"


TIMEZONE="$(cat /etc/timezone)"


exec docker-compose $@

And our `docker-compose.yml` file, modified based on this sample.
version: '2'
    container_name: pihole
    restart: unless-stopped
    image: pihole/pihole
    - ServerIP=$IP
    - ServerIPv6=$IPv6
    - WEBPASSWORD=*foobar*
    - DNS1=
    - DNS2=
    - $DOCKER_CONFIGS:/etc/pihole/
    - $DOCKER_CONFIGS/dnsmasq.d/:/etc/dnsmasq.d/
    - "80:80"
    - "443:443"
    - "53:53/tcp"
    - "53:53/udp"
    - "67:67/udp"

Betta Spawn Log : BSL20181105 : HMPK Super Red (M) x HMPK Super Red (M)

Another sibling pair we bought similar to breeding project, BSL20181005. We tends to get sibling pair so we can obtain the same colour as the parent Betta instead of mixing pair from different colours. Our previous breeding projects produce offspring with less than desire colours (as in like Rojak) as shown below.

For breeding Super Red Betta, this is our third breeding project. Breeding project BSL20180518, did produce good offspring, although the number obtained was way too small, roughly around eight and sadly no female Betta at all. Another breeding project BSL20180316, although the female was not a Super Red, did yield one (yes, just one) surviving Super Red. Worst still, it's a very small size male Betta.

What we hope for this breeding project? More female Bettas so we can continue our breeding project for coming generation.

Male: HMPK Super Red (M)
Age: 4+ months
Temperaments: Sluggish and slow.
Size: Medium (3.5cm body only)
Grade: C

When we first bought this male, the movement was quite sluggish and slow. Furthermore, the anal fin was long and caudal fin was not symmetry. Nevertheless, the body size was large and good.

Female: HMPK Super Red (M)
Age: 4+ months
Temperaments: Curious and active.
Size: Medium (3.0cm body only)
Grade: B

Nothing special about this female Betta. Just the body was quite thin and long.

Log Notes
Bought this pair from the Betta farm.

Start conditioning. We don't use the usual glass aquarium as breeding tank but a styrofoam box instead.  Reason being that we want to try different approach using different container. Furthermore, styrofoam box ensures both fishes will not be disturbed and keep the temperature stable.

Mating happened and eggs were observed in the bubble nest.

Some fries were seen swimming freely. Estimated that the this spawn was around 60-plus or more. Based on past experience, not all the fry will survive during these breeding period. As usual, the female was removed immediately.

2018-11-11 (1st week)
We've decided not to use leaving-father-with-fry method and removed the male Betta immediately once.

2018-11-18 (2nd week)
BBS feeding as usual. Growing rate were inconsistent among the fishes.

2018-11-25 (3rd week)
BBS feeding as usual. Growing rate were inconsistent among the fishes.

2018-12-02 (4th week)
Total fry count was around 30-plus, half of what observed initially in the first week.

2018-12-09 (5th week)
To increase the growth of these fishes, we decided to feed BBS twice per day.

1/ Pick a good quality male Betta if possible as it will save us more time instead of fixing any defect issues in multiple breeding projects.

Pi-hole with LXD - Installation and Setup

Pi-hole is wrapper of your DNS server that block all advertisements and trackers. We're using it at our home network to block all those unnecessary bandwidth wasting contents. Setting up for any of your devices is quite straightforward, just make sure your router point to it as DNS server.

While there is a Docker image existed, we have installed it within a LXD container since we have a LXD host exists in our small homelab server, Kabini (more on this in coming posts).

First we setup the container based on Ubuntu 18.04.
$ lxc launch ubuntu:18.04 pihole
$ lxc list -c=ns4Pt
|  NAME  |  STATE  |         IPV4         | PROFILES |    TYPE    |
| pihole | RUNNING | (eth0) | default  | PERSISTENT |

Looking at the table above, notice that container created based on the default profile, the IP we obtained is within the 10.x.x.x range. What we need to do is to change to create a new profile which will enable the container accessible to other in the LAN network. Hence, we need to switch from bridge to macvlan.

The `eth0` network adapter links to your host's network adapter, which can have different naming. For example, `enp1s0` (LAN). However, you can't bridge a Wifi interface to ethernet interface as Wifi by default, only accept a single MAC address from a client.
$ lxc profile copy default macvlan
$ lxc profile device set macvlan eth0 parent enp1s0
$ lxc profile device set macvlan eth0 nictype macvlan

Stop the `pihole` container so we can switch the profile to `macvlan`.
$ lxc stop pihole
$ lxc profile apply pihole macvlan
Profiles macvlan applied to pihole
$ lxc start pihole
$ lxc list
$ lxc list -c=ns4Pt
|  NAME  |  STATE  |         IPV4         | PROFILES |    TYPE    |
| pihole | RUNNING | (eth0) | macvlan  | PERSISTENT |

Next, enter the container and install Pi-hole.
$ lxc exec pihole bash
root@pihole:~# curl -sSL | bash

LXC/LXD 3 - Installation, Setup, and Discussion

It has been a while (like three years ago) since I last look into LXC/LXD (like version 2.0.0). As we're celebrating the end of 2018 and embracing the new year 2019, it's good to revisit LXC/LXD (latest version is 3.7.0) again to see what changes have been made to the project.

Installation wise, `snap` have replace `apt-get` as the preferred installation method so we can always get the latest and greatest updates. One of the issue I faced last time was support for non-Debian distros like CentOS/Fedora and the like was non-existed. To make it work, you have to compile the source code on your own. Even so, certain features was not implemented and made possible. Hence, `snap` is a long awaited way to get LXC/LXD to works on most GNU/Linux distros out there.

Install the packages as usual.
$ sudo apt install lxd zfsutils-linux

The `lxd` pre-installation script will ask you on which version that you want to install. If you choose `latest`, the install the latest version using `snap`. Otherwise, for stable production 3.0 release, it will install the version that came with the package.

You can verify the installation method and version of the LXD binary.
$ which lxd; lxd --version

The next step is to configure LXD's settings, especially storage. In our case here, we're using ZFS, which have better storage efficiency. The only default value changed was the new storage pool name.
$ sudo lxd init
Would you like to use LXD clustering? (yes/no) [default=no]:
Do you want to configure a new storage pool? (yes/no) [default=yes]:
Name of the new storage pool [default=default]: lxd
Name of the storage backend to use (btrfs, ceph, dir, lvm, zfs) [default=zfs]:
Create a new ZFS pool? (yes/no) [default=yes]:
Would you like to use an existing block device? (yes/no) [default=no]:
Size in GB of the new loop device (1GB minimum) [default=45GB]:
Would you like to connect to a MAAS server? (yes/no) [default=no]:
Would you like to create a new local network bridge? (yes/no) [default=yes]:
What should the new bridge be called? [default=lxdbr0]:
What IPv4 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]:
What IPv6 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]:
Would you like LXD to be available over the network? (yes/no) [default=no]:
Would you like stale cached images to be updated automatically? (yes/no) [default=yes]
Would you like a YAML "lxd init" preseed to be printed? (yes/no) [default=no]:

If you want to manage the container as normal user, add yourself to the `lxd` group and refresh the changes.
$ sudo adduser $USER lxd
$ newgrp lxd
$ id $USER | tr ',', '\n'
uid=1000(ang) gid=1000(ang) groups=1000(ang)

Next, we're going to create our first container and show its status. Downloading the whole template container image going to take a while.
$ lxc launch ubuntu:18.04 c1   
Creating c1
Starting c1

$ lxc list -c=ns4Pt
| NAME |  STATE  |         IPV4         | PROFILES |    TYPE    |
| c1   | RUNNING | (eth0) | default  | PERSISTENT |

This Week I Learned 2018 - Week 49

Last week post or some old posts.

How to identify and utilize the hidden pocket time available? Surprisingly, there are 13 time slots available. Generally, how do we to shed unnecessary time off your daily schedule, for examples, choosing what to wear or 40 minutes per day on buying stuff? Planning, automation, and limit the choices you've to make. Plan your week ahead, preps your meals up front, or wear the same type of clothing everyday. All these to prevent decision fatigue by removing yourself to make unnecessary decisions in your daily life.

What are you thankful for? I share the same sentiment with this person. Off course, personally, be content.

Does quitting social medias like Instagram or Facebook make you happier? (via HN) Indeed, as the author experienced, it will make your lighter and thus happier. I believe the same experience you felt when going for vegetarian food for a period, your stomach felt lighter. As usual, moderation is the key but take note, these apps were explicitly designed to "consume" you. Start slowly. Instead of drastic changes, disconnect yourself during the weekend, then weekday, and finally totally remove yourself from it.

How does one living with less? Fit everything you own into one carry-on bag. As usual, there always a subreddit, r/onebag, exists. If you travel a lot for a long period of time, the author list of items is a good way to start or reduce the "stuff" you owned to the essential bare minimum.

How smooth jazz took over the '90s? When you mix the technicality of Jazz and melodically of Pop music, then you have Smooth Jazz.

Is Microsoft Edge (Spartan render engine) or Internet Explorer (Trident render engine) going to be replaced by Microsoft own version of Chromium? Yes and finally bloody yes. (via HN) The demise of Edge/IE browser allows me to check off an item from my to-do item after so many, many years of painful experiences and wasted numerous hours trying to get web sites / web apps to work correctly with Edge/IE and numerous hacks and workarounds (remember the stupid box model and their refusal to fix it?). Maybe right now we can have a consistent and standardize web browser render engine with minimum differences. Yes, they may pull another "embrace, extend, and extinguish" strategy again but at least right now we have a FOSS web browser and Firefox.

Why you should switch to Firefox web browser? (via HN) If you values and concerns about privacy. First, Mozilla values your privacy. All the browser data (bookmark, browser history, and etc) synced through Mozilla Sync cannot access by any parties except you. Second, the Firefox Multi-Account Containers extension where cookies are not shared and kept within the container tab itself. This means that each tab is a new browser session and isolated from other tabs where you can use multiple identities and accounts simultaneously. For Google Chrome, there is this extension, SessionBox that did the same but do you trust a third party vendor instead of Mozilla? Third, tracking protection is already built into the browser itself.

Golang Development Environment with GVM in Ubuntu 18.10

It has been a while since I last looked at development using Golang. Since I was reading some Golang code during this period, might as well look at setting the Golang development environment in Ubuntu 18.10.

There are several ways to setup your Golang development environment. Two good choices are using the default package installation or using Go Version Manager (GVM). There are several options to choose from default packages management, either by DEB or Snap as shown below.
$ go

Command 'go' not found, but can be installed with:

sudo snap install go         # version 1.10.3, or
sudo apt  install golang-go
sudo apt  install gccgo-go 

However, if you want several different Go versions co-exist within the same machine or want to get the latest greatest version, Go Version Manager (GVM) will be the preferred choices. While my preference choice is to use existing package manager (simpler and easier), it's good to look into other approaches. Hence, our focus of this post will be on GVM.

Some prerequisites. Please install and remove some packages (if you have existing Go installed).
$ sudo apt install curl git mercurial make binutils bison gcc build-essential
$ sudo apt remove golang-go
$ sudo snap remove go

Next, download and install the gvm installer. Yes, we all know downloading and running Bash script from the Interweb is rather stupid and insecure. But what the heck.
$ zsh < < (curl -s -S -L
Cloning from to /home/ang/.gvm
Created profile for existing install of Go at "/snap/go/3039"
Installed GVM v1.0.22

Please restart your terminal session or to get started right away run
 `source /home/ang/.gvm/scripts/gvm`

Reload your Bash file settings.
$ source ~/.zshrc

Find the most recent 5 stable releases.
$ gvm listall | grep -v -E '(release|beta|rc)' | sort -rn -t. -k2,2 | head -n 5

Install the binary.
$ gvm install go1.11.2 --binary

Set and use the default binary.
$ gvm use go1.11.2 --default
Now using version go1.11.2

Now check your installation.
$ which go

Now, check your Golang related environment paths.
$ gvm pkgset list

gvm go package sets (go1.11.2)

=> global

See the environment settings of the `global` profile.
$ gvm pkgenv global

If you don't like Gvm and want to nuke the whole installation.
$ gvm implode

Thinkpad X230 - Tweaking Intel Centrino Advanced-N 6205 [Taylor Peak] Slow Wireless Performance

After using that ISP for so many years, the modem that came with the existing packages finally failed. The technician told me that the model of the modem was so old and there was no replacement stock. Instead, we have to substitute it with another modem cum router. Nevertheless, a simple hardware swap and configuration setup and everything back to normal. Typically, the next step was to test the broadband speed from my lappy.

Install the Ookla's speed test CLI tool.
$ sudo apt-get install speedtest-cli

Benchmark the connection speed. Not entirely correct as this depends on the Wifi signals and access protocols. Nevertheless, it will give us a baseline. Result shown below was nothing impressive and seemed wrong and should be higher instead.
$ speedtest | grep -E "Download|Upload"
Download: 21.12 Mbit/s
Upload: 18.83 Mbit/s

Checking through the available network adapter in this lappy.
$ lspci | grep Network
00:19.0 Ethernet controller: Intel Corporation 82579LM Gigabit Network Connection (Lewisville) (rev 04)
03:00.0 Network controller: Intel Corporation Centrino Advanced-N 6205 [Taylor Peak] (rev 34)

Based on the hardware information we obtained in previous step, we want to find out what Wifi protocol does this wireless adapter supported.
$ lspci -vv -s 03:00.0 | grep 802
 Subsystem: Intel Corporation Centrino Advanced-N 6205 (802.11a/b/g/n)

Following the instruction from this page, update the iwlwifi (Intel Wireless Lan) driver to enable antenna aggregation of the Wifi adapter.
$ echo options iwlwifi 11n_disable=8 bt_coex_active=N | sudo tee -a /etc/modprobe.d/iwlwifi.conf
$ sudo modprobe -r iwlwifi
$ sudo modprobe iwlwifi

However, this does not works for me. Even trying different approaches. Perhaps upgrading the internal Wifi adapter that supports 802.11ac? But that is damn tricky as we need to flash the BIOS to remove the whitelisted Wifi adapter.

MSP430 - Online Resourses

Some relevant online resources for those who want to start exploring microcontrollers, especially the TI MSP430G2 LaunchPad development board. This page will be updated from time to time.

How/Where to start?
Technical Documents
  • SLAC485. Sample MSP4302553 codes.
  • SLAU144J. MSP430x2xx Family User's Guide
Tutorials / Webinars / Workshops
Community Sites
University courses based on MSP430
  • ECE2049: Embedded Computing in Engineering Design.
  • EE3376: Microprocessors.
Using other programming languages
  • Assembly programming with MSP430. Contains a list of of online resources related to assembly programming with MSP430.
  • Mecrisp. Another implementation of Forth for MSP430.
  • noForth. Interactive Forth programming language for MSP430. Do this if you want to learn Forth and hardware control through the Egel project.

Setting Git with P4merge in Babun

In previous post, we have discussed on setting up Babun in Windows, the next step was to setup a good merging tool to work with Git. Good and free merging tool is essential when resolving conflict during rebasing or merging. There are several good tools but the one we're comfortable with is P4Merge.

If the `p4merge.exe` binary is not found within the Babun shell, then you've to update the environment variable `$PATH` to append to the exact location of the binary. This can be done through Windows' environment path as well. Since we want our Git configuration file `gitconfig` to be portable with minimum tweaking, we can opt to set direct path.

This is where `cygpath` comes in which will convert path between Unix and Windows.

If we want to find the Windows path to our default Babun installation directory.
$ cygpath -w /

How about the Unix path for `p4merge.exe` binary.
$ cygpath -u "C:\Program Files\Perforce\p4merge.exe"
/cygdrive/c/Program Files/Perforce/p4merge.exe

To make sure Git can find `p4merge.exe` binary from Babun.
$ cygpath -asm "/cygdrive/c/Program Files/Perforce/p4merge.exe"

Next, set `p4merge` our default merge tool and the direct path to its binary.
$ git config --global merge.tool p4merge
$ git config --global mergetool.p4merge.path C:/PROGRA~1/Perforce/p4merge.exe

If you don't like the tab ordering of the merging windows, customize to your liking.
$ git config --global mergetool.p4merge.cmd \
    "C:/PROGRA~1/Perforce/p4merge.exe" $BASE $LOCAL $REMOTE $MERGED

Additionally, `cygpath` also have built-ins options to access default system paths in Windows.
$ cygpath
System information:

  -A, --allusers        use `All Users' instead of current user for -D, -O, -P
  -D, --desktop         output `Desktop' directory and exit
  -H, --homeroot        output `Profiles' directory (home root) and exit
  -O, --mydocs          output `My Documents' directory and exit
  -P, --smprograms      output Start Menu `Programs' directory and exit
  -S, --sysdir          output system directory and exit
  -W, --windir          output `Windows' directory and exit
  -F, --folder ID       output special folder with numeric ID and exit

You can access these path directly with Windows Explorer using `cygstart`.
$ cygstart `cygpath -D`

`cygstart` is a tool is used open almost anything. For example, web URL but you must prepend it with `http`.
$ cygstart

Zsh with Zgen

In my previous post, I've been talking about setting up Babun in Windows environment. One of the main reason to use Babun shell was the available sensible default settings for Zsh shell through oh-my-zsh framework and abundant plugins.

Initially I tried configured Zsh using Antigen based on the post by mgdm. While the tmux can start automatically every time a new session was started, the Zsh can't find the antigen-* functions. Hence, I've decided to switch the Zsh framework to Zgen instead.

First thing first, you will need to switch your current shell from Bash to Zsh. Logout and login again (I can't find any other ways besides this) to reflect the changes.
$ chsh -s `which zsh`

Since my dotfiles repository already existed, hence I only need to add Zgen as Git submodule.
$ mkdir $HOME/.zsh.d
$ cd $HOME/.zsh.d
$ git submodule add

The next step was to setup Zsh config file, `$HOME/.zshrc` with Zgen.
source $HOME/.zsh.d/zgen/zgen.zsh


# If the init script doesn't exist
if ! zgen saved; then
    zgen oh-my-zsh
    zgen oh-my-zsh plugins/tmux

    # Generate the init script from plugins above.
    zgen save

Refresh the Zsh's settings.
$ source $HOME/.zshrc

Development with Docker Toolbox and Babun

For those stuck with or prefer Windows environment, Docker Toolbox is the painless and simplest way to have a consistent development environment using Docker. While we can duplicate the same environment through actual virtualization or Window Subsystem For Linux (WSL), the time taken to configure and setup the environment does not worth the effort. Furthermore, Docker still not quite works for WSL yet.

While the Git Bash for Windows works well for its basic features, a Bash prompt with some *nix utilities, there are still several console apps solely missed like rsync and wget, which will not be bundled together unless you install these separately. Furthermore, you have to waste time to customize the console prompt to your liking (optional).

This is where Babun, a Windows shell over Cygwin, comes in. The sensible default settings provided by  oh-my-zsh with wide range of extensible plugins is good enough without much tweaking.

Babun Docker
Since we're using Docker Toolbox, we also need to make sure it works with Docker Toolbox through Babun Docker.

Go to the Docker QuickStart Terminal and stop the Docker Machine.
$ docker-machine stop default

Open Babun shell and install Babun Docker.
$ curl -s | source /dev/stdin
$ babun-docker-update
$ docker-machine start default

Always load the Docker Machine settings on new opened terminal session.
$ echo "# Docker Machine stuff\n eval \$(docker-machine env default --shell zsh)" >> ~/.zshrc

Zsh and tmux
Next, which is quite crucial for me was to auto load tmux every time Babun or Zsh start.
$ pact install tmux

In your `.zshrc`, enable the tmux plugin and set it to autoload.
# Enable this before the plugin

plugins = (git tmux)

The next step is to download my own tmux configuration file and reload the Zsh shell to reflect the changes. You can also close and re-open the Babun shell. There was an issue where the Babun shell cannot start properly due to unknown error. Update your Babun installation (which actually is Cygwin) should fix the issue.
$ wget
$ source $HOME/.zshrc

Depending on the number of plugins enabled and theme selected, Babun shell can be quite slow. Keep your enabled plugins to a minimum, pick less resource intensive theme, use a Zsh framework to manage these plugins, or optimize Cygwin instead. Nevertheless, one way to check if your shell prompt is slow, run this command.
$ babun check

This Week I Learned 2018 - Week 48

Last week post or read the old stuff instead.

What is this console app that always gave me a conflicting experience every time I use it? ImageMagick. Besides the forking of GraphicsMagick, the use of complex XML format (surprising for a 28-years program at the time of writing) as its configuration settings, it always failed when processing large number of files that exceed its default threshold values. Tweaking it with different settings or disabled it did not resolve the crash issue. Switching to GraphicsMagick yielded the same result. The workaround was convert each image file to PDF in parallel manner and merge all PDF files as single large PDF file.
find . -name '*.jpg' | parallel --progress convert {} {.}.pdf
pdfunite *.pdf scanned_doc.pdf

Does Webpack, Docker Machine, through Virtual Box, and Unix-based host OS work well? No, not really when come to watching changes of files and hot reloading. First, Inotify, the Linux kernel subsystem which notify file changes to application is not and will not be supported in Virtual Box. How about we switch to VMWare? Nope, not supported either. Switching Webpack's watch method to polling have its own issue as well, CPU usage and hot reloading depends on frequency of polling. The key is find the acceptable polling interval. Off course, there are workarounds but not to my liking. If you read carefully, optimal solution using Inotify does not work because the limitation of shared folders through Network File System (NFS) and how file changes event is not communicated between Docker's host and container.

What to consider when designing RESTful API for third parties usage? There are four rules: (1) Use API keys for every request endpoint, (2) Regulate usage through rate limiting using HTTP 429 and API key instead of IP address, (3) Revoke API key if there are usage violation but provides API for client to check rate limits, and (4) Use other means to validate authentication and authorization beside API key.

What are the differences between COALESCE and IFNULL in MySQL? There are several but COALESCE is the preferred choice because (1) It's a standard and should works across multiple DBMS (but do we switch DB that often?), (2) COALESCE support multiple arguments until it can find the first non-NULL value but IFNULL only  support two arguments, and lastly (3) IFNULL is slightly faster than COALESCE. Interestingly, undefined value (1/0) is considered as NULL or missing value.
mysql > SELECT IFNULL(1/0,'yes');
mysql > yes

mysql> SELECT COALESCE(1/0,'yes');
mysql > yes

What is the equivalent of `which` in Windows? `where` as shown below.
C:\where notepad

This Week I Learned 2018 - Week 47

Last week post or something else.

如何避免成为一个油腻的中年猥琐男? 虽然作者的观点是出自于中国男性的观察,但是任何中年人都可从文章借镜。不认同第八条规,“不要停止购物”。年纪越大,物资需求理当越少,甚至到无。


What the recommended anime to watch in year 2018?  Megalo Box. If you're a fan of Cowboy Bebop (not a fan and way overrated), you will like this anime television series as both share a few similarities. 90's hand drawn style (dirty and raw and not like Makoto Shinkai's style), great and unique characters design (looking at you Fairy Tails and Hunter x Hunter), and predictable story line (rag to riches). Meanwhile, if you are a fan of space opera genre, the remake of Legend of the Galactic Heroes is worth watching as well, if you can ignore the  aesthetic of 3D effects which are unappealing and lifeless (looking at you Berzerk 2016).

How do you access the Docker container as root user? Surprisingly, quite straight forward. Uid of zero(0) is equivalent to `root` user.
docker exec -u 0 -it mycontainer bash

What happened when you're using LaTeX to typeset your thesis? A graph shown below (via Reddit) is worth a thousand words. I can relate to the author experience, instead of working on writing, you're struggling with typesetting.

This Week I Learned 2018 - Week 46

Last week post or something else from the past instead.

What I say to people who are looking for a job? (via HN) Is not about job hunting but a good step-by-step guide on identifying on what you want to do with your life or career instead. The advice is useful to evaluate the reality of what you think you love to do and actually doing it for a long period of time. Very much suitable for fresh graduates who don't know what they want to do with their life. For example, most young people with some programming knowledge dream to be a game developer but once they start building their first game, the initial passion will die down and most will quit after a while. Maybe they don't have the lack of right exposure, support, and environment. Nevertheless, passion, interest, and enthusiasm varies from person to person.

Meanwhile, if you had two months off between jobs what would you be doing? Do nothing but eat, sleep, shit, and repeat (just to unwinding) or travel (not the usual tourist type trip but maybe solo trip). Or go through your long postponed someday list and finally pick something up and pursuit it. Perhaps, "work" as usual but at home doing your thing as usual.

What is like to survive a month without computer? (via HN) He is not the first who tried this before, someone else did it for two months, and another one, a year without Internet. We're left wonder what it's like without any exposure to any electronic devices these days. Can we survive a day without our mobile phone? Doubt so for most people these days. Can you imagine the anxiety of not having your phone next to you? It used to be a norm last time. At the end of the digital sabbath, the author felt that it's not that special or spiritual as he hoped. He did, however, recommend that instead of two months, try digital detox or going analogue for two weeks.

Similarly, Vipassana retreat is harder and requires more mental power but maybe too extreme for most people. Another approach, Mauna, the practicing observing the silence is worth trying as well. For us mere mortal, start small. Away from any digital devices or Internet during the weekend. Off everything after 6pm during the weekday. Start from there, slowly but surely.

I've been investigating digital detox for quite some time and implement some of these strategies with moderate success and failure. Still, more adjustments needed as we're trying different approaches.

Is "not doing anything at all is the most productive thing you can do"? Boredom may be good for your creativity. As they said, "an idle mind is the devil's workshop". If you're stuck with a problem do something else not relevant and does not engage your brain. You subconscious mind will do all the works. I was wondering what if we dont do nothing and just stay in a very quiet place, where you have nothing else to do except engaging and confront your own thoughts, will you go crazy? Yes, in 45 minutes, in the world quietest place.

Do you know how Red Hat was initially funded? 8 credit cards with a debt of 50k. Crazy as it sounds but it seemed this was quite common practices for business that can't get proper loans. The sales of Red Hat to IBM did pinque some interests on its founders and humble beginning (via HN). While I believe they should have use apt as the package manager instead of reinventing another subpar package manager, rpm. They have proven themselves to be the most successful companies or poster boy of FOSS world.

How do you keep track of the articles you want to read? Instead of overwhelmed yourself with pending reading list, the best approach is just "now or never". Why put off when you can do it today? If any articles are important enough or worth your attention, read it now. If you have more then 10-plus tabs opened, then you're setting yourself up for information overload. Often, we save too many articles but never get the chance to read it. Most of these articles are mildly interesting and should be put it someday anyway.

Is there anything else like Memepool? Yes, we have Useful Interweb, "which brings only the best links every day".

What is the worse code base you've seen so far? Oracle Database 12.2. The insight shared by an ex-employee did shed some lights on maintaining extremely large legacy software project, in this case, a database management system. While this mess can traced back to overseas Indian team but US team should shares the blame as well. However, it was mess to start with in the first place. And, as usual, there is always a xkcd comic to describe such insane scenario.

This Week I Learned 2018 - Week 45

Last week post or something else from the old archive.


What would happened to Red Hat after IBM have acquired it? (via HN) I'm not sure Red Hat will be still Red Hat (you can work your own FOSS stuff even if it detriment to the company) since IBM is well-known for aggressive creating and protecting its patents portfolio. FOSS is not its core business values, it's just another department. But question remains, why purchased Red Hat? They need to control and be a major player as a cloud vendor compare to Amazon, Microsoft, and Google. Red Hat, with its full FOSS stack, libraries, or tools, provides a platform for them.

Build your own professional-grade audio amp on the sort of cheap (via HN), worth it? Not really, unless you're really into learning (great things to do with your kids) and assembly the whole thing. Most of the DIY kits are way too pricey (Cmoy is the exception) and not worth the effort of getting the whole thing from Ali Express. Again, it's not the audio equipment itself, you still needs to manage the audio room or environment with acoustic panels. Be warned, stop when you can and don't buy into the whole system, cables, furniture, panels, and misc. Unless you can hear the differences (doubt so in my case), you're making money from audio, or friscking rich, don't join the audiophile madness.

Why does privacy matter or I'm not motivated enough to take privacy seriously? Well, if you want to prevent something like Social Credit System from the big brother.

Why kick timing is important in swimming? I intrigued by so many coaches overlook the kick timing aspect in the swimming drill. It seemed the focus was on building the stamina through drill rather than the technique and style. With the right kick timing that syncs with hand actions (catch, pull, exit, and recovery). Sun Yang, is a well-known swimmer which utilizes all three kick timing techniques depends on his breathing patterns as shown in his 1500m freestyle world record in 2012 Olympics race. 2-beat or 4-beat kick for the first 1400m and 6-beat kick for the last 100m.

So You Wanna Be a Chef? (via HN) Why the world need more honesty so young people can calibrate their own expectation in their career of choice? If not, we're setting them up for unreasonable failed expectation and brutal honestly about life, especially when come to financial (high student debt) and emotional reality (unreciprocate passion) . While having passion is good for your career of choice, but this does not means you can work for free or being undercharged.

Was Hindu god, Ganesha created to curb Buddhism? Debatable view but one thing for sure, Buddhism influence was limited by Adi Shankara in the 8th century.

When should you go to bed? The right question to ask is what time you want to wake up instead.

What is your books reading strategy? This approach is probably the most comprehensive I've seen so far.

Upgrading to Ubuntu 18.10 (Cosmic Cuttlefish)

Ubuntu 18.10 was released last week and I've managed to upgrade most of my machines to this newer version. Compare to upgrade experience of 18.04, no show stopper was encountered. Reading through the release notes, it's not a major releases, just some upgrades to existing packages. However, some interesting items caught my attention.

1/ GNOME Disks now supports VeraCrypt. The name sounds familiar until I googled it up. It seemed that VeraCrypt is the fork version of the discontinued TrueCrypt, a popular disk encryption software many moons ago. A few old acquaintances love to use this software to stash their favourite collections.

2/ Sounds over-amplication. This is a welcome needed feature especially if you have lots of music files with incorrect volume range. Previous workaround was to play it through VLC which support this.

This Week I Learned 2018 - Week 44

Last week post or something else from the past.


What is GNU Kind Communication Guidelines? (via HN) The first comment (shown below) caught my attention of effective communication. However, there are always exceptions.
This is excellent; using love and persuasion to help someone improve is so much better than by force, compulsion, and fear. How many children rebel against restrictive and domineering parents? but a child who is loved and taught, but allowed to make choices and pursue independence usually ends up much healthier and happier.
Why digital detox is still more than essential these days in digital era? Repeated interruption leads to lost concentrationDiscussions at HN thread proposed several ways but is there a way to reduce this impact? Yes, but without discipline and life style changes as we're too digitally connected. For a start, take life slowly and be more patience. For example, reading a dead tree book is harder these days we have alternative and faster way to do so. But, isn't it nice to just slow and enjoy the smell and texture of the book while doing so?

When does education stop? (via HN) An essay of justification for studying liberal arts against the practical Science, Technology, Engineering and Mathematics (STEM). Regardless the choice you made in your life or career path, love what you do, and do what you love, provided you don't starve yourself and your family to death. Note the article is hosted in David Bull's site, a very dedicate gaijin woodblock printmaker on preserving and populating Japanese woodblock printmaking.

How to write a technical paper (pdf)? (via HN) The advice on writing good abstract was the best I've read so far. Easy, step-by-step, and straight to the point. Not to mention several other ways such as rules, formula, or algorithm as recommended for further reading.

What do you do in your 1-on-1s with your direct reports? Build trust.

How to check the React version of the app using it? There are many ways (depends on the ReactJs library was minified or not). The simplest way so far (may not work for all) is as follow. Is Facebook is using the latest greatest version? Seemed so.

This Week I Learned 2018 - Week 43

Last week post or something else from the archive instead.

What should you do when you're taking vacant possession of the new property in MY? Download (PDF) the document CIS 7:2014 QLASSIC (Quality Assessment System in Construction) from CIDB (Construction Industry Development Board Malaysia). Read it, print our the checklist, and go through your property to check for any defects. A homeowner have the legal rights to request property developer to rectify any issues within the Defect Liability Period (DLP). Is there any property developer who dares to include this checklist and document during the handover of a new property? Doubt so.

What is like to be a engineering manager? You have no power, take the heat for your team, and mostly focus on management (office politics).

Can you explain JavaScript's closure like I'm five? So many explanations but this example is simple enough to understand. The next step is to understand how closure was used in JS world. Current stage is like you know how to hit a pool ball but don't know why you need to hit it in a certain way.

What the heck is Perl11? (via HN) Well, is Perl 5 + Perl 6. Again, endless drama on the direction of the language itself. Perl have the opportunity to shine and lead the way but lost it. Perl 6, on the other hand, is too little too late.

What are $_, @_, %_ used for? I was quite surprised by the reply, but this answer was outstanding. The `$_` known as default topic variable can be referred as "fill in the blank". How come I never think of that analogy?

What are the non-free installed in your GNU/Linux distribution? Well, you can ask virtual RMS. Running this in my lappy shows the usual suspect packages. Yes, the proprietary drivers or firmwares still remains an unsolved problem for FOSS ecosystem that does not follow the Free System Distribution Guidelines (GNU FSDG).
$ vrms
                Non-free packages installed on x230

amd64-microcode                     Processor microcode firmware for AMD CPUs
fonts-ubuntu                        sans-serif font set from Ubuntu
i965-va-driver                      VAAPI driver for Intel G45 & HD Graphics family
intel-microcode                     Processor microcode firmware for Intel CPUs

                Contrib packages installed on x230

iucode-tool                         Intel processor microcode tool
ttf-mscorefonts-installer           Installer for Microsoft TrueType core fonts
virtualbox-5.2                      Oracle VM VirtualBox

  4 non-free packages, 0.2% of 2788 installed packages.
  3 contrib packages, 0.1% of 2788 installed packages.

This Week I Learned 2018 - Week 42

Last week post or some random stuff from the past.

Can you still be a developer in your 60s? Yes, it's still possible (look at Carl Sassenrath) but looking at the poster qualifications, he is over qualified and can be very intimidating to someone. The root cause is still "cultural fit' and ageism. Perhaps the poster can join the FOSS movement and contribute to it instead? Looking at the positive side, if you can survive until 60s and is fit to work, consider yourself very lucky than most people around that age. Nonetheless, just live below your means, be healthy, and enjoy what you're doing.

Why good sleep is crucial for learning? (via HN) More importantly, insufficient sleep can lead to numerous health issues and diminish your enjoyment of life. While you can't feel the impact when you're young, only at certain age, you will sense something have messed up somehow somewhere in your body. While it varies by person, but you needs at least 8.5 hours of sleep. If you're working, minus your working hours and travel times, with 8 hours of sleep, you're left with 6 hours to do your own errands. What can we do? Lifestyle changes and stick to a constant schedule, every day, every single damn day.

Is semicolon necessary in TypeScript? No but it's good to have it for consistent results, especially for new comer and coding convention. Even this is recommended by Ecma TC39. Off course with much debates and interesting point of view. I believe in the camp of better safe than sorry, just use semicolon;

What should a front end developer knows? Here are some common topics you will encounter eventually.
  1. ForEach vs. Map
  2. Promises vs. Generators
  3. What are the states in Promises?
  4. How many ways to lazy loading an image?
  5. What are the differences between Local Storage, Session Storage, and Cookies?
  6. What is event delegation in JavaScript?
  7. What is Cross-Origin Resource Sharing (CORS)?
What is 30 seconds of code? A bunch of JavaScript code snippets that demonstrates different features of this programming language.

Why we need `EXPORT` and `EXPORT_OK` in Perl? Well, we use the later if we need to let the library consumer or caller to explicitly import the module's symbols like subroutines, variables, constants, and so forth.