Category Archives: Javascript

Video: Monads and Gonads

Larry Battle

Hello, I'm Larry Battle and I love to program, fix problems and discover new technologies. Check out my stackoverflow and github accounts. I also do book reviews on amazon.com. I'm not the best of writers but I do enjoy spreading my knowledge through my short blogs at bateru.com/news. So please leave some feedback. It would be greatly appreciated.

More Posts - Website

Follow Me:
Twitter

Video: Quick overview of AtScript at ng-europe 2014

- AtScript Documentation

Larry Battle

Hello, I'm Larry Battle and I love to program, fix problems and discover new technologies. Check out my stackoverflow and github accounts. I also do book reviews on amazon.com. I'm not the best of writers but I do enjoy spreading my knowledge through my short blogs at bateru.com/news. So please leave some feedback. It would be greatly appreciated.

More Posts - Website

Follow Me:
Twitter

Code of the Day: Javascript Date.prototype.setDay()

In Javascript, I find it strange how `Date.prototype.getDay()` in defined but `Date.prototype.setDay()`.
So here’s the code for `Date.prototype.setDay()`.

// Sets the Date object to the day of the week.
// @param {Number} - dayIndex must be from 0 - 6, where 0 is sunday.
// @return {Number} returns the primitive value of the Date object.
Date.prototype.setDay = Date.prototype.setDay || function (dayIndex) {
	dayIndex = Math.floor(+dayIndex);
	if (dayIndex < 0 || 6 < dayIndex) {
		throw new Error("Must pass integer between 0-6, where sunday is 0.");
	}
	this.setDate( this.getDate() + dayIndex - this.getDay() );
	return this.valueOf();
};

Demo 1

var a = new Date(Date.parse("Feb 1, 2014"));
a.setDay(0);
console.log(a.toDateString() === "Sun Jan 26 2014" );
a.setDay(6);
console.log(a.toDateString() === "Sat Feb 01 2014" );

Demo 2

// Prings the Monday - Friday for the current day.
var getWeekString = function () {
	var days = [],
		date = new Date();
 
	for (var i = 1, len = 6; i < len; i++) {
		date.setDay(i)
		days.push("## " + date.toDateString() );
	}
	return days;
};
console.log(getWeekString().join("\n\n"));

If you looking for a good Javascript Date library, checkout moment.js.

More info:
MDN Date Object

Larry Battle

Hello, I'm Larry Battle and I love to program, fix problems and discover new technologies. Check out my stackoverflow and github accounts. I also do book reviews on amazon.com. I'm not the best of writers but I do enjoy spreading my knowledge through my short blogs at bateru.com/news. So please leave some feedback. It would be greatly appreciated.

More Posts - Website

Follow Me:
Twitter

Javascript WebGL Partical Effect Demo

Here’s a cool demo that I wanted to share.
Source: http://liveweave.com/TcZrXF

Larry Battle

Hello, I'm Larry Battle and I love to program, fix problems and discover new technologies. Check out my stackoverflow and github accounts. I also do book reviews on amazon.com. I'm not the best of writers but I do enjoy spreading my knowledge through my short blogs at bateru.com/news. So please leave some feedback. It would be greatly appreciated.

More Posts - Website

Follow Me:
Twitter