Friday, December 2, 2016

Error: connect ECONNREFUSED

In macOS environment there is no explicit file for my.cnf. It's weird, before I introduced .my.cnf in home directory, applications can connect to remote host (e.g., just fine.

The solution is to force the TCP on .my.cnf


$ brew services restart mysql

It turns out that the MySQL installation on my machine is using socket. What's odd is based is I'm not using localhost (e.g., for database connection's host, despite server and client are same machine, yet MySQL still resorts to using socket.

On Unix, if you are running the server and the client on the same machine, connect to localhost. For connections to localhost, MySQL programs attempt to connect to the local server by using a Unix socket file, unless there are connection parameters specified to ensure that the client makes a TCP/IP connection

Thursday, December 1, 2016

Enabling MySQL's binary logging on macOS

MySQL 5.7.16, installed on macOS Sierra using Homebrew.

With Homebrew installation, it's convenient to access mysql commandline. Whereas using its DMG installer, the mysql commandline can only be accessed using its full path.

mysql --user root --password -e 'SHOW VARIABLES' | grep log_bin

By default, log_bin is disabled
log_bin OFF
log_bin_trust_function_creators OFF
log_bin_use_v1_row_events OFF
sql_log_bin ON

Create directory where to put the binary logging files and its index:
sudo mkdir /var/log/kel-mysql-log-bin/
sudo touch /var/log/kel-mysql-log-bin/binlogging.index
sudo chown -R `whoami` /var/log/kel-mysql-log-bin/

Check the binary logging directory:
ls -la /var/log/kel-mysql-log-bin/

drwxr-xr-x   3 jack  wheel   102 Dec  1 19:55 .
drwxr-xr-x  60 root  wheel  2040 Dec  1 19:55 ..
-rw-r--r--   1 jack  wheel     0 Dec  1 19:55 binlogging.index

Create .my.cnf in user's home path:
vim ~/.my.cnf

.my.cnf content:

Restart MySQL:
mysql.server restart

Check if the binary logging is enabled:
mysql --user root --password -e 'SHOW VARIABLES' | grep log_bin

log_bin ON
log_bin_basename /var/log/kel-mysql-log-bin/binlogging
log_bin_index /var/log/kel-mysql-log-bin/binlogging.index
log_bin_trust_function_creators OFF
log_bin_use_v1_row_events OFF
sql_log_bin ON

Check the binary logging directory:
ls -la /var/log/kel-mysql-log-bin/

drwxr-xr-x   4 jack  wheel   136 Dec  1 19:57 .
drwxr-xr-x  60 root  wheel  2040 Dec  1 19:55 ..
-rw-r-----   1 jack  wheel   154 Dec  1 19:57 binlogging.000001
-rw-r-----   1 jack  wheel    44 Dec  1 19:57 binlogging.index

log_bin variable is not something that is being set directly, it's a read-only variable. To turn the log_bin on, the binary logging directory and index must be specified.

Happy Coding!

Wednesday, October 5, 2016


Destructuring makes code readable

// We could use this directly, but the parameter names won't be obvious
//      EmployeeViewResource.get($state.params)
// So let's do this:
const {employeeId,userId} = $state.params;

EmployeeViewResource.get({employeeId, userId}).$promise.then(result =>

Sunday, October 2, 2016

newing from dynamically-loaded type

newing an object from a dynamically-loaded/reflected type from statically language such as C# and Java requires an API (e.g., Activator.CreateInstance for C# developers). Whereas in node you can still use the new keyword

> new (require('./api/-core/protocol-buffer/proto-mapping')['com.puter.platform.protocols.users.AccountUpdated'])({account: { uuid: {id: '021e4feb-99c4-419b-8891-b38bd6b00897'}}}).encode64();

Just mind the parenthesis after the new keyword.

Have yet to know what's the difference of the above dynamic object creation from ES6's Reflect.construct.

Happy Coding!

Thursday, September 29, 2016

Protobufjs decoding base64

These are same:

var obj = MessageName.decode(Buffer.from(base64string, 'base64'));

var obj = MessageName.decode64(base64string);

Saturday, July 30, 2016

Error with: npm install pdf-fill-form

The solution to following error..

pdf-fill-form@2.0.0 install /Users/jack/node-playground/test-pdf/node_modules/pdf-fill-form
node-gyp rebuild
CXX(target) Release/
CXX(target) Release/
CXX(target) Release/
../src/ fatal error: 'poppler/qt4/poppler-form.h' file not found
1 error generated.
make: *** [Release/] Error 1
gyp ERR! build error 
gyp ERR! stack Error: make failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:276:23)
gyp ERR! stack at emitTwo (events.js:106:13)
gyp ERR! stack at ChildProcess.emit (events.js:191:7)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:204:12)
gyp ERR! System Darwin 15.5.0
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/jack/node-playground/test-pdf/node_modules/pdf-fill-form
gyp ERR! node -v v6.0.0
gyp ERR! node-gyp -v v3.4.0
gyp ERR! not ok 
npm WARN test-pdf@1.0.0 No description
npm WARN test-pdf@1.0.0 No repository field.
npm ERR! Darwin 15.5.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "pdf-fill-form" "--save"
npm ERR! node v6.0.0
npm ERR! npm v3.10.5

npm ERR! pdf-fill-form@2.0.0 install: node-gyp rebuild
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the pdf-fill-form@2.0.0 install script 'node-gyp rebuild'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the pdf-fill-form package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node-gyp rebuild
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs pdf-fill-form
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! npm owner ls pdf-fill-form
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR! /Users/jack/node-playground/test-pdf/npm-debug.log to install Xcode first:

xcode-select --install

Then re-run:
npm install pdf-fill-form

Happy Coding!

Friday, July 29, 2016

Show invalid inputs upon submit

Old approach was to set all the controls dirty upon submit. This is the better way:

    form, .ng-invalid  {
        border-color: red;