Search blog

Tuesday, September 20, 2016

[[Solved]] - How to Update Eclipse from Terminal or IDE in Ubuntu 12.04, 14.04, 15.04, 16.04

Since I had installed Eclipse manually under '/opt/eclipse/' directory and not from the Ubuntu Software Centre, I couldn't update it from the terminal. Trying to Update Eclipse from the Terminal or within the IDE was giving me several errors such as these:

 Error 1:  
 An error occurred while uninstalling  
 session context was:(profile=epp.package.cpp, phase=org.eclipse.equinox.internal.p2.engine.phases.Uninstall, operand=[R]org.eclipse.platform_root 4.5.1.v20150904-0015 --> null, action=org.eclipse.equinox.internal.p2.touchpoint.natives.actions.CleanupzipAction).  
 Backup of file /opt/eclipse/.eclipseproduct failed.  
 File that was copied to backup could not be deleted: /opt/eclipse/.eclipseproduct 
 Error 2:  
 An error occurred while uninstalling  
 session context was:(profile=epp.package.cpp, phase=org.eclipse.equinox.internal.p2.engine.phases.Uninstall, operand=[R]org.eclipse.rcp_root 4.5.1.v20150904-0015 --> null, action=org.eclipse.equinox.internal.p2.touchpoint.natives.actions.CleanupzipAction).  
 Backup of file /opt/eclipse/readme/readme_eclipse.html failed.  
 File that was copied to backup could not be deleted: /opt/eclipse/readme/readme_eclipse.html 
 Error 3:  
 An error occurred while uninstalling  
 session context was:(profile=epp.package.cpp, phase=org.eclipse.equinox.internal.p2.engine.phases.Uninstall, operand=[R]org.eclipse.rcp_root 4.5.1.v20150904-0015 --> null, action=org.eclipse.equinox.internal.p2.touchpoint.natives.actions.CleanupzipAction).  
 Backup of file /opt/eclipse/readme failed.  
 Permission denied  

Update Eclipse

Looking at the above errors I figured out one of the possible cause was that Eclipse did not have SU (Super User) privilege. So, I executed Eclipse from the terminal giving it Super User privilege. And once in the IDE ran and update from within it. (Look image below)

To run Eclipse with Super User Permission from within the terminal. Launch your terminal with CTRL + ALT + T:

 cd /opt/eclipse  
 sudo ./eclipse  

Updating Eclipse from IDE

Once in Eclipse go to Help > Check for Updates. Now the Eclipse should be updated without any error.

Sunday, September 18, 2016

JavaScript Equivalent of PHP's number_format() Function

Today while going through JavaScript I came across a float value and then wanted to truncate it by two decimal places. I knew in PHP we have the number_format() function and this is what I found for Javascript:

yourFloatVarHere.toFixed(2);

Example:

Suppose you have a value say: 0.589723, and you would like to truncate this value to two decimal place.
 var divide;  
 var num_format;  
 divide = 33/86;  
 num_format = divide.toFixed(2);  

33/ 8 = 0.38372093
Since we have truncated our answer to two decimal place, the final answer will be: 0.38

Wednesday, September 14, 2016

Understanding the Difference Between isset(), empty(), is_empty() and unset() functions in PHP

isset() function in PHP: 

As the name suggests the isset() function in PHP checks whether the variable 'is set' or not. To be more clear this is what happens when this function is called:
  •  Returns TRUE if the variable exists; FALSE otherwise. In other words, only variable that don't exist (or, variable with strictly NULL values) will return FALSE in the isset() function. All variable types that have any type of value, whether it is 0, a blank text string, etc. will return TRUE.

empty() function in PHP: 

The empty() function in PHP returns TRUE or 1 in the following cases:
  1. if the variable is undeclared
  2. if the variable is assigned zero. Example $high = 0;
  3.  if the variable is assigned an Empty string or declared NULL. Example: $high= ''; or $high = NULL;

is_null() function in PHP:

As the name suggests, the is_null() function checks whether a variable is NULL or not. This holds TRUE if:
  1. variable is not declared
  2. variable is declared as NULL. Example: $high = NULL;
Note: '' empty string is not NULL because NULL has no memory allocation, as it has nothing to store, but an empty string does.

    unset() 

    You can wipe a variable out of existence using unset().

    Handy Usage: These functions are handy when you need to make sure that the user filled out the appropriate fields in the form.

    Example:

     <?php   
      // Experimenting with isset(), empty() & is_null()   
     // Comment/Uncomment each condition below and test  
      // $high = '';   
      // $high = NULL;   
      // $high = 0;   
      // $high = 'hello';   
      echo '$high = '.$high.'<br />';   
      echo 'isset($high) = '.isset($high).'<br />';   
      echo 'empty($high) = '.empty($high).'<br />';   
      echo 'is_null($high) = '.is_null($high).'<br />';   
      ?>   
    

    >> Last Updated: 2-Mar-2018

    Sunday, September 11, 2016

    Install and Run the MIT App Inventor Emulator in Ubuntu 12, 13, 14, 15 & 16



    1. You'll need sudo privileges to do the installation.

    Note: The setup programs are 32-bit software. If you have a 64-bit system you may need to install libraries to allow your machine run 32-bit software. One way to do this is to run the command:

     sudo apt-get install lib32z1  
    

    2. If you have previously installed the App Inventor setup software, you should remove those files before installing the new software:

     sudo rm -rf /usr/google/appinventor  
     sudo rm -rf ~/.appinventor  
    


    3. Download the .deb package for the Emulator from the following link: http://appinv.us/aisetup_linux_deb

    4. Use the GDebi Package Installer to install the .deb Emulator package. If you don't have the GDebi Installer you can get it from the Ubuntu Software Centre at: http://bit.ly/2c1AlRD

    5. The software will be installed under /usr/google/appinventor.

    6. Hit Ctrl+Alt+T and fire up your Terminal and change directory as below:

     cd /usr/google/appinventor/commands-for-Appinventor  
    

    7. Once in the appInventor directory enter the following command to finally Run the Emulator:

     ./aiStarter  
    

    8. Now connect the appInventor to the Emulator as shown in the image below:

    Click Image to Enlarge


    Top 5 Posts (Weekly)