Skip to content

Instantly share code, notes, and snippets.

View RajaJaganathan's full-sized avatar
🎯
Focusing

Raja Jaganathan RajaJaganathan

🎯
Focusing
View GitHub Profile
@RajaJaganathan
RajaJaganathan / server.js
Created May 4, 2015 05:29
Serve the static/public file through node js server.
(function() {
'use strict';
var express = require('express');
var app = express();
app.use(express.static('public'));
app.use("/", express.static(__dirname));
app.listen(3033);
@RajaJaganathan
RajaJaganathan / gist:7f0bf89e0fed3af1249e
Created July 6, 2015 17:32
AngularJS:Setting dynamic controller for directives
var app = angular.module('myApp',[]).
directive('communicator', function(){
return {
restrict : 'E',
scope:{},
controller : "@",
name:"controllerName",
template:"<input type='text' ng-model='message'/><input type='button' value='Send Message' ng-click='sendMsg()'><br/>"
}
}).
@RajaJaganathan
RajaJaganathan / layout_debugger.js
Last active August 29, 2015 14:24
CSS Layout Debugger
//Using $$
[].forEach.call($$("*"),function(a){
a.style.outline="1px solid #"+(~~(Math.random()*(1<<24))).toString(16)
})
//Using document.querySelectorAll:
[].forEach.call(document.querySelectorAll("*"),function(a){a.style.outline="1px solid #"+(~~(Math.random()*(1<<24))).toString(16)})
@RajaJaganathan
RajaJaganathan / lodash.config.js
Created September 19, 2015 08:37
Using lodash in Angular Template
var myapp = angular.module('myApp', [])
// allow DI for use in controllers, unit tests
.constant('_', window._)
// use in views, ng-repeat="x in _.range(3)"
.run(function($rootScope) {
$rootScope._ = window._;
});
@RajaJaganathan
RajaJaganathan / Usage.js
Last active May 1, 2020 20:38
lodash utility methods
Usage :
var collections = [
{id: 1, name: 'xyz'},
{id: 2, name: 'ds'},
{id: 3, name: 'rtrt'},
{id: 4, name: 'nhf'},
{id: 5, name: 'qwe'}
];
var filtered = _.findByValues(collections, "id", [1,3,4]);
@RajaJaganathan
RajaJaganathan / json_to_vo.js
Last active June 26, 2019 14:40
JSON to Domain Object Model(Value Object)
// Domain Object Model
// Mapping service JSON value to Value object.
// Use Constructor Functions
// Use prototype methods
// Use static methods
// Do response mapping
function User(id, fname, lname) {
@RajaJaganathan
RajaJaganathan / moment.filter.js
Created September 19, 2015 08:50
AngularJS : Generic moment filter that allow you to use any moment formatting method.
(function () {
'use strict';
angular.module('myApp', [])
.filter('moment', [
function () {
return function (date, method) {
var momented = moment(date);
return momented[method].apply(momented, Array.prototype.slice.call(arguments, 2));
};
@RajaJaganathan
RajaJaganathan / outsideClickHandler.js
Last active September 19, 2015 09:02
Angular detect click outside
app.directive('clickOutSide', function($document){
return {
restrict: 'A',
link: function(scope, elem, attr, ctrl) {
elem.bind('click', function(e) {
// this part keeps it from firing the click on the document.
e.stopPropagation();
});
$document.bind('click', function() {
// magic here.
@RajaJaganathan
RajaJaganathan / ngEnter.js
Created September 19, 2015 09:07
ngEnter directive utility
app.directive('ngEnter', function () {
return function (scope, element, attrs) {
element.bind("keydown keypress", function (event) {
if(event.which === 13) {
scope.$apply(function (){
scope.$eval(attrs.ngEnter);
});
event.preventDefault();
}
@RajaJaganathan
RajaJaganathan / load-view-poupu.js
Last active September 19, 2015 09:14
AngularJS Setup load view/images poup when service call in progress
var app = angular.module('myApp',
['myApp.services', 'myApp.controllers']);
app.run(['$rootScope', function($root) {
$root.$on('$routeChangeStart', function(e, curr, prev) {
if (curr.$$route && curr.$$route.resolve) {
// Show a loading message until promises aren't resolved
$root.loadingView = true;
}
});