<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Kenny Chan Zhi Yao</title>
    <description>Kenny Chan&#39;s thought and random ideas on technology
</description>
    <link>http://zhiyao.github.io/</link>
    <atom:link href="http://zhiyao.github.io/feed.xml" rel="self" type="application/rss+xml"/>
    <pubDate>Sat, 30 Jul 2016 05:29:03 +0000</pubDate>
    <lastBuildDate>Sat, 30 Jul 2016 05:29:03 +0000</lastBuildDate>
    <generator>Jekyll v3.1.6</generator>
    
      <item>
        <title>My journey into Angular 2, Angular-CLI, Firebase + AngularFire2</title>
        <description>&lt;p&gt;Having developed a project in Angular 1.5, I was naturally curious what Angular 2 has to offer.
So after hearing much of the pitch from Google IO 2016. I decided to get my hands dirty.&lt;/p&gt;

&lt;p&gt;Here is a simple tutorial on how to get setup using Angular2, Firebase, AngularFire 2 using angular cli. It’s aim is to target programmers who also wanted to dive into the cool new firebase and angular2. This tutorial assumes that you know how to setup a computer with node.js&lt;/p&gt;

&lt;h2 id=&quot;is-angular2-ready-for-prime-time&quot;&gt;Is Angular2 ready for prime time?&lt;/h2&gt;
&lt;p&gt;I still have a little doubt at the moment of my writing. While working on this, I had spend a good deal of hours, fighting with the angular2, firebase and angularfire2 to play nice to each other.
Perhaps in a couple of weeks, things might settle down, fingers cross.&lt;/p&gt;

&lt;p&gt;I am developing this on a windows machine just because I have send my MacBook Pro Retina to Apple for the stain gate issue. But on mac should be relatively simple to setup.&lt;/p&gt;

&lt;h2 id=&quot;requirements&quot;&gt;Requirements&lt;/h2&gt;
&lt;p&gt;If you are unsure what editor to use, I would recommend using &lt;a href=&quot;https://code.visualstudio.com&quot;&gt;vscode&lt;/a&gt;. Reason being that it is cross platform and it plays really well with typescript, which is used extensively on Angular2.&lt;/p&gt;

&lt;p&gt;If you already have &lt;a href=&quot;https://nodejs.org/en/download/&quot;&gt;node.js&lt;/a&gt; installed &lt;em&gt;&lt;a href=&quot;http://blog.teamtreehouse.com/install-node-js-npm-windows&quot;&gt;(for window noobs)&lt;/a&gt;&lt;/em&gt;, install the &lt;code class=&quot;highlighter-rouge&quot;&gt;angular-cli&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;typings&lt;/code&gt; using command line with node package manager(npm):&lt;/p&gt;

&lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    npm install -g angular-cli typings
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;

&lt;h2 id=&quot;getting-started&quot;&gt;Getting Started&lt;/h2&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;Create a new project&lt;/p&gt;

    &lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; ng new &amp;lt;project_name&amp;gt;
 cd &amp;lt;project_name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Install AngularFire2 and Firebase&lt;/p&gt;

    &lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; npm install angularfire2 firebase --save
&lt;/code&gt;&lt;/pre&gt;
    &lt;/div&gt;

    &lt;p&gt;what this does essentially is to install the &lt;code class=&quot;highlighter-rouge&quot;&gt;angularfire2&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;firebase&lt;/code&gt; library, and the changes will be reflected in the &lt;code class=&quot;highlighter-rouge&quot;&gt;package.json&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;/node_modules&lt;/code&gt; folder&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Adding angularfire2 and firebase into &lt;code class=&quot;highlighter-rouge&quot;&gt;angular-cli-build.js&lt;/code&gt;&lt;/p&gt;

    &lt;p&gt;Any time that you have added a library from npm, you would need to include them in this file so that angular-cli will know how to bring them from &lt;code class=&quot;highlighter-rouge&quot;&gt;/node_modules&lt;/code&gt; to the &lt;code class=&quot;highlighter-rouge&quot;&gt;/dist&lt;/code&gt; folder&lt;/p&gt;

    &lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; //angular-cli-build.js
 /* global require, module */

 var Angular2App = require(&#39;angular-cli/lib/broccoli/angular2-app&#39;);

 module.exports = function(defaults) {
 return new Angular2App(defaults, {
     vendorNpmFiles: [
     &#39;systemjs/dist/system-polyfills.js&#39;,
     &#39;systemjs/dist/system.src.js&#39;,
     &#39;zone.js/dist/**/*.+(js|js.map)&#39;,
     &#39;es6-shim/es6-shim.js&#39;,
     &#39;reflect-metadata/**/*.+(ts|js|js.map)&#39;,
     &#39;rxjs/**/*.+(js|js.map)&#39;,
     &#39;@angular/**/*.+(js|js.map)&#39;,

     // add this 2 lines in
     &#39;angularfire2/**/*.js&#39;,
     &#39;firebase/*.js&#39;
     ]
 });
 };
&lt;/code&gt;&lt;/pre&gt;
    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Build&lt;/p&gt;

    &lt;p&gt;Run &lt;code class=&quot;highlighter-rouge&quot;&gt;ng build&lt;/code&gt; and check the /dist/vendor&lt;code class=&quot;highlighter-rouge&quot;&gt; folder for the &lt;/code&gt;angularfire2&lt;code class=&quot;highlighter-rouge&quot;&gt; and &lt;/code&gt;firebase` folders.&lt;/p&gt;

    &lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; ng build 
&lt;/code&gt;&lt;/pre&gt;
    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Configure &lt;code class=&quot;highlighter-rouge&quot;&gt;src/system-config.ts&lt;/code&gt;&lt;/p&gt;

    &lt;p&gt;Now we need to add &lt;code class=&quot;highlighter-rouge&quot;&gt;angularfire2&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;firebase&lt;/code&gt; into SystemJS (The dynamic module loader) Update the file with the followings&lt;/p&gt;

    &lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; //src/system-config.ts
 /** Map relative paths to URLs. */
 const map: any = {
 &#39;firebase&#39;: &#39;vendor/firebase/firebase.js&#39;,
 &#39;angularfire2&#39;: &#39;vendor/angularfire2&#39;
 };

 /** User packages configuration. */
 const packages: any = {
 angularfire2: {
     defaultExtension: &#39;js&#39;,
     main: &#39;angularfire2.js&#39;
 }
 };
&lt;/code&gt;&lt;/pre&gt;
    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Configure firebase typescript support&lt;/p&gt;

    &lt;p&gt;To get the firebase typescript support go to &lt;code class=&quot;highlighter-rouge&quot;&gt;src/tsconfig.json&lt;/code&gt; and add the following line&lt;/p&gt;

    &lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; //src/tsconfig.ts
 &quot;files&quot;: [
     &quot;main.ts&quot;,
     &quot;typings.d.ts&quot;,
     &quot;node_modules/angularfire2/firebase3.d.ts&quot;
 ]
&lt;/code&gt;&lt;/pre&gt;
    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Setup your firebase account&lt;/p&gt;

    &lt;p&gt;&lt;em&gt;This is the part that gets change often and most tutorial seems to ignore. Hopefully the steps listed here are comprehensive enough. If not leave a comment and I will try updating this.&lt;/em&gt;&lt;/p&gt;

    &lt;p&gt;Go to &lt;a href=&quot;firebase.google.com&quot;&gt;firebase&lt;/a&gt;, once you are setup go create a new project&lt;/p&gt;

    &lt;p&gt;Locate your project-name&lt;/p&gt;

    &lt;p&gt;&lt;img src=&quot;http://zenlab.me/images/projectname.png&quot; alt=&quot;locate project name&quot; /&gt;&lt;/p&gt;

    &lt;p&gt;To locate the api-key: https://console.developers.google.com/apis/credentials?project=YOUR-PROJECT&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Setup Firebase Database Auth Rules&lt;/p&gt;

    &lt;p&gt;Navigate to the rules of the firebase database, and set the read to true. I know it isn’t ideal but for the purpose of this tutorial the objective is to get you setup as simple as possible.&lt;/p&gt;

    &lt;p&gt;&lt;img src=&quot;http://zenlab.me/images/databaseauth.png&quot; alt=&quot;navigate to change firebase database&quot; /&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Seed Firebase Database&lt;/p&gt;

    &lt;p&gt;Seed the firebase database with the following content&lt;/p&gt;

    &lt;p&gt;&lt;img src=&quot;http://zenlab.me/images/database-seed.png&quot; alt=&quot;seeding firebase database&quot; /&gt;
 Or just import the following &lt;a href=&quot;http://zenlab.me/images/angular-firebase-export.json&quot;&gt;json file&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Inject AngularFire&lt;/p&gt;

    &lt;p&gt;Open &lt;code class=&quot;highlighter-rouge&quot;&gt;src/app/main.ts&lt;/code&gt; and inject Firebase providers and specify your default Firebase:&lt;/p&gt;

    &lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; import { FIREBASE_PROVIDERS, 
 defaultFirebase } from &#39;angularfire2&#39;;

 bootstrap(AppComponent, [
     FIREBASE_PROVIDERS,
     defaultFirebase({
         apiKey: &quot;api-key&quot;,
         authDomain: &quot;&amp;lt;firebase_project_name&amp;gt;.firebaseapp.com&quot;,
         databaseURL: &quot;https://&amp;lt;firebase_project_name&amp;gt;.firebaseio.com/&quot;,
         storageBucket: &quot;gs://&amp;lt;firebase_project_name&amp;gt;.appspot.com&quot;
     })
 ]);
&lt;/code&gt;&lt;/pre&gt;
    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Use AngularFire and bind to a items list&lt;/p&gt;

    &lt;p&gt;Open &lt;code class=&quot;highlighter-rouge&quot;&gt;src/app/app.component.ts&lt;/code&gt;&lt;/p&gt;

    &lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; import { Component } from &#39;@angular/core&#39;;
 import { AngularFire, FirebaseListObservable } from &#39;angularfire2&#39;;

 @Component({
 moduleId: module.id,
 selector: &#39;app-root&#39;,
 templateUrl: &#39;app.component.html&#39;,
 styleUrls: [&#39;app.component.css&#39;]
 })

 export class AppComponent {
 items: FirebaseListObservable&amp;lt;any[]&amp;gt;;

 constructor(af: AngularFire) {
     this.items = af.database.list(&#39;items&#39;)
 }
&lt;/code&gt;&lt;/pre&gt;
    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Update app.component.html&lt;/p&gt;

    &lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;lt;ul&amp;gt;
    &amp;lt;li *ngFor=&quot;let item of items | async&quot;&amp;gt;
            
    &amp;lt;/li&amp;gt;
&amp;lt;/ul&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Start the server&lt;/p&gt;

    &lt;div class=&quot;highlighter-rouge&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;ng server
&lt;/code&gt;&lt;/pre&gt;
    &lt;/div&gt;

    &lt;p&gt;And finally we have magic~&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;So far my journey with angular2 has taught me the following&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Typescript that helps minimize ambiguity in javascript by introducing typed superset of javascript&lt;/li&gt;
  &lt;li&gt;Angular-cli is a command line tool that helps to build a scaffolding, inspired by ember-cli which in terms is inspired by rails.&lt;/li&gt;
  &lt;li&gt;Component first approach which was much inspired by react.js.&lt;/li&gt;
  &lt;li&gt;Firebase real time database.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I hope that you have fun going through with this tutorial.
As the pace of development is fast, I am pretty certain this might not work within several months from date of this post.&lt;/p&gt;

&lt;p&gt;Moving on next, you might want to check out the following&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/angular/angular-cli/wiki&quot;&gt;angular-cli wiki&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://firebase.google.com/docs/&quot;&gt;firebase docs&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.youtube.com/watch?v=8E-dueHCd2o&quot;&gt;ngAir 71&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Happy hacking Angular2&lt;/p&gt;
</description>
        <pubDate>Fri, 29 Jul 2016 09:58:00 +0000</pubDate>
        <link>http://zhiyao.github.io/javascript/angular2/angular-cli/firebase/angularfire2/2016/07/29/journey-angular2-firebase.html</link>
        <guid isPermaLink="true">http://zhiyao.github.io/javascript/angular2/angular-cli/firebase/angularfire2/2016/07/29/journey-angular2-firebase.html</guid>
        
        
        <category>javascript</category>
        
        <category>angular2</category>
        
        <category>angular-cli</category>
        
        <category>firebase</category>
        
        <category>angularfire2</category>
        
      </item>
    
      <item>
        <title>How to batch move a calendar(ICS) dates and time</title>
        <description>&lt;p&gt;calendar-shifter script makes shifting ics calendar of dates and times a lot easier.&lt;/p&gt;

&lt;p&gt;##Background&lt;/p&gt;

&lt;p&gt;Sometimes you just got a calendar file off the internet in a .ics format filled with hundreds of events. Everything was great execpt for one major problem, the timezone or date was wrong. And you have to correct them manually one by one.&lt;/p&gt;

&lt;p&gt;This has happen to me when I downloaded an &lt;a href=&quot;http://www.teambeachbody.com/connect/message-boards?p_p_id=19&amp;amp;p_p_lifecycle=1&amp;amp;p_p_state=exclusive&amp;amp;p_p_mode=view&amp;amp;p_p_col_id=column-6&amp;amp;p_p_col_count=1&amp;amp;_19_struts_action=%2Fmessage_boards%2Fget_message_attachment&amp;amp;_19_messageId=86307460&amp;amp;_19_attachment=Insanity.ics.zip&quot;&gt;old insanity calendar&lt;/a&gt; dated 5 years back. After moving a couple of events on the calendar, I thought to myself that there must be a better way to do this. To my amazement, there was such a tool on Mac’s calendar app or Google calendar.&lt;/p&gt;

&lt;p&gt;##Solution&lt;/p&gt;

&lt;p&gt;So I fired up my text editor and started to code a simple ruby script to do just that.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/zhiyao/calendar-shifter&quot;&gt;calendar-shifter script&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I hope this script could solve someone’s problem as well.&lt;/p&gt;
</description>
        <pubDate>Thu, 26 May 2016 16:42:00 +0000</pubDate>
        <link>http://zhiyao.github.io/ruby/calendar/scripts/2016/05/26/how-to-batch-move-a-calendar-ics-dates-and-time.html</link>
        <guid isPermaLink="true">http://zhiyao.github.io/ruby/calendar/scripts/2016/05/26/how-to-batch-move-a-calendar-ics-dates-and-time.html</guid>
        
        
        <category>ruby</category>
        
        <category>calendar</category>
        
        <category>scripts</category>
        
      </item>
    
      <item>
        <title>Writing Writing Writing... I am not fond of it</title>
        <description>&lt;p&gt;Writing has always not been my forte. But I am here to change that starting from today. Even if no one reads this or my writing is so bad, I would start writing ideas and thoughts at least 1 time a week to begin.&lt;/p&gt;

&lt;p&gt;So to begin I went to research on why I should start writing. Here are some of the list of reasons.&lt;/p&gt;

&lt;p&gt;###1. Focus and reorganise your thoughts
 Before beginning any projects, it pays to start writing about it first. Writing helps me focus on what matters and organise your thoughts in a more coherent manner. Benjamin Franklin once said, “Either write something worth reading or do something worth writing”&lt;/p&gt;

&lt;p&gt;###2. Build an audience and spread your ideas.
 When you write and share your writing, you are putting a piece of yourself out there. Writing actually create an opportunity for you to connect with a stranger.&lt;/p&gt;

&lt;p&gt;###3. Absorb knowledge better
“好记性不如烂笔头”, a chinese proverbs that translate to “the faintest ink is better than the best memory”. We all absorb knowledge better when we write notes. Writing makes you aware of your content.&lt;/p&gt;

&lt;p&gt;###4. Its free
We live in a age where publishing and distributing that article is free of charge. Unlike 20 years ago, publishing anything meant going to a publisher and it get distributed as an article in a magazine or newspaper.&lt;/p&gt;
</description>
        <pubDate>Wed, 18 May 2016 01:35:31 +0000</pubDate>
        <link>http://zhiyao.github.io/writing/2016/05/18/write-write-write.html</link>
        <guid isPermaLink="true">http://zhiyao.github.io/writing/2016/05/18/write-write-write.html</guid>
        
        
        <category>writing</category>
        
      </item>
    
  </channel>
</rss>
