Monday, December 28, 2015

Print angular module dependencies

Here is a simple function to print angular module dependencies:

    angular.__moduleDependencies__ = function (moduleName, indent, nonlast, seen) {
        var module, suffix;
        indent = indent || '';
        seen = seen || [];
        suffix = (indent === '' ? '' : (nonlast ? '├─ ' : '└─ '));
        if (seen.indexOf(moduleName) !== -1) {
            console.log(indent + suffix + moduleName + ' ^');
            return;
        }
        seen.push(moduleName);
        module = angular.module(moduleName);
        if (angular.isDefined(module)) {
            console.log(indent + suffix + moduleName);
            angular.forEach(module.requires, function(requiredModuleName, key){
                var requiredMod = angular.module(requiredModuleName);
                if (angular.isDefined(requiredMod)) {
                    
                    angular.__moduleDependencies__(requiredModuleName,
                        indent + '| ', key < (module.requires.length - 1), seen);
                } else {
                    console.error(indent + requiredModuleName);
                }
            });
        } else {
            console.error(indent + suffix + moduleName);
        }
    };

Usage

angular.__moduleDependencies__('todomvc')


Output

todomvc
 | ├─ ngRoute
 | | └─ ng
 | | | └─ ngLocale
 | └─ ngResource
 | | └─ ng ^

Sunday, December 27, 2015

Filed Eclipse enhancement

Many time I copy a file and the only difference is that I need to map a noun to another.e.g.

firstName -> lastName

getFirstName() -> getLastName()

FIRSTNAME -> LASTNAME

and even better:

FIRST_NAME -> LAST_NAME

FIRST-NAME -> LAST-NAME

This is supported by emacs to some extent. See below.

The Eclipse find/replace dialog should support this using a Case mapping chekbox option like this:

__ Options ____________________

[ ] Case sensitive

    [X] Case mapping

Some languages use camel case, some use hyphen or underscore. The dialog could take that into account.

Support Emacs style case matching replace behavior.

"
15.10.3 Replace Commands and Case
:
:
In addition, when the newstring argument is all or partly lower case, replacement commands try to preserve the case pattern of each occurrence. Thus, the command

M-x replace-string RET foo RET bar RET

replaces a lower case ‘foo’ with a lower case ‘bar’, an all-caps ‘FOO’ with ‘BAR’, and a capitalized ‘Foo’ with ‘Bar’. (These three alternatives—lower case, all caps, and capitalized, are the only ones that replace-string can distinguish.)

If upper-case letters are used in the replacement string, they remain upper case every time that text is inserted. If upper-case letters are used in the first argument, the second argument is always substituted exactly as given, with no case conversion. Likewise, if either case-replace or case-fold-search is set to nil, replacement is done without case conversion.
"

REF: http://www.gnu.org/software/emacs/manual/html_node/emacs/Replacement-and-Case.html#Replacement-and-Case

Sunday, December 13, 2015

TIP: Track window innerWidth using AngularJS

Here is a simple Plumkr to track the window innerWidth using AngularJS:

Try it