Tag Archives: Javascript

Manage your project dependencies using Bower

Let’s continue our tour on Yeoman.

 

Bower is a tool to manage your js dependencies of your project. you can find out all the dependencies on the bower.json. The bower.json below is the one initialized in the AngularJS project.
Continue reading Manage your project dependencies using Bower

Build an AngularJS webapp using Yeoman

We get the Yeoman working last time.

 

Now, we can use Yeoman to scaffold a AngularJS project. =)

1. Install the angular webapp generator.

npm install -g generator-angular

Continue reading Build an AngularJS webapp using Yeoman

Setup Yeoman in Windows PowerShell

Update @ 2015-09-23: Using PowerShell is just my personal preference, You could use MS-DOS in Windows if your machine doesn’t have PowerShell installed.

1. Download Node.js and install it and make sure you have the npm package manager selected before the installation.
setup-yeoman-in-powershell-1
 
Continue reading Setup Yeoman in Windows PowerShell

Javascript – Calculate the number of days between two dates

// Checkin date
var checkin = '2013-04-04';
var checkin_date = new Date();
checkin_date.setYear(parseInt(checkin.substr(0, 4), 10));
checkin_date.setMonth(parseInt(checkin.substr(5, 2), 10) - 1);
checkin_date.setDate(parseInt(checkin.substr(8, 2), 10));

// Checkout date
var checkout = '2013-04-10';
var checkout_date = new Date();
checkout_date.setYear(parseInt(checkout.substr(0, 4), 10));
checkout_date.setMonth(parseInt(checkout.substr(5, 2), 10) - 1);
checkout_date.setDate(parseInt(checkout.substr(8, 2), 10));

// Calculate the difference
var days = (checkout_date - checkin_date)/1000/60/60/24;

// Output the result
console.log(Math.floor(days));

 

Done =)

Reference: StackOverflow – jquery datepicker + date diff calculation

Javascript – Create a date object from a date string

Previously, we talked about how to convert a date object into string.
Javascript – Get YYYY-MM-DD string from a Date object

This time, we will do the opposite which parses a date string and create a date object.

// Assume we have the date string in YYYY-MM-DD formate
var datestring = '2013-05-03';

var date_obj = new Date();
date_obj.setYear(parseInt(datestring.substr(0, 4), 10));
date_obj.setMonth(parseInt(datestring.substr(5, 2), 10) - 1);
date_obj.setDate(parseInt(datestring.substr(8, 2), 10));

// Verify the date object
console.log(date_obj);

 

Done =)

Reference: StackOverflow – javascript: how to parse a date string

jQuery – Freeze HTML table header and the left columns

A few months ago, i am working on a website project which contains a very wide HTML table. The client wants to keep the top row and the two columns on the left hand side of the table sticky. There is no proper way to do it but and the only solution i could found is using a jQuery library written by Conan Albrecht. The original post could be found in the link below but the source link is no longer valid.
A JQuery Plugin For Freezing Table Rows/Columns

Luckily i have a copy of the lib and you can download here.
Continue reading jQuery – Freeze HTML table header and the left columns