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
C:\Windows\System32\notepad.exe
C:\Windows\notepad.exe

No comments:

Post a Comment