What is Idempotence?

Got asked this question the other day and my mind pulled a blank on me. However an idempotent method is really straight forward. It’s just a method that no matter how many times its called the result state will always be the same, you can call the method many times without concern.

A good example of an idempotent method is the close() method on a data connection, you call it once, it closes, you call it a second time? Still closed, a third time? You get the idea.

This answer on the question of “What is idempotence?” on Stackoverflow explains it really well: http://stackoverflow.com/a/19320202/1445352

Resource: https://en.wikipedia.org/wiki/Idempotence

Update Node.js on a Windows Machine

Since most people are doing front end development on a Mac or are running Ubuntu updating Node.js on Windows seems to be forgotten about on most tutorials or accepted answers on Stackoverflow.

So here it is, download the latest MSI from the Node.js website (and install!) and then run the following commands on CMD Prompt.


npm cache clean
npm update -g

Source: Upgrading Node.js to latest version

JSPM is not recognized as an internal or external command or command not found

This drove me mad, while following the aurelia getting started guide I got as far as adding my GitHub credentials to API requests before I realised the terminal window or command prompt couldn’t see JSPM.

Everything pointed to the PATH variable not being set correctly but from what I could see everything was. In the end through some persistent searching I found this post: JSPM not working from command prompt.

And to develop a little further on that solution adding %appdata%\npm to the windows environment variable PATH solved the issue entirely.

Changing the CTRL + SHIFT + F settings in STS or Eclipse

I’m a big fan of clean well indented code but I’ve found the CTRL + SHIFT + F setting in STS & Eclipse to wrap lines way too soon.

Most people develop at 1080p resolution these days so it makes no sense to wrap lines so soon.

To change the line wrapping rules go to Window > Preferences > Java > Code Style > Formatter

Now create a new profile based off the current one, in my case this was Eclipse [built-in].

Click on Edit.. and go to the Line Wrapping tab, I set the Maximum line width to 240 but you can change it to whatever suits.

line wrapping 2

line wrapping

Source: Possible to change settings for CTRL + SHIFT + F in Eclipse?

Spring Security web classes are not available error

Another random error/bug I came across playing around with Spring MVC, when implementing security I kept getting an error in my security context xml file telling me that required spring security web classes are not available.

While I had spring-security-config in my pom.xml file it seems one of the benefits of Maven had again sh*t itself and a required dependency was not being pulled in.

You need to manually add spring-security-web which solved the issue for me, seems to be a known bug.

<dependency>
    <groupId>org.springframework.security</groupId>
    <artifactId>spring-security-web</artifactId>
    <version>3.1.4.RELEASE</version>
</dependency>

Make sure you update the version to match your spring-security-config dependency.

Source: http://stackoverflow.com/a/9677714/1445352

Dmaven multiModuleProjectDirectory system propery is not set

This error just drove me mad in STS/Eclipse.

You need to add the Default VM argument -Dmaven.multiModuleProjectDirectory=$M2_HOME.

You do this by going to Window > Preference > Java > Installed JREs > Edit

Capture

This assumes you have the Environment variable M2_HOME set up correctly (this should be done when installed Maven).

Source: Stack Overflow