Mustache JS the JavaScript Template System

Mustache JS is an open source logic-less template system developed for languages such as JavaScript, C#.NET, Java or any web programming languages.  Mustache provides templates and views as the basis for creating dynamic templates. It is easy to be designed in such a way to separate the logic between UI and JavaScript.

Most of the web developers that are not aware of template systems create new chunks of HTML code and dynamically insert them into the DOM using JavaScript. A common way of doing this is use innerHTML for conventional JavaScript approach, or using JQuery .html(content) to replace the value of your DOM.

The old technique no longer works for developers nowadays, because it makes developers difficult to maintain the system improvement because of the DOM id or classes existed inside your JavaScript source code or certain IF ELSE logic appeared in the HTML content.

Not just it affect code readability, without separately the business logic from the HTML templates, it makes life much more difficult in term of reusing the template for other purposes. Below are a few easy examples on how to use Mustache JS.

 

Mustache Source Code

var rendered = Mustache.render($("#template"), {name: "Khai"});
$('#target').html(rendered);

Template Source Code

<script id="template" type="text/script">
Hello {{ name }}!
</script>

Result / Output

Hello Khai!

And you can complete your repeater like below,

Data Source Code

{
  "person": [
    { "name": "Khai" },
    { "name": "Yong" },
    { "name": "Lim" }
  ]
}

Template Source Code

{{#person}}
<b>{{name}}</b>
{{/person}}

Besides that, you can include simple IF ELSE condition in your Mustache JS like below, # represent true, ^ represent inverted.

Template Source Code

{{#value}} Value is True {{/value}} {{^value}} Value is False {{/value}}

For more examples or technique you can refer to https://github.com/janl/mustache.js or http://www.stackoverflow.com

Conclusion

Overall Mustache JS is very easy to be implemented. And you only required to include a single Mustache JS file. But if you are developing a more comprehensive table / repeater that required things like template, sorting, instant edit mode, or search as a whole package,  probably Knockout JS will be a better solution.

Improve your WIFI signal by diagnosing your networks

It is quite often I received complains from friends and relatives regarding internet problem. What they normally unsatisfied are wifi is slow, having difficulty to connect to certain web page, and even face similar problem when loading Facebook videos. There could be a few reasons behind all these. It can be an Internet Provider issue, router problem, wifi weak, or channels clashing with neighbors.

We will never know the solution if we don’t understand the root causes of the problem that we are facing with. It could be 1 or more causes that I listed above. So the first step is to diagnose the networking problem, and narrow down all the possible angle, so when we know the root cause of it, then we can fix our networks.

Diagnose the WIFI signals

It is always important to diagnose the problem first. So below are a few things we have to try an error before we decide what to fix.

So if you have a router at home, it will be good if it is connected with at least 2 devices. The first one go with a desktop / laptop that connected via a LAN cable (wired), and the second one it is going to be your phone or your tablet device.

Most of the standard cheap router is able to handle less than 5 wireless devices, when you have more than 5 devices,  then you will encounter networking problem.

Slow router processing speed OR too many WIFI access around

If the internet access works good with a wired LAN cable, but do badly with WIFI, then there are only 2 reason why this happened. The first major reason is too many wifi access around. Second reason is because the router processing speed no longer can catch up with all the devices that connected with it. Normally this happened when you have more than 5 to 10 wireless devices that connected to your router simultaneously. The budget way is to disconnect all your wireless devices, and keep only 1 or 2. If the problem is solved, then please consider change your router that can handle more wireless devices.

You still probably can stick with new 2.4GHZ router, but comes with a better processing power. But if after you removed all the devices, and those 2 that you kept earlier are still having internet connection problem, then it must be too many Wifi access around your area, that directly affecting your wifi channel.

If down to this, there is only one solution, is to change to a new AC router (5.0 GHZ).

wave
The different between 2.4Ghz and 5.0Ghz. Source from [http://www.gofetchcomputers.com/blog/]

Could it be Internet Provider Issue?

Yes, potentially it can be an Internet Provider Issue, or broken international cables. If you only use a PC/laptop connected to your router using LAN cable, if the internet is still not met your expectation, then it is most likely an Internet Provider problem.

So I added a flowchart into this post. It will helps you on how to diagnose the slow network problem.

Diagnose Networking

Setup Cloud Station on Synology NAS

Synology Disk Station allowed user to setup a cloud service which is fairly similar like DropBox.com.

The majority of people now switch between multiple devices every day, resulting in a dramatic increase in the popularity of cloud storage. Sometimes our entire productive life – working reports, notes, references – relies on the cloud, meaning we need a cost-efficient, high-capacity yet absolutely private cloud solution more than ever. Synology NAS can provide the solution.

Installing the Synology Cloud Station Client application on windows 7.

cloud1

You can select a quick setuo, or advanced setup. If  you selected advanced setup you can specify your cloud directory where you want to sync.

cloud2

If you completed, you can see the cloud in your windows directory.

cloud3

You can setup multiple cloud sources from different Synology NAS.

cloud4

The toolbar icon will displayed if you have the latest up to date files.

cloud5

cloud6

Below is the mobile version, you can login to specific domain with port number.

IMG_1792

Below is the mobile version of cloud directory.

IMG_1793

You can see your sync files.

IMG_1794

Because it is a mobile version, so  you can filtered files by file format.

IMG_1795

Modify Synology Photo Station Default Directory

By default, Synology Disk Station will only accept one photo directory as the photo station source. But sometimes you want to re-connect the existing photo directory that you already have, or migrate the photo directory to a bigger hard disk volume. You can’t select multiple photo directories unless you install the Synology Media Server application.

If you don’t want to do that, the only solution is to change your photo station default directory to the hard disk volume that you preferred.

After you installed the Photo Station on your Synology NAS, go to Control Panel and refer to the “Shared folder” page.

photo1

photo2

As you can see now, the default shared folder of the Photo Station is pointing at “Volume 1”, So our task now is to migrate it to “Volume 2”.

photo3photo4photo5

 

YouTube now lets you save videos offline in Malaysia

Now it is live in Malaysia

Before that, you probably have to download your youtube video using an online youtube download site, of save your youtube video using windows application such as youtube downloader.

The feature was announced way back in 2014 but it tooks some time to go live in Malaysia.

IMG_1783

IMG_1785 IMG_1784

IMG_1788

You can’t save video while you are watching it

I have a tried on the youtube app on my IPhone IOS 9.1, it somehow designed it in such as way that you can’t save video if you are watching on it. This design surely has to be in this way because if the app allow you to download the video at the same times while you are streaming on it, it is definitely going to affect the network performance. But it looks like working fine with Android phone.

IMG_1787

Default on WIFI, But you can do it with your 3G/LTE

By default you can only download the videos if you are connected to WIFI, but there is a setting somewhere in the youtube app can be turn ON so that you can download the videos too even with you 3G/LTE. I warned you!

IMG_1786

Not all the videos can be downloaded

From what I noticed is that not all the video can be downloaded. I strongly believed that this has to be related to the copyright of the videos.

Once you downloaded those videos, you has to be connected to the internet at least within a range of 48 hours, or else those downloaded video will be automatically removed.

Finally, I tested and proved it, it is working on my phone!

IMG_1791

 

Pick your PC hardware parts virtually before you buy them

10 years ago, when you were decided to buy a new desktop PC, you probably will stick with online review or refer back to anyone who had already bought them at the first place,

The steps are important in our old days, because we want to make sure all the PC hardware parts that chosen by you are compatible with each other.

But now with PC Part Picker, you can do it virtually before you decide to buy them. This is an example of PC parts,

http://pcpartpicker.com/p/2GVVkL

You can customize your desktop PC for all the categories include processor, motherboard, ram, hard disk & any form of accessory.

pcpicker1

The site will displayed if all your parts are actually compatible with each other, showing the total power assumption, comparing models, and most importantly is the total pricing.

pcpicker2

Beside, you can share your PC build, or refer to other expert’s PC build before you finalize your preferred items.

Setup a Surveillance Station on 2 different LAN networks

Currently I installed a Synology NAS at my home, but I need another one to setup at my hometown (300 kilometers away) so that I can helped my parent to monitor their premises. Instead of spending on 2 Synology Disk Stations, I just stick with one, but connect to my parent’s house CCTV and grab all the live content and recording it down into my NAS.

But we need to make sure a couple of things are working now before we link all the CCTVs at a single NAS.

  1. My parent’s CCTVs support port forwarding access
  2. My parent’s router can support external access
  3. My parent’s router support dynamic DNS.
  4. Setup a free domain

 

If (1) and (2) are OK, then the next important step is to setup a free domain at www.Noip.com. let’s say we setup http://secondhouse.ddns.net, update your router’s DDNS (Dynamic Domain Name System) settings so that each time your router reboot, it will notify noip.com server on it’s latest IP address, so that when you access http://secondhouse.ddns.net, you would get the latest IP address.

The next thing is to setup port forwarding for your CCTV, let’s say we already setup port 8000 for external source to access the CCTV, then you should fill up the information like below,

2lan.PNG

The Synology Surveillance Station is good enough to stream the CCTV content across internet. Physically your CCTVs can be at 2 or more different locations, but virtually you are keeping all the video recording at a single NAS.

Connect DS Cam to your Synology NAS

Since we had already setup external access for our Synology NAS, now is time to test it and make sure we can access our Synology Surveillance Station from the WAN network using our phone or browsers. If you are using IOS or Android phone, download the Synology official Surveillance Cam App,

IOS: https://itunes.apple.com/us/app/ds-cam/id349087111?mt=8
Android: https://play.google.com/store/apps/details?id=com.synology.DScam&hl=en

Install them, and you would see the DS cam icon like below,

 

You can enter your router external IP Address with the forwarded port, if you are not sure how to do a port forwarding for Synology NAS please refer to my previous post here.

IMG_1742

The green box is “navigation menu”, and the red one is “view all mode”

IMG_1743

If you click on individual camera, the right box at the top is “manual recording”.

IMG_1744

Navigation Menu

IMG_1745

Recordings video

IMG_1746

You can filter the recording videos by source, cameras, and date. And if you want you can sort it by date.

IMG_1747

This is “view all” mode. You can see all the camera real time activities in a single view.

IMG_1748

 

Setup external access to your Synology NAS

2 Ways

There are 2 ways to setup external access for your Synology NAS, the first way is to setup Synology QuickConnect ID. The other method is to setup router port forwarding. If you are using QuickConnect ID definitely would be safer compare to router port forwarding method because you have to manage your router security better if you are doing it your way.

A standard port to access Synology NAS HTTP is port 5000. HTTP then required port 5001. To access photo station externally then you required a port 80. Surveillance Station required standard port 5000 or 5001.

Synology Network Ports

You can see the complete list of network port for Synology NAS, refer to here.

https://www.synology.com/en-us/knowledgebase/DSM/tutorial/General/What_network_ports_are_used_by_Synology_services

Although in the network port list, they mentioned required port 9000 or 9001 for Surveillance Station, but I noticed that exposing port 5000 and 5001 is sufficient enough.

Router Port Forwarding

Let’s say, for an example if your Synology NAS URL is, http://192.168.0.108:5000/webman/index.cgi

You can set your router port forwarding like below,

forward1.PNG

If your external IP address (router IP address) is like 175.200.142.46, you can access your Synology NAS using http://175.200.142.46:20000/ then you can see your Synology NAS login screen.

For cloud station, just access it with http://175.200.142.46:20001/ will do.

In order to test if your Synology NAS successfully exposed to external access, use Google Paping to double check with “paping 175.200.142.46 -p 20001”.

*Most importantly, setup your Synology NAS properly, please refer to here.*

 

Change Surveillance Station Directory

By default, Synology NAS would choose a primary disk and set the surveillance station directory on it, but sometimes we might want to pick the other hard disk to store all our surveillance recording videos, so below is the way how to do it correctly.

When you accessed the control panel, enter the “Shared Folder”, inside the Shared folder there are a few default system folder that already been there after you setup the Synology NAS.

directory1

directory2

“Edit shared folder surveillance” option will prompt, and you can pick volume 2 as the location.

directory3

Synology NAS will move all the Surveillance Station directories to volume 2 accordingly.

directory4

As a result, you can see that the “Surveillance” volume had been changed to “volume 2” at the end.

directory5