Thursday, 29 May 2014

Avoid expressions/braces being shown on page load Angularjs

At first I try to ignore the famous curly braces ‘{{}}’ of the angularjs for binding data to the view, this happens just few seconds before my application try’s to load but then I got fed up and decided to do something about, it turns out it could be resolved.

Actually there multiple ways of resolving this, which will are listed below

  • For most people who don’t like the look of braces in your html code, good news, you can make use of the ‘ng-bind’ of angular directive just like below.
    Eg.
    <div ng-bind="title">
    reference to ngBind could be found in ngbind
  • And for those people who still want to stick with the braces, it isn’t bad news also for you, you can still resolve this issues by making use of the ‘ng-cloak’ which is also an angularjs built-in directive, to use this method to resolve the issue refer below.
    Eg.
    Index.html
    <div ng-cloak="">{{ title }}</div>
    style.css

    [ng\:cloak], [ng-cloak], [data-ng-cloak], [x-ng-cloak], .ng-cloak, .x-ng-cloak { display: none!important;}
    and as well reference to ngCloak could be found in ngCloak
  • And lastly if it is much work and you have no pressure on you, you can just continue ignoring it until it starts getting annoying. Just kidding that all i have.

I hope this can help someone out there.

Tuesday, 27 May 2014

AngularJS executing controller twice

During my angularJS adventure i noticed that my controller seems to be running twice, something like getting two alert when testing for result or double responses during HTTP post, like every nubie to a technology, i had asked myself same question i had asked myself as pass through previous hurdle, i had thought to myself have i made a great mistake in choosing this framework.

So After pulling up my pants and sucking it up, i started googling and found out i had made a mistake but not of the choice of framework but that of my code.When i start my first app with angularjs, i started buy writing :

<div data-ng-controller="MyCrtl">
but then i got to the ease of routing then i switch with :
$routeProvider.when('/',{ templateUrl:'patials/sample.html', controller:'MyCrtl'});
but then i left the previous in my 'sample.html' code which was apparently wrong the meaning of this as i gathered is that i am now instructing AngularJS, to digest my controller twice. 

Solution:

Remove the data-ng-controller="'MyCrtl"' from your html code if you have specified controller:'MyCrtl' I hope this can help someone out there.

Tuesday, 21 January 2014

Run a java project written in eclipse or netbean from the command line

You know when the whole aspect of having so many IDEs to help you do things like compile and running of your code, yeah i was biten in the a** of late and was expect to provide a jar file needed to be executed by someone else but i needed to test the jar which has other jar dependence through a commandline. I knew I had to add the jar dependencies as parameters to the java binary, but I was unsure how to do that. After a bit of googling around , I found out how to achieve this. Here’s a skeleton :


java -classpath lib1.jar;lib2.jar package.otherpackage.classname argv1 argv2 ... argvn

If you have your .class files in a folder, let’s say the name of the folder is classes, then you need to add that folder to the classpath, so the skeleton becomes :


java -classpath classes;lib1.jar ...

I hope you get the picture. If you don’t know what jars to include, but your project works in eclipse, you can open the .classpath file and extract the entries with kind=”lib”. Here is a sample .classpath file from a project :


<?xml version="1.0" encoding="UTF-8"?>
<classpath>
 <classpathentry kind="src" path="src"/>
 <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
 <classpathentry kind="lib" path="lib/commons-codec-1.3.jar"/>
 <classpathentry kind="lib" path="lib/commons-collections-3.2.1.jar"/>
 <classpathentry kind="lib" path="lib/commons-httpclient-3.1.jar"/>
 <classpathentry kind="lib" path="lib/commons-io-1.4.jar"/>
 <classpathentry kind="lib" path="lib/commons-lang-2.4.jar"/>
 <classpathentry kind="lib" path="lib/commons-logging-1.1.1.jar"/>
 <classpathentry kind="lib" path="lib/xml-apis-1.3.04.jar"/>
 <classpathentry kind="output" path="bin"/>
</classpath>

You can easily parse this file and extract them. This was how i got through the task.


Hope this helps someone.

Removing system property

Hi guys its being awhile I guess its because of so much i most be involved in well but this was short and prompting. Recently i was faced with removing a key from System.properties(), what i found out is that some developer, might try to approach this by setting the value to null, but then System.setProperty(key, val) will throw NullPointerException when either key or value is null. Here are 2 ways to remove or clear a system property:
  1. clearProperty(String key) introduced in JDK 1.5.


  2. System.getProperties().remove("key");
    

When java security manager is enabled, Both methods need specific permissions to succeed. Approach 1 requires PropertyPermission "key", "read,write". Approach 2 requires a much wider permission: PropertyPermission "*", "read,write", because you are free to modify/remove all system properties with the returned object from System.getProperties()