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()

Sunday, 9 June 2013

Replace jquery FormData for file upload javascript

Replacing FormData


Recently there was the requirement to upload file using jquery but for some reasons i found out that the uploading thing is working in properly in Firefox, chrome and safari but not functioning in IE(Internet Explorer).After long search, i had to manage the upload with an iframes for IE,below is the function that did magic :) enjoy

      
function fileUpload(form, action_url, div_id) {
    // Create the iframe...
    var iframe = document.createElement("iframe");
    iframe.setAttribute("id", "upload_iframe");
    iframe.setAttribute("name", "upload_iframe");
    iframe.setAttribute("style", "border: none;display: none;");
 
 
    // Add to document...
    form.append(iframe);
    window.frames['upload_iframe'].name = "upload_iframe";
 
    iframeId = document.getElementById("upload_iframe");
 
    // Add event...
    var eventHandler = function () {
 
            if (iframeId.detachEvent) iframeId.detachEvent("onload", eventHandler);
            else iframeId.removeEventListener("load", eventHandler, false);

            // Message from server...
            if (iframeId.contentDocument) {
                content = iframeId.contentDocument.body.innerHTML;
            } else if (iframeId.contentWindow) {
                content = iframeId.contentWindow.document.body.innerHTML;
            } else if (iframeId.document) {
                content = iframeId.document.body.innerHTML;
            }
 
            //getting the response from server 
           content = content.replace("","").replace("","");
          alert(content);
        }
 
    if (iframeId.addEventListener) iframeId.addEventListener("load",eventHandler,true);
    if (iframeId.attachEvent) iframeId.attachEvent("onload", eventHandler);
 
    // Set properties of form...
    form.attr("target", "upload_iframe");
    form.attr("action", action_url);
    form.attr("method", "post");
    form.attr("enctype", "multipart/form-data");
    form.attr("encoding", "multipart/form-data");
 
    
    form.submit();// Submit the form...
 
}
and that's is all, i hope this could help someone.

find the full source here :
https://github.com/oniadebowale/FormDataWorkAround

Sunday, 2 September 2012

Setup Android on Eclipse

Setup Android on Eclipse


This tutorial is intended for newbies developers that want to start developing Android applications using Eclipse IDE. To start, One most install Java SDK (JDK) (am using jdk 6) and then install the Eclipse, Android SDK and the Android Development Tool (ADT) plugin for Eclipse. Setting up android is quite easy steps to follow 

Android SDK provides the tools and APIs necessary to begin developing applications on the Android platform using the Java programming language. Android offers custom plugin for Eclipse IDE, called Android Development Tools (ADT), that is designed to give you a powerful, integrated environment for building Android applications as at this time of blogging the latest is v19.

Download and Install JDK
Download and install the latest JDK (JDK 1.6 or a later version) from JDK download page
 
Download and Install Eclipse IDE
Download and install Eclipse (Juno) from Eclipse download page. You can also use the Java or RCP version of Eclipse.
 
Download and Install Android SDK Starter Package
You should know that there are two method of getting the starter pack on your computer system.
 
  • By downloading the zip file
  • The other is using the windowS installer
 
 

Page to download Android SDK

Dont be alarm though, as there is no visible differences in both,as both have to create an android sdk folder at a specified directory, which pretty much contain same content. that said,

The Android SDK starter package includes the latest version of the SDK Tools. Included in that component are some tools, called Android SDK and AVD Manager that you can use to download other components from the SDK repository site.
  • Unpack the archive to a suitable location on your machine,if you are using the zip file download . By default, the SDK files are unpacked into a directory named android-sdk-<machine-platform> . For example, on Windows platform the directory will be android-sdk-windows.




  • Android SDK installation directory
Adding Android Platforms to Your SDK
To add one or more Android platforms (for example, Android 1.6 or Android 2.1) to your SDK, use the Android SDK and AVD Manager, included in the SDK starter package. It is recommended to download multiple platforms, so that you can build your application on the lowest version you want to support, but test against higher versions that you intend the application to run on.
  • Launch the Android SDK and AVD Manager on Windows by executing SDK Manager.exe at the root of the SDK directory.
  • On Available Packages menu, select the platforms to download (1.1 to 2.1).
  •  
  • Click Install Selected and then select Accept All to accept selected packages.
  • Click Install Accepted button to start download and install the selected packages.








  •  
Download and Install ADT Plugin
To install the ADT Plugin, you can take advantage of the Eclipse remote update feature. By setting up a remote update site, you can easily download, install, and check for ADT updates. Alternatively, you can download the latest ADT to your development computer as a local site archive.
  • Launch Eclipse, then select Help –> Install New Software.
  • In Available Software dialog, click Add
  • Enter a name for the remote site (ex: Android Plugin) in the Name field and in the Location field, enter this URL:
    https://dl-ssl.google.com/android/eclipse/
    and then click OK. If you have trouble acquiring the plugin, you can try using ‘http’ instead of ’https’ in the URL.
  •  

     
  • Select the checkbox next to Developer Tools, which will automatically select the nested tools Android DDMS and Android Development Tools and then click Next.


  • On the next dialog, click Next to read and accept the license agreement and install any dependencies, then click Finish.
  • Restart Eclipse
  • To check whether the ADT has been installed correctly, try to create a new project by select File > New > Project, you shoud find Android Project listed on project wizard.
Update 2012:
July 2012, Android team has released Android 4.1 (Jelly Bean) software development kit (SDK) has been released in full to developers, which is based on the Linux kernel 3.1.10, it is an incremental update with an aim of improving the user interface both in performance and funtionality. 

Thursday, 16 August 2012

Getting distance of coordinates using java

Getting distance of coordinates 



Yesterday came across way of calculating the distance between coordinates(latitude & longitude) and as usual the application is to be written in java, so after my search i got this snippet i would like to share below which can be used as desired. 
public static double distFrom2(double p_dbllatitude1, double p_dbllongitude1, double p_dbllatitude2, double p_dbllongitude2) { double radianLat1 = p_dbllatitude1 * Math.PI / 180 ; double radianLat2 = p_dbllatitude2 * Math.PI / 180 ; double radiandiff1 = radianLat1 - radianLat2 ; double radiandiff2 = p_dbllongitude1 * Math.PI / 180 - p_dbllongitude2 * Math.PI / 180 ; double s = 2 * Math.asin ( Math.sqrt ( Math.pow ( Math.sin ( radiandiff1 / 2 ) , 2 ) + Math.cos (radianLat1) * Math.cos (radianLat2) * Math.pow (Math.sin (radiandiff2 / 2 ),2))); s = s * 6378137.0 ; s = Math.round ( s * 100000 ) / 100000 ; return s ; }

the result is in meters and to convert to kilometers just divide by 1000. that all for now.a programmer's dairy..