Skip to content

Instantly share code, notes, and snippets.

View shahzadns's full-sized avatar
:octocat:
Working on his projects.

Shahzad Nawaz shahzadns

:octocat:
Working on his projects.
View GitHub Profile
@shahzadns
shahzadns / AngularJS-BaseController.js
Last active February 16, 2019 18:23
This is an example for using a "Base Controller" in an AngularJS application, to get done some basic tasks like destroying $rootscope listeners, or any third-party component.
/**
* @title: `setting up BaseCtrl` in AngularJS 1.3.x
* @author: Shahzad Nawaz
* @dated: 2/28/2015.
*/
(function () {
'use strict';
/*Base Controller starts*/
@shahzadns
shahzadns / $scope.$watch
Last active December 22, 2017 09:18
Watcher demonstration on angular 1.x scope properties - using built-in set, get of objects.
/**
* Created on: Dec 22 2017
* Created by: Shahzad Nawaz
* Derived from different sources, Stakoverflow, Blogs, experience.
*/
console.clear(); //--snippets - clear prev run log
/* rocking Scope class for $watch only */
function Scope() {
@shahzadns
shahzadns / Random-alphanumeric-strings
Last active December 21, 2017 23:46
To get an array of randomly selected alpha-numeric characters, in JavaScript.
/**
* @title: Random-alphanumeric-strings
* @author: Shahzad Nawaz
* @dated: 7/16/2015.
*/
//e.g #1
var sixLenstrings = getRandomStrings(6, 2);
console.log(sixLenstrings);
// output: ["UlTl14", "JZRbSS"]
@shahzadns
shahzadns / REST APIs response format
Last active October 14, 2017 02:46
Provides response format for RESTful APIs for both success and error scenarios.
/**
* Created on: Oct 14 2017
* Created by: Shahzad Nawaz
* Derived from different sources, Stakoverflow, Blogs, experience.
* For more advanced handling - checkout https://github.com/adnan-kamili/rest-api-response-format
*/
// success response example - http status code - always 200
var res = {
@shahzadns
shahzadns / nodejs-enhanced-cjs-pattern
Last active January 23, 2017 19:19
This gist proposes an enhanced CommonJS module declaration pattern for NodeJS.
/*
Date: Jan 19 2017
title: NodeJS enhanced CJS module pattern
author: Shahzad Nawaz
email: shahzadscs@gmail.com
Description:
This gist proposes an enhanced CommonJS module declaration pattern for nodeJS/express modules.
*/