Wednesday, December 30, 2015

Do you have any helpful habits or routines?

I felt it's very interesting write-up by Andrew Ng and which I can feel everyday in my life. Worth keeping in my notes!!

Do you have any helpful habits or routines?

I wear blue shirts every day, I don’t know if you know that. [laughter] Yes. One of the biggest levers on your own life is your ability to form useful habits. 

When I talk to researchers, when I talk to people wanting to engage in entrepreneurship, I tell them that if you read research papers consistently, if you seriously study half a dozen papers a week and you do that for two years, after those two years you will have learned a lot. This is a fantastic investment in your own long term development. 

But that sort of investment, if you spend a whole Saturday studying rather than watching TV, there’s no one there to pat you on the back or tell you you did a good job. Chances are what you learned studying all Saturday won’t make you that much better at your job the following Monday. There are very few, almost no short­ term rewards for these things. But it’s a fantastic long­term investment. This is really how you become a great researcher, you have to read a lot.

People that count on willpower to do these things, it almost never works because willpower peters out. Instead I think people that are into creating habits — you know, studying every week, working hard every week — those are the most important. Those are the people most likely to succeed. ­ 
                                                                                                                                           -Andrew Ng 




Tuesday, December 29, 2015

Eclipse popup dialog/ notification message blocked by model shell



In general, while we are working on any eclipse model dialog/wizard ,if any notification dialog appears that will be blocked until get it's the focus. 

Thursday, December 10, 2015

Wednesday, December 9, 2015

Git: Reverting multiple bad commits which are already pushed to a central repository

Here is the case:
I pushed multiple bad commits into a central repository and now I wanted to roll back all of them.

Step1 : check git log and identify your last good commit or till where you wanted to roll back.
$ git log --oneline
5ff2aee commit1 - bad commit
8516637 commit2- bad commit
64db1b7 commit3 - bad commit
6897d4b commit4 - bad commit
6974cb5 commit5 - this is my last good commit
79e63c6 commit6
6cd2939 commit7
d39ae18 commit8

Step2: Do reset hard till your last good commit.
$ git reset --hard 6974cb5

Step3: verify git log
$ git log --oneline
6974cb5 commit5 - this is my last good commit
79e63c6 commit6
6cd2939 commit7
d39ae18 commit8

Step 4: Do force push to central repo
$ git push origin <master repo> -f




Preferences sharing across all workspaces - Handling programatically

To share preferences across all workspaces in eclipse, you need to save preferences via ConfigurationScope.

What is configuration scope ?

Preferences stored in this scope are shared by all workspaces that are launched using a particular configuration of Eclipse plug-ins. On a single-user installation, this serves to capture preferences that are common to all workspaces launched by that user. On a multi-user installation, these preferences are shared by all users of the configuration.

How to save ?

IEclipsePreferences store = ConfigurationScope.INSTANCE.getNode(MyUIPlugin.PLUGIN_ID);
if (store != null)
{
store.putBoolean(MyFLAG_PREF, true);
try
{
store.flush();
}
catch (BackingStoreException e)
{
//Log exception
}
}


How to retrieve the saved preference value?

boolean isSet = Platform.getPreferencesService().getBoolean(MyUIPlugin.PLUGIN_ID,
MyFLAG_PREF, false, new IScopeContext[] { ConfigurationScope.INSTANCE });


Understand more about preference scopes:


Eclipse tips and tricks

Managing eclipse global preferences / eclipse installation level preferences

Where are the global preferences stored for eclipse? 
 eclipse\configuration\.settings folder

Here some plugins store their global preferences. For example: the recent workspace settings are in org.eclipse.ui.ide.prefs.

MAX_RECENT_WORKSPACES=5
RECENT_WORKSPACES=/Users/kondalkolipaka/development/workspaces/devbranch2\n/Users/kondalkolipaka/development/workspaces/devbranch
RECENT_WORKSPACES_PROTOCOL=3
SHOW_WORKSPACE_SELECTION_DIALOG=true
eclipse.preferences.version=1

Same way you can store your plugin global preferences in your own file.

Take a look at this.
http://mcuoneclipse.com/2012/04/06/eclipse-global-preferences/

Tuesday, December 8, 2015

Suppress warnings for non-nls string literals

@SuppressWarnings("nls") suppress warnings relative to non-nls string literals

Example:
@SuppressWarnings("nls")
private static final String[] PLATFORMS = { "iphone", "ipad", "windows", "android" };


Complete list:


The list of tokens that can be used inside a SuppressWarnings annotation is:
  • all to suppress all warnings
  • boxing to suppress warnings relative to boxing/unboxing operations
  • cast to suppress warnings relative to cast operations
  • dep-ann to suppress warnings relative to deprecated annotation
  • deprecation to suppress warnings relative to deprecation
  • fallthrough to suppress warnings relative to missing breaks in switch statements
  • finally to suppress warnings relative to finally block that don't return
  • hiding to suppress warnings relative to locals that hide variable
  • incomplete-switch to suppress warnings relative to missing entries in a switch statement (enum case)
  • javadoc to suppress warnings relative to javadoc warnings
  • nls to suppress warnings relative to non-nls string literals
  • null to suppress warnings relative to null analysis
  • rawtypes to suppress warnings relative to usage of raw types
  • resource to suppress warnings relative to usage of resources of type Closeable
  • restriction to suppress warnings relative to usage of discouraged or forbidden references
  • serial to suppress warnings relative to missing serialVersionUID field for a serializable class
  • static-access to suppress warnings relative to incorrect static access
  • static-method to suppress warnings relative to methods that could be declared as static
  • super to suppress warnings relative to overriding a method without super invocations
  • synthetic-access to suppress warnings relative to unoptimized access from inner classes
  • sync-override to suppress warnings because of missing synchronize when overriding a synchronized method
  • unchecked to suppress warnings relative to unchecked operations
  • unqualified-field-access to suppress warnings relative to field access unqualified
  • unused to suppress warnings relative to unused code and dead code

Sunday, December 6, 2015

Fragments in OSGI - Eclipse


A Bundle fragment, or simply a fragment, is a bundle whose contents are made available to another bundle (the fragment host). Importantly, fragments share the classloader of their parent bundle. One notable difference is that fragments do not participate in the lifecycle of the bundle, and therefore cannot have an Bundle-Activator.


Example:
These are 2 plugins which does not have any activator classes.
org.eclipse.epp.logging.aeri.ui
org.eclipse.epp.logging.aeri.ide - Host Plugin

And, In org.eclipse.epp.logging.aeri.ide plugin MANIFEST.MF file, you can find below section:
Fragment-Host: org.eclipse.epp.logging.aeri.ui;bundle-version="1.0.0"


At runtime the fragment is merged with its host plug-in and for the runtime both projects are just one. Fragments are always optional for their host plug-in and the host plug-in doesn't even know that it exists.

Thursday, December 3, 2015

"No repository found containing: osgi.bundle" error message during the Eclipse udpate

Below trick helped me to resolve the problem.

Help>Install new software>Uncheck "Contact all update sites during install to find required software"

Tuesday, December 1, 2015

How to identify whether you working in development or debug mode in eclipse RCP

Being a eclipse plugin development programmer, we need to perform certain operations based on the mode you working on.

Eclipse provides a way to identify whether your eclipse is running in debug mode or development mode.

if (Platform.inDevelopmentMode()) //it will look for osgi.dev property
{
  //you are running in development mode.
}

if (Platform.inDebugMode()) //it will look for osgi.debug property
{
  //you are running in debug mode.
}


Monday, November 30, 2015

Git stash save with name and re-apply with the name

To save your changes with name "xxx"
git stash save "xxx"

Apply whenever you want it back.
git stash apply stash^{/xxx}


Lot of other solutions @
http://stackoverflow.com/questions/11269256/how-to-name-a-stash-in-git


Thursday, November 26, 2015

Managing node.js with nvm

Managing node.js with nvm

Run below command to install nvm
curl https://raw.githubusercontent.com/creationix/nvm/v0.11.1/install.sh | bash
You'll see some output fly by, and then nvm will be installed. You will see a line that says:
=> Close and reopen your terminal to start using NVM
It's not actually necessary to log out, we just need to make sure that the changes nvm made to your path are actually reflected, so just do:
source ~/.profile
Alternatively, run the command suggested in the output of the script. Now type:
nvm ls-remote
Should you see the error, -bash: nvm: command not found it may be because git is not installed.
Go ahead and install git and rerun the script:
apt-get install git
And you will be shown a list of all the available versions of node.js. You can always find out the latest stable release by heading to the node.js website, where it's printed in the center of the page.
To install version 0.10.13 (the latest as of this writing) type:
nvm install 0.10.13
If you type:
node --version
You will now see that node v0.10.13 is installed and active. If you had an older node app that only works with node v0.8.16, and wanted to downgrade, then you would input:
nvm install v0.8.16
to install and switch to v0.8.16.
When you're done and want to switch back to v0.10.13, you can do so with nvm's use command:
nvm use v0.10.13
Nvm is great and makes switching between node versions easy and convenient. However, there's one caveat. If you type:
which node
you will see something interesting. Nvm installs node.js inside your user's home directory. This is fine for development, but if you want to actually host node applications, you don't want to install the latest new version of node via nvm and discover that you've inadvertently caused your production node app (which can be incompatible with the latest node.js) to stop working. It's best to install one copy of node globally so that other users can access it, and use nvm to switch between your development versions.
To do this, run the following command (entering your user's password at the prompt):
n=$(which node);n=${n%/bin/node}; chmod -R 755 $n/bin/*; sudo cp -r $n/{bin,lib,share} /usr/local
The above command is a bit complicated, but all it's doing is copying whatever version of node you have active via nvm into the /usr/local/ directory (where user installed global files should live on a linux VPS) and setting the permissions so that all users can access them.
If you ever want to change the version of node that's installed system wide, just do another nvm use vXX.XX.XX to switch your user's node to the version you want, and then re-run the above command to copy it to the system directory. 
To check that it works, become the root user and do another which command to make sure that node is now installed to /usr/local/bin:
sudo -s
which node
You should see:
/usr/local/bin/node
Congrats! Node.js is now installed and ready for use. Enjoy!
UPDATE:
Use below to change the default version for a shell.
nvm alias default 0.12.7

Thursday, November 19, 2015

How to control eclipse Java formatter on or off

This you can be controlled from Eclipse preferences.

Eclipse preferences: Java > Code Style > Formatter. Click on "Edit" button, "Off/On Tags", check off "Enable Off/On tags".

How to use in the code:
// @formatter:off
...your code here won't be formatted
// @formatter:on




How to listen to Eclipse Log errors

Register a listener in your Core Plugin startup:

Platform.addLogListener(new MyLogListener());

Listen to the log:

import org.eclipse.core.runtime.ILogListener;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;

public class MyLogListener implements ILogListener
{

@Override
public void logging(IStatus status, String plugin)
{
if (status.getCode() == IStatus.ERROR)
{
startJob(status);
}
}

private void startJob(final IStatus status)
{
Job job = new Job("Reporting error...")
{
@Override
protected IStatus run(IProgressMonitor monitor)
{
System.out.println("===============Studio error reporting starts==============");
String ticketMessage = status.getMessage();
System.out.println(ticketMessage);
Throwable exception = status.getException();
exception.printStackTrace();
 System.out.println("===============Studio error reporting ends==============");
return null;
}
};
job.schedule();
}

}

Tuesday, November 17, 2015

Semantic Versioning

http://semver.org

Given a version number MAJOR.MINOR.PATCH, increment the:
  1. MAJOR version when you make incompatible API changes,
  2. MINOR version when you add functionality in a backwards-compatible manner, and
  3. PATCH version when you make backwards-compatible bug fixes.
Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format.



Wednesday, November 11, 2015

How to change the default console output buffer size in Eclipse

Eclipse User:

In Window > Preferences > Run/Debug > Console there's a checkbox "Limit console output" and a textfield for entering the buffer size of the console. However, you can increase it up to 1000000

Eclipse Plugin Development:

To uncheck the console output limit:
IPreferenceStore store = DebugUIPlugin.getDefault().getPreferenceStore();
store.setDefault(IDebugPreferenceConstants.CONSOLE_LIMIT_CONSOLE_OUTPUT, false);
To change only the buffer limit:
store.setDefault(IDebugPreferenceConstants.CONSOLE_LOW_WATER_MARK, 500000);

Wednesday, October 21, 2015

How to merge the changes from your development branch to master/release branch

$ git checkout development
$ git merge -s ours release  //merge release into development and discard any changes on release branch
$ git checkout release
 $git merge development

Note: Very important point here is, we are completely discarding the changes which are made in release branch. Here we will just bring all the changes from development branch to release branch without having conflicts. If any conflicts during the merge it will take development changes and ignore the release changes if any.

This merge strategy can be used ONLY when you are sure that release branch does not have any additional git commits compared to development branch. 

If release branch is having specific commits and which are not there in development branch, then it's better to go always with the default merge strategy.

$ git checkout release
$ git merge development

Resolve any conflicts if any and commit it.






Monday, October 12, 2015

How to find the product code for the installed MSI file in windows

Run below command from power shell to see.

PS C:\Users\Admin> get-wmiobject -class Win32_Product


IdentifyingNumber : {32A3A4F4-B792-11D6-A78A-00B0D0170400}
Name              : Java SE Development Kit 7 Update 40
Vendor            : Oracle
Version           : 1.7.0.400
Caption           : Java SE Development Kit 7 Update 40

IdentifyingNumber : {32A3A4F4-B792-11D6-A78A-00B0D0170760}
Name              : Java SE Development Kit 7 Update 76
Vendor            : Oracle
Version           : 1.7.0.760
Caption           : Java SE Development Kit 7 Update 76

IdentifyingNumber : {32A3A4F4-B792-11D6-A78A-00B0D0170800}
Name              : Java SE Development Kit 7 Update 80
Vendor            : Oracle
Version           : 1.7.0.800
Caption           : Java SE Development Kit 7 Update 80

IdentifyingNumber : {64A3A4F4-B792-11D6-A78A-00B0D0170400}
Name              : Java SE Development Kit 7 Update 40 (64-bit)
Vendor            : Oracle
Version           : 1.7.0.400
Caption           : Java SE Development Kit 7 Update 40 (64-bit)

IdentifyingNumber : {64A3A4F4-B792-11D6-A78A-00B0D0170800}
Name              : Java SE Development Kit 7 Update 80 (64-bit)
Vendor            : Oracle
Version           : 1.7.0.800
Caption           : Java SE Development Kit 7 Update 80 (64-bit)


IdentifyingNumber  number represents the product code.

Sunday, September 13, 2015

How can I pass arguments to an extension point constructor/ createExecutableExtension with parameters in eclipse

Please also refer to my previous post.
http://exploreeclipse.blogspot.in/2015/09/reading-extension-point-from-eclipse.html


public void readExtensionPoint(String myjsonString) {
IExtensionRegistry registry = Platform.getExtensionRegistry();
IConfigurationElement[] elements = registry.getConfigurationElementsFor("com.kk.myplugin", "services");
for (IConfigurationElement iConfigurationElement : elements)
{
iConfigurationElement.getAttribute("service_id");
iConfigurationElement.getAttribute("name");
try
{
try
{
String attribute = iConfigurationElement.getAttribute("class");
String contributorName = iConfigurationElement.getDeclaringExtension().getContributor().getName();
Class<?> javaClass = Platform.getBundle(contributorName).loadClass(attribute);
Constructor<?> ctor = javaClass.getDeclaredConstructor(String.class);
IService service = (IService) ctor.newInstance(myjsonString);
return service;
}
catch (Exception e)
{
}
}
catch (CoreException e)
{
e.printStackTrace();
}
}


}

Reading an extension point from eclipse plugin

public void readExtensionPoint() {
IExtensionRegistry registry = Platform.getExtensionRegistry();
IConfigurationElement[] elements = registry.getConfigurationElementsFor("com.kk.core", "platformServices");
for (IConfigurationElement iConfigurationElement : elements)
{
iConfigurationElement.getAttribute("id");
try
{
//This is your class
Object createExecutableExtension = iConfigurationElement.createExecutableExtension("class");
}
catch (CoreException e)
{
e.printStackTrace();
}
}

}


Here is my extension point schema definition:

<?xml version='1.0' encoding='UTF-8'?>
<!-- Schema file written by PDE -->
<schema targetNamespace="com.kk.core" xmlns="http://www.w3.org/2001/XMLSchema">
<annotation>
      <appinfo>
         <meta.schema plugin="com.kk.core" id="platformServices" name="platformServices"/>
      </appinfo>
      <documentation>
         [Enter description of this extension point.]
      </documentation>
   </annotation>

   <element name="extension">
      <annotation>
         <appinfo>
            <meta.element />
         </appinfo>
      </annotation>
      <complexType>
         <sequence minOccurs="1" maxOccurs="unbounded">
            <element ref="service"/>
         </sequence>
         <attribute name="point" type="string" use="required">
            <annotation>
               <documentation>
                  
               </documentation>
            </annotation>
         </attribute>
         <attribute name="id" type="string">
            <annotation>
               <documentation>
                  
               </documentation>
            </annotation>
         </attribute>
         <attribute name="name" type="string">
            <annotation>
               <documentation>
                  
               </documentation>
               <appinfo>
                  <meta.attribute translatable="true"/>
               </appinfo>
            </annotation>
         </attribute>
      </complexType>
   </element>

   <element name="service">
      <complexType>
         <attribute name="id" type="string" use="required">
            <annotation>
               <documentation>
                  
               </documentation>
            </annotation>
         </attribute>
         <attribute name="class" type="string" use="required">
            <annotation>
               <documentation>
                  
               </documentation>
               <appinfo>
                  <meta.attribute kind="java" basedOn="com.kk.core.services.Service:com.kk.core.services.IService"/>
               </appinfo>
            </annotation>
         </attribute>
      </complexType>
   </element>

   <annotation>
      <appinfo>
         <meta.section type="since"/>
      </appinfo>
      <documentation>
         [Enter the first release in which this extension point appears.]
      </documentation>
   </annotation>

   <annotation>
      <appinfo>
         <meta.section type="examples"/>
      </appinfo>
      <documentation>
         [Enter extension point usage example here.]
      </documentation>
   </annotation>

   <annotation>
      <appinfo>
         <meta.section type="apiinfo"/>
      </appinfo>
      <documentation>
         [Enter API information here.]
      </documentation>
   </annotation>

   <annotation>
      <appinfo>
         <meta.section type="implementation"/>
      </appinfo>
      <documentation>
         [Enter information about supplied implementation of this extension point.]
      </documentation>
   </annotation>


</schema>


Extension:
   <extension
         id="com.kk.core.platform.services"
         name="KK Platform Services"
         point="com.core.platformServices">
      <service
            class="com.kk.core.services.CheckService"
            id="xx34567vvk">
      </service>
     
   </extension>

Sunday, September 6, 2015

Storing in eclipse secure storage with encryption

ISecurePreferences root = SecurePreferencesFactory.getDefault();
ISecurePreferences node = root.node("/com/kk/store"); //path

//store
try
{
node.put("myusername", "mysecretpassword", true);
}
catch (StorageException e)
{
e.printStackTrace();

}

Where does Eclipse secure storage file is saved ?

This you can find from Eclipse preferences.
Eclipse -> Preferences -> General -> Security -> Secure Storage -> Contents Tab

Here you can find 'Storage Location'.

Example:
/Users/kkolipaka/.eclipse/org.eclipse.equinox.security/secure_storage



How to get the Eclipse Installation location ?

Eclipse provided a direct API call for this.

Platform.getInstallLocation().getURL();

To get a string path:

Platform.getInstallLocation().getURL().getPath();

Wednesday, September 2, 2015

Undo a git rebase

Step 1: Identify the head commit of the branch till where you wanted to undo it.

$ git reflog
5621e87 HEAD@{0}: checkout: moving from TISTUD-7562 to development
7747926 HEAD@{1}: rebase -i (finish): returning to refs/heads/TISTUD-7562
7747926 HEAD@{2}: rebase -i (squash): TISTUD-7562:For limited plan billing is not opened via wizard
2101ed5 HEAD@{3}: rebase -i (start): checkout 5621e87fac883fca1783bb2f1b6f811422bdf289
0975830 HEAD@{4}: rebase: aborting
0975830 HEAD@{5}: reset: moving to HEAD@{1}
2101ed5 HEAD@{6}: rebase -i (start): checkout 5621e87fac883fca1783bb2f1b6f811422bdf289
0975830 HEAD@{7}: commit: TISTUD-7562:Avoiding multiple validations during the package launch actions from package explorer and app explorer.
2101ed5 HEAD@{8}: rebase finished: returning to refs/heads/TISTUD-7562
2101ed5 HEAD@{9}: rebase: TISTUD-7562:For limited plan billing is not opened via wizard


Here, I wanted to undo till HEAD@{7}

Step 2: Reset to required commit

git reset --hard HEAD@{7}

This will bring back all the changes which you are having at HEAD@{7} commit.