October 13, 2017

Install Youcompleteme with pathogen in neovim

Notes for installing YCM with pathogen, Mac environment. Prerequisites: brew cmake python3/python2 (here i use python3) # 1. Install neovim brew install neovim # 2. Install neovim python provider # https://neovim.io/doc/user/provider.html#provider-python pip3 install --upgrade neovim # 3. Install YouCompleteMe cd ~/.vim/bundle git clone https://github.com/Valloric/YouCompleteMe.git && cd $_ git submodule update --init --recursive # here i use system clang rather than downloading, and i only need c family, golang, javascript, rust completer python3 install. ... Read more

September 30, 2017

Cron need root password to be set

I am using Digital Ocean with password login disabled. I provision new machine using ansible userdata, so that every team member can login by ssh. Everything works fine until one day I find cron job doesn’t work correctly under root. The error log is pam_unix(cron:account): expired password for user root (root enforced) The tricky part is, when creating a new droplet, Digital Ocean needs you to login by initial password and reset it immediately. ... Read more

September 12, 2017

Get ready for FreeBSD

I would like to install both FreeBSD and Win10 onto my old workstation. FreeBSD offical manual is quite straight forward and smooth for beginner to complete installation. It just misses some pieces for dual boot with old BIOS, here it is. I am installing version 11.1 and still using ufs with old BIOS, most parts should be compatible to the previous versions. Now when you come to Partitioning step, choose Manual, you might probably see a divice like ada0 with MBR label followed by ada0s1 and ada0s2 with NTFS label. ... Read more

December 21, 2016

Provision AWS Lightsail with Ansible

Amazon has announced a new cloud service Lightsail recently aiming at DigitalOcean, with exact same price and same spec of node. As a heavy DigitalOcean user, I am more than happy to try the alternative provided by AWS. Creating the first instance is not smooth, I got successfully created the first instance by AWS SDK after 3 weeks in and out mails with the support team. TL;DR This post is a quick guide on provisioning the instance by Ansible. ... Read more

November 18, 2016

Https for everything

HTTPS is highly recommended for every web site, as a web developer I am building both my personal and company app under https. Applying for the certificates could be a block for you to migrate/build your site to https as you need to pay for it and it could take quite a while. Thanks to letsencrypt now we can have free open certificate authorify for our sites. I will list the least steps to build a site by using certbot ... Read more

September 11, 2016

How to make ngrx/store work with HMR

In my previous post, I talked of a way to develop angular 2 app with HMR. The vendors I use are @angularclass/hmr and @angularclass/hmr-loader Later on, I thought I might need a data flow tool like redux to manage my app state and I found ngrx/store @angularclass/hmr injects some hmr prefix life cycles into the main module to let you to restore the data. But app state management is optional and you can choose your own way to implement it, so I will walk you through how I implement HMR with ngrx/store ... Read more

September 3, 2016

Angular2 HMR with backend server supported

Currenly I am developing a client + server side boilerplate with Angular 2 and Feathers. For server side, I am using ts-node with nodemon, so far so good. But I find it cumbesome that every time I need to bundle client side code. After some exploring, I find a way to solve the problem. These are the dependencies: angular2-hmr a bootload wrapper on bootstrapModule, it’s cleared classified how to use in github angular2-hmr-loader, a webpack loader to work with the previous one webpack-dev-middleware, just like webpack-dev-server webpack-hot-middleware, an express/feather middleware just like webpack-dev-server w/ hot All of their READMEs clearly walk you through, it just suprises me that few information could be connected on this while it’s a quite general practice in React

March 27, 2016

Vertical align an unknown size image

Some ways to vertiacl align an image in a div, the image’s width and height are unknown Use a helper incline-block div to vertica the image. The helper’s width is 0 Use a tricky way top, right, bottom, left all 0 and margin auto Use css transform translateY demo

June 17, 2015

Unit test Angular directive

I seldom test angular directive unless there is some DOM mutation being processed in the directive, like add/remove classes, show/hide elements or compile/destroy elements. If you have a heavy dependencies on directives, the unit test will be a little bit clunky as for mocking the inline controller of the required directive. Stack overflow gives several alternatives to do so, I am picking two of them which I prefer to go and demo them here. ... Read more

January 31, 2015

Scope, the most important thing in JavaScript

cope and scope chain, the most important mechanism in JavaScript, are barely clearly explained though specified in ECMA-262 version 5.1. Without scope mechanism, there wouldn’t be closure and functional programming. This post is aim to elaborate what happens behind from the very beginning when control enters the global code to execution end. Firstly, for easy literal, let’s agree on the following abbreviation: GE: Global Environment VE: Variable Environment LE: Lexical Environment OLE: Outer Lexcial Environment Reference ER: Environment Record EC: Execution Context go: global object (window for browser, global for NodeJS) ... Read more