Saturday, October 4, 2014

RStudio Error: package ‘forecast’ is not available (for R version 3.0.1)

When I tried to install 'forecast' package in RStudio, I got this error:

Warning in install.packages :
  package ‘forecast’ is not available (for R version 3.0.1)

Based on the search results, I need to install the latest version of R and restart RStudio for the changes to take effect.

Update R version using RGui (You can do this even in RStudio, but I felt it is slow) using this code:

if(!require(installr)) { 
+ install.packages("installr"); require(installr)} 

updateR() 

(Referene: http://www.r-statistics.com/2013/03/updating-r-from-r-on-windows-using-the-installr-package/)


R installer will be opened and you need go through the installation wizard. Then the packages will be installed in the new R version and will be updated.

No I can install forecast package in RStudio.

install.packages("forecast")
library(forecast)


Monday, September 29, 2014

MAC OS X- installing package 'gdata' in RStudio (ERROR: tar: failed to set default locale)

These days I am working on R using RStudio and came with an interesting problem when I start to install 'gdata' package.

Error: tar: failed to set default locale

The 'gdata' package is required to use when you want to import excel files to your RStudio workspace.

I found that this is a problem with MAC OS. And you will face this issue if you try to install a new package (not only gdata).

So the solution is to change the settings. In the terminal, type:

 defaults write org.R-project.R force.LANG en_US.UTF-8

This happens because of the internationalization of the R.app and you are using a non standard setup like different language. Thus, you will override the auto detection and set default setting.

Then you need to quit RStudio, for the changes to take effect and then open it. Restarting RStudio using RStudio commands won't work.

Type:
> install.packages("gdata")
> library("gdata", lib.loc="/Library/Frameworks/R.framework/Versions/3.0/Resources/library")

You can do this through the GUI as well.

Tool>Install Packages
Then from right bottom panel under libraries select gdata library.


Reference: http://cran.r-project.org/bin/macosx/RMacOSX-FAQ.html

Friday, August 30, 2013

No more need a router, use Virtual Router - Mac or Windows

With Mac, using virtual router is so easy. No software is required.

Check this video:
http://www.youtube.com/watch?v=nzmVPC3VfLk


Also with Windows 7 and lower Windows OSs using Virtual router plus you are able to create a hotspot. When installing in windows 7 you may face some issues.

http://www.youtube.com/watch?v=HMks0UFrF-w

Some common issues:
1. Virtual Router Could Not Be Started

  •  Close Virtual router
  •  Go to command prompt. 

                     Go to START, enter "cmd", then press "ctrl + shift + enter" to open command prompt as administrator. If not right click and select open as administrator.

  • Copy paste following two commands into command prompt, one by one.

netsh wlan set hostednetwork mode=allow ssid=myNetwork key=password

netsh wlan start hostednetwork

2. The group or resource is not in the correct state to perform the requested operation

In cmd try the following command:
netsh wlan set hostednetwork mode=allow

However, I could not get this to work in Windows 8.

Mobiscroll - Change the default date-format in the output date shown in the text box

Theses days I'm trying out HTML5 to develop mobile applications. I find HTML5 rather useful compared to native coding in iPhone and Android. If not for HTML5, I will need to develop two separate applications for 2 platforms. HTML5 makes my life easier.

I am using mobiscroll plugin 2.3. In the date picker, what ever I do, I was not able to get the output date in the format I need. Always I am getting:

 After trying out different options and after going through various forums, I managed to find how to handle it.

  $("#toDate").mobiscroll().datetime({
                    preset: 'date',

                    dateFormat: 'dd/mm/yyy'',
                    dateOrder: 'ddmmy',
                    onSelect: function() {
                        $(this).val($.scroller.formatDate('dd-mm-yy HH:ii A', $(this).scroller('getDate')));
                    },
                    parseValue: function(val) {
                        var d = new Date(),
                            result = [];
                        try {
                            d = $.scroller.parseDate('dd-mm-yy HH:ii A', val);
                        }
                        catch (e) {
                        }
                        // Set wheels
                        result[0] = d.getDate();
                        result[1] = d.getMonth();
                        result[2] = d.getFullYear();
                       
                        return result;
                    }
     });

So the output will be something like

If you need a format like 'Thursday 31 Aug 2013', then try "DD d M yy".


However, if you are using a previous version, try the solution at:
https://groups.google.com/forum/#!topic/mobiscroll/XbvCMpD1Zds

For date formats refer:
http://docs.mobiscroll.com/datetime

My html part is:

<li data-role="fieldcontain">
<label for="toDate">To:</label> <input type="datetime" id="toDate" /></li>


Thursday, May 23, 2013

Simple html page with JQuery to call an API

I had been developing an API using EJB and some of the interns (they are supposed to develop the client application) had a problem in understanding how to communicate with the API. When I asked them to initiate POST request to an API using javascript only, they looked puzzled.

Thus, I thought to share a sample code with you.

Important code segments to take note.
jQuery.support.cors = true: Force cross site scripting (XSS). Importantly, to work in internet explorer
jQuery.parseJSON(result): A well-formed JSON string is turned to a javascript object.

index.html page is as follows:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<title>Sample jQuery Web Page</title>
<head>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

<script type="text/javascript">

Login = function() {

 var resultDiv = $("#resultDiv");
 jQuery.support.cors = true;    //force cross site scripting - XSS
$.ajax({
        url: "http://xyz.abc.com/user/login",
        type: "POST",
        data: { username: $("#username").val(), password: $("#password").val(), callback: "?" },
        dataType: "text",
        success: function (result) {
            alert(result);
            var res = jQuery.parseJSON(result);
            var status= res.status;
            alert(status);
            switch (status) {
                case 0:
                   alert("sessionId: " + res.sessionId);
                   alert("My profileId: "+ res.profileId);
                   resultDiv.html(result);
                   break;
                default: //e.g. at invalide username, status=2
                    resultDiv.html(result);
            }
        },
        error: function (xhr, ajaxOptions, thrownError) {
        alert(xhr.status);
        alert(thrownError);
        }
    });
};

</script>
</head>
<body>

<h1>Sample jQuery Web Page - Login</h1>

<form>
<label>Username</label>
<input name="Username" type="text" id="username"  /> <br/><br/>
<label>Password</label>
<input name="Password" type="password" id = "password" />
<input name="Submit" type="button" id="submit" onclick="Login()" value="Submit" />
</form>


<div id="resultDiv"></div>


</body>
</html> 

Error "No Transport" - with AJAX/jQuery

Back to my blog after sometime..

I developed a web application to call a remote API (done using EJB) using javascript. Using javascript the data will be requested from the server and the returned data will be displayed in the html page in my local browser. I was ready to deploy as the code worked fine in firefox, chrome and safari.. but found it is not working in Internet Explorer.. :(

I am getting the error AJAX error message mentioned above. AJAX code is not working.. :(
How to handle this..???

Add   jQuery.support.cors = true;    before jQuery.ajax

It is working now even in IE.. :)

This is due to an IE cross domain issue.  JQuery checks whether cross site scripting (XSS) is allowed, and IE under normal browser context blocks cross site scripting. Since it is partially controlled by jQuery.support.cors, with the above tweak we can fix the issue. Thus, XSS is enabled for jQuery.

Reference:
http://mike-ward.net/blog/post/00660/force-jquery-1-5-to-always-allow-cross-site-scripting

Sunday, October 21, 2012

Jar Bundler - MAC OS X

I used to bundle all the jar files using JarBundler we get with Xcode. However, this is not working with JDK 7. Previously, I used it with JDK 1.6 (Apple Java 6) and then made a package file with Package Maker. Since JDK 7 is from Oracle, it cannot be used with Apple's tools like Xcode. Oracle cannot support or use, tools like Xcode or JarBundler as they use non-public APIs.

Therefore, apps using JDK 7 must be bundled with appbundler or javafxpacker. But according to Oracle "JavaFX applications can only be packaged on Mac as desktop applications and cannot be deployed on Mac, because there is no standalone JRE or JavaFX Runtime". Similarly, Launch4j version for Mac could only be used to create .exe files and cannot be deployed on Mac.

So how to do it? It seems the only option is appbundler (http://java.net/projects/appbundler).


In the terminal with the appbundler, you may get the following error ($ant bundle-button):

BUILD FAILED
/Users/me/Downloads/components-ButtonDemoProject/build.xml:16: java.nio.file.NoSuchFileException: /Users/nus/Downloads/components-ButtonDemoProject/Info.plist
at sun.nio.fs.UnixException.translateToIOException(UnixException.java:86)
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102)
at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107)
at sun.nio.fs.UnixCopyFile.copy(UnixCopyFile.java:520)
at sun.nio.fs.UnixFileSystemProvider.copy(UnixFileSystemProvider.java:252)
at java.nio.file.Files.copy(Files.java:1225)
at com.oracle.appbundler.AppBundlerTask.copy(AppBundlerTask.java:566)
at com.oracle.appbundler.AppBundlerTask.copyRuntime(AppBundlerTask.java:357)
at com.oracle.appbundler.AppBundlerTask.execute(AppBundlerTask.java:290)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:390)
at org.apache.tools.ant.Target.performTasks(Target.java:411)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
at org.apache.tools.ant.Main.runBuild(Main.java:809)
at org.apache.tools.ant.Main.startAnt(Main.java:217)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)


It happens because JAVA_HOME is not set properly. Therefore, it can be set by in the terminal:
export JAVA_HOME=`/usr/libexec/java_home --version 1.7.0_10`
or
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_10.jdk/Contents/Home

1.7.0_10 is the JDK version I am using.

Thus, now I am getting BUILD SUCCESSFUL when run $ant bundle-button
You will get .app now.


Reference:
http://docs.oracle.com/javafx/2/installation_2-1/javafx-installation-mac.htm
http://docs.oracle.com/javase/7/docs/technotes/guides/jweb/packagingAppsForMac.html

Sunday, October 14, 2012

Issue - JFileChooser on Mac OS X

These days I am converting a java code written in a Windows system to MAC OS X Lion(10.7.X). Though we know java is platform independent, with MAC OS I am getting various issues. I am having JDK 1.7.

The current problem I am having is with JFileChooser. According to Oracle, file chooser GUI is used for navigating the file system, and then either choosing a file or directory from a list, or entering the name of a file or directory. To display a file chooser, you usually use the JFileChooser API to show a modal dialog containing the file chooser.

So what is the problem I am facing. I am unable to select files with JFileChooser, even if I had set the selection mode as FILES_AND_DIRECTORIES. Even if the files are shown, in file chooser window the file names appear in gray. Thus, even if a file is selected and clicked save, actually a file is not selected. The sample code segment is shown below.

Code...
JFileChooser chooser = new JFileChooser()chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES );

I tried various options to solve it, but could not get it to work. :(

Found the solution!! You need to change the default Look and Feel (LAF or L&F) for MAC.

At the beginning you have to set to JAVA LAF.

try { UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); } catch(Exception e) { System.out.println("Error setting Java LAF: " + e); }

It is working now. :) You can try to change into other LAFs and see how it appears.

receive buffer of socket java.net.DatagramSocket@49cfbdab was set to 20MB, but the OS only allocated 3.36MB

Have you seen this warning in NetBeans??? You need to increase the size of receive buffer.

WARNING: receive buffer of socket java.net.DatagramSocket@49cfbdab was set to 20MB, but the OS only allocated 3.36MB. This might lead to performance problems. Please set your max receive buffer in the OS correctly (e.g. net.core.rmem_max on Linux)
Oct 10, 2012 2:36:08 PM org.jgroups.logging.JDKLogImpl warn
WARNING: receive buffer of socket java.net.MulticastSocket@65ad4b68 was set to 25MB, but the OS only allocated 3.36MB. This might lead to performance problems. Please set your max receive buffer in the OS correctly (e.g. net.core.rmem_max on Linux)


Even though, you can ignore this warning, as suggested by NetBeans it is better to handle it. I am using a MAC OS X. So the changes to max buffer will be done via the Terminal.

The Steps are shown below.

Open Terminal.

supz:~# sudo nvram boot-args="ncl=131072"

supz:~# sudo shutdown -r now

After the restart, enter the following lines shown below.

supz:~# sudo sysctl -w kern.ipc.maxsockbuf=33554432

kern.ipc.maxsockbuf: 8388608 -> 33554432

supz:~# sudo sysctl -w net.inet.udp.recvspace=16777216

net.inet.udp.recvspace: 42080 -> 16777216

MAC OS X - InetAddress.getLocalHost() throws UnknownHostException

I am currently looking at some socket programming code which works in windows, but not in MAC OS X 10.7. I am using JDK 1.7. Previously this worked well in JDK 1.6.

The issue is with InetAddress.getLocalHost()
it throws java.net.UnknownHostException when I used with getHostAddress or getHostName.

The workaround is, edit host files.

Open Terminal and type the line shown below to edit in etc/hosts.
sudo nano /private/etc/hosts

Enter password.

In etc/hosts, (use arrow keys to move around) add a new line with  IP address <space> and hostname

Here, you can get the hostname by typing 'hostname' in terminal

To save control+o, then enter and to exit control+x

Now back in terminal, flush the cache by
dscacheutil -flushcache

Now, there should not be any error.

Sometimes you get both hostname and IP with getLocalHost(). Therefore, from getLocalhost() extract only the substring with the IP.

Steps are:

  1. First convert the inetAddress you get with getLocalHost to String. 
  2. Then get the substring with the IP (Original String will be in the form of <host_name>/<IP>) e.g. String ip_addr
  3. Convert back the IP substring to inetAddress to be used in Socket. InetAddress.getName(ip_addr)

More information @ http://java.net/jira/browse/MACOSX_PORT-564

Saturday, April 21, 2012

smartPLS Installation Error - "An error has occurred. See the log file "

I am having a module on Statistics and I am supposed to use smartPLS 2. 1 year ago I was able to install and work smartPLS quite easily without any issue in installation. But this time I had an installation issue with smartPLS. And during the class I got to know lot of my friends could not install either. So I thought to share the issue and solution to overcome it.

After installing for the first time, when I tried to open I get the error message:

An error has occurred. See the log file 
C:\Program Files(x86) \SmartPLS2\Configuration\1329991694250.log 


When checked in the log file it says:

eclipse.buildId=unknown 
java.version=1.7.0_02 
java.vendor=Oracle Corporation ...........

So how to solve it?

This is due to having JRE 7 in your machine. When you try to install smartPLS 2 with JRE 7, you get an incompatibility issue. With JRE 6, there is no such issue.

Step 1: If you do not have JRE 6 installed, install it. Do not uninstall JRE 7.
Step 2: Copy the path to JRE 6 installation (e.g., c:\Program Files (x86)\Java\jre6\bin\javaw.exe)
Step 3: Open Notepad and copy the below 2 lines to Notepad.


-vm
c:\Program Files (x86)\Java\jre6\bin\javaw.exe

(Note: Last line is the path to JRE 6 installation, it will vary based on your installation. Replace your path of JRE 6 )

Step 4: Save the file as

smartpls.ini
in your SmartPLS 2 program folder (e.g., c:\Program Files (x86)\SmartPLS)

(Note: extension of the file is .ini)



Thus, JRE6 will be automatically used by smartPLS.

There are some other methods in : http://www.smartpls.de/forum/viewtopic.php?t=1882

Thursday, April 19, 2012

Hi.. I am totally new to blogging and I am interested in Android development. So would like to share my experience with you all.. :)