Thursday, February 26, 2015

About AngularJS directive

1. How directives are compiled:


HTML compilation happens in three phases:
  1. $compile traverses the DOM and matches directives.
    If the compiler finds that an element matches a directive, then the directive is added to the list of directives that match the DOM element. A single element may match multiple directives.
  2. Once all directives matching a DOM element have been identified, the compiler sorts the directives by their priority.
    Each directive's compile functions are executed. Each compile function has a chance to modify the DOM. Each compile function returns a link function. These functions are composed into a "combined" link function, which invokes each directive's returned link function.
  3. $compile links the template with the scope by calling the combined linking function from the previous step. This in turn will call the linking function of the individual directives, registering listeners on the elements and setting up $watchs with the scope as each directive is configured to do.

2. Difference between Controller and Link
    When do I want my code to run
  • Before compilation? – Controller
  • After compilation? – Link
3. Controller "$scope" and link "scope"
- controller ‘$scope’ and link ‘scope’ are the same thing. The difference is paramaters sent to the controller get there through Dependency Injection (so calling it ‘$scope’ is required), where parameters sent to link are standard order based funcitons.  

4. Why do we have "controller" in directive
So we can do awesome stuff like using one directives controller in another. We simply set something we want to “this” and get it using the “require” option in the directive.




Reference Link:

AngularJS execution order and Directive compile



The execution order is:
  1. app config
  2. app run
  3. directive setup
  4. directive compile
  5. app controller
  6. directive link
  7. ** Data resolve called **
  8. new route's controller

Reference Link:

Sunday, February 22, 2015

In the trenches: Transclude in AngularJS

In the trenches: Transclude in AngularJS: Transclude - That's not a word you'll find in a dictionary :). Once you dive into Angular , creating custom directives is a daily c...

Monday, February 16, 2015

node-sass doesn't support the latest version of nodejs

When I did

npm install

I got the following problem:

The imported project "C:\Microsoft.Cpp.Default.props" was not found. 
Confirm that the path in the <Import> declaration is correct, and that the file exists 
on disk.
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (D:\..\node_modules\npm\node_modules\node-gyp\lib\build.js:267:23)
gyp ERR! stack     at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:797:12)
......


The reason for my situation is because node-sass doesn't support the latest version (0.12.0) of nodejs. After I switched to 0.10.x, the problem was resolved

Saturday, February 14, 2015

Testing Data generator

1) FillTest
URL:  http://www.filltext.com/
Access: Website available
Data type: Json
Description: FillText generates JSON datasets for testing or demonstration purposes.

2) generatedata
URL: http://www.generatedata.com/
Access: Website available
Data type: JSON, XML, CSV, HTML, Excel, LDIF, SQL, Programming Language

3) DBMonster
URL: http://sourceforge.net/projects/dbmonster/
Access: Download is needed
Data type: for SQL database

4) mockaroo
URL: https://www.mockaroo.com/
Access: Website available
Data type: CSV, Tab-Delimited, SQL, Excel, JSON, DBUnit XML

Thursday, February 12, 2015

gem install could not find error

When doing gem insall <pkg>, ex., gem install sass,
if you get the error like this:

Could not find a valid gem 'sass' (>=0), here is why:
Unable to download data from https://rubygems.org/ - SSL_connect returned=1 errno=0 state=SSLv3 read server certificate B: certificate verify failed(https://api.rubygems.org/latest_specs.4.8.gz)

You can solve the problem by typing the command:


gem source -a http://rubygems.org/

And then do the gem install sass again.

Tuesday, February 10, 2015

Exceptions of lacking org.springframework.stereotype.Repository annotation

The @Repository annotation inndicates that an annotated class is a "Repository" (or "DAO").
A class thus annotated is eligible for Spring DataAccessException translation. The annotated class is also clarified as to its role in the overall application architecture for the purpose of tools, aspects, etc.
As of Spring 2.5, this annotation also serves as a specialization of @Component, allowing for implementation classes to be autodetected through classpath scanning.

I have JpaBlogEntryRepo class in my application. If I forgot to add the @Repository annotation before the class declaration, the following exception will be raised at the time of starting the server (mine is tomcat):


SEVERE: Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'blogEntryServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private firstapp.core.repositories.BlogEntryRepo firstapp.core.services.impl.BlogEntryServiceImpl.entryRepo; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [firstapp.core.repositories.BlogEntryRepo] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
 ...
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private firstapp.core.repositories.BlogEntryRepo firstapp.core.services.impl.BlogEntryServiceImpl.entryRepo; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [firstapp.core.repositories.BlogEntryRepo] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
 at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:561)
 ... 24 more

Sunday, February 8, 2015

is(nullValue()) and doesNotExist() for jayway.jsonpath

There are Account and AccountResource in my application. For testing, I add @JsonIgnore before my getPassword() method so that it won't return password for my test.

I use jayway.jsonpath to validate those returned value;
If the version of jayway.jsonpath is 0.9 and older, is(nullValue()) can be used:

mockMvc.perform(get("/rest/accounts/1"))
        .andDo(print())
        .andExpect(jsonPath("$.password", is(nullValue())))



But for any newer version, the is(nullValue()) will throw exception:



java.lang.AssertionError: No value for JSON path: $.password, exception: No results for path: $['password']
 at org.springframework.test.util.JsonPathExpectationsHelper.evaluateJsonPath(JsonPathExpectationsHelper.java:101)
 at org.springframework.test.util.JsonPathExpectationsHelper.assertValue(JsonPathExpectationsHelper.java:91)
 at org.springframework.test.web.servlet.result.JsonPathResultMatchers$1.match(JsonPathResultMatchers.java:56)
 at org.springframework.test.web.servlet.MockMvc$1.andExpect(MockMvc.java:152)
 at firstapp.mvc.AccountControllerTest.getExistingAccount(AccountControllerTest.java:142)



To solve this problem for any version that is later than 0.9, we use the doesNotExist() instead, i.e:



mockMvc.perform(get("/rest/accounts/1"))
       .andDo(print())
       .andExpect(jsonPath("$.password").doesNotExist())

Change of Angularjs controller definition from 1.2.x to 1.3.x

For Angularjs 1.2.x and older, the global constructor of controller works:
function AppCtrl(){
    console.log("App Controller Msg")
}

But for Angularjs 1.3.x and later, this code will throw the following exception :

 Error: [ng:areq] http://errors.angularjs.org/1.3.12/ng/areq?p0=AppCtrl&p1=not%20a%20function%2C%20got%20undefined
    at Error (native)
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.3.12/angular.min.js:6:417
    at Rb (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.12/angular.min.js:19:510)
    at tb (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.12/angular.min.js:20:78)
    at $get (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.12/angular.min.js:75:331)
    at https://ajax.googleapis.com/ajax/libs/angularjs/1.3.12/angular.min.js:57:65
    at s (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.12/angular.min.js:7:408)
    at v (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.12/angular.min.js:56:438)
    at g (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.12/angular.min.js:51:299)
    at g (https://ajax.googleapis.com/ajax/libs/angularjs/1.3.12/angular.min.js:51:316)



The old behavior of looking on 'window' for controllers was originally intended for use in examples, demos, and toy apps. It turns out that allowing global controller functions encouraged poor practices. To migrate from 1.2.x to 1.3.x, you need to register your controllers with modules rather than exposing them as globals:



angular.module('myApp',[]).controller('AppCtrl',[function AppCtrl(){
 console.log("App Controller Msg")
}]);

Funny Linux Commands

Source article:
http://www.tecmint.com/20-funny-commands-of-linux-or-linux-is-fun-in-terminal/
http://blog.jobbole.com/41129/

1) sl
Author: Toyoda Masashi
Source Code: https://github.com/mtoyoda/sl

2) cowsay/cowthink
Author: Scott Chacon
Source Code: https://github.com/schacon/cowsay

3) fortune
Author: Ken Arnold
Source Code: ftp://ftp.ibiblio.org/pub/linux/games/amusements/fortune/

4) cmatrix
Author: Chris Allegretta
introduction: http://www.asty.org/cmatrix/

5) telnel towel.blinkenlights.nl
Source: http://www.blinkenlights.nl/services.html

6) figlet/toilet
Source Code for figlet: https://github.com/cmatsuoka/figlet
Related articles: https://sequoia.github.io/blog/fun-with-toilet/    http://www.linux.com/learn/docs/686943-linux-tips-fun-with-figlet-and-toilet

7) xeyes
For mac, it is Jeyes
Related article: http://www.valleyprogramming.com/blog/java-xeyes-app

8) rev(reverse), factor