Saturday, April 16, 2011

Ubuntu Tip - "The password you use to login to your computer no longer matches that of your login keyring”

I've recently come  to use one of the applications in ubuntu that requires access to the keyring.
“Enter password to unlock your login keyring. The password you use to login to your computer no longer matches that of your login keyring”This issue can be solved in two ways:
- If you know the password he asks for:
You can change he asks to match the same password you use to login by making the following steps:
  1. Go to Applications -> Accessories -> Passwords and Encryption Keys.
  2. Right click Passwords:login
  3. Select "Change Password"
  4. Type in your old password and your new password twice to confirm (match it to your logon password of course) 
  5. Hit "OK".
- If you don't know the password he asks for:
The fix is to remove the file which store the password in. The file is located at “~/.gnome2/keyrings/default.keyring”. the "default" can have another name depends on which file is looking for.

What is the Keyring?
 Now let's take a look about the keyring. Keyring is like the password manager of firefox. It stores all the passwords for you without the need to remember & type the passwords each time you use it like the wireless password, mail accounts, FTP account .. etc

Monday, March 28, 2011

SVN Tips – Ignore file or directory in Subversion (eclipse)

Windows_Live_Sync_logo

Usually when we deal with the subversion we want to ignore specific files or directories from committing. These files may depend on local paths.

Common files are ignored:

.class files and SVN related files .

Maven as example

maven usually have the following project structure:

image

Committing the target folder will always generate conflicts when committing, so we should ignore this folder in SVN here’s how:

From eclipse window menu –> Preferences, then from the right menu Team –> Ignored Resources as shown below:

image

then choose add Pattern and enter “target”

Conclusion

Working with SVN could raise some issues with having some files created only for local testing, so ignoring these files will handle this issue.

Thursday, October 28, 2010

Eclipse tips - Conditional Breakpoints

The traditional waydebug_educational_software_510925

Sometimes in debugging we want to trace the code at a breakpoint under certain conditions, so what we do is every time this breakpoint is hit we check manually if this the case we want to trace or not.
 

Eclipse way !

Eclipse has a neat feature called conditional breakpoint. This feature enables you to enable the breakpoint if certain conditions is met. Now each time the breakpoint is reached, the expression is evaluated in the context of the breakpoint execution, and the breakpoint is either ignored or honored.

Example

Suppose we have this sample code
   1:  public static void initialize() 
   2:  {
   3:      final List activities = getActivities();
   4:   
   5:     for (Iterator i = activities.iterator(); i.hasNext();) 
   6:     {
   7:        final NestedActivity nestedActivity=(NestedActivity) i.next();
   8:        final SmallActivities[] smallActivities=nestedActivity.
   9:                                getSmallActivities();
  10:   
  11:        doSomething(nestedActivity, smallActivities);
  12:     }
  13:  }



And we want to put a conditional breakpoint at line 11 before executing the doSomething(..) method to trace a nestedActivity called debugging, so here is what we do:

  • Create breakpoint at line
  • Right click at the breakpiont then breakpoint properties
  • The properties of the breakpoint window will open
image
  • Check Enable condition
  • Write In the Condition field the expression for the breakpoint condition (notice the code assistant)
  • Do one of the following:
    • If you want the breakpoint to stop every time the condition evaluates to true, select the condition is 'true' option.  The expression provided must be a Boolean expression.
    • If you want the breakpoint to stop only when the result of the condition changes, select the value of condition changes option.

Saturday, October 16, 2010

The code is breathing - ep1

2003-06-17

Test Coverage tools (Cobertura)

The test coverage tools are used to ensure that all code paths are tested. It calculates the percentage of code called by tests. It also gives reports of which parts aren’t tested.

Cobertura – Hello World

As an example we will take the Cobertura as an example. As it’s free, open source and integrated with JUnit and Ant.

Installing Cobertura

Running the example that comes with it

  • It came with an example of simple calculator that square and sum numbers
  • In order to run the example you should install the JUnit & Ant & add their values in the classpath and path
  • open the example’s directory from the command line and enter ant
  • Now all the magic happens!! it compiles, run the tests and generate the reports

Now let’s take a look at the reports

image

It shows the percentage of overall the packages and for each class alone. The best thing is yet to come. By clicking on the class name it shows the class code and highlight the path which didn’t get accessed by the test cases in red and which get accessed in green. It also shows a number beside it which shows how many times this line is executed by the test cases.

image

How it works?

  • The cobertura generate for each class an instrumented version of it which has instructions
  • These instrumented version is added to the compile code
  • Instead of running the normal compiled code, you run the instrumented version
  • When these instructions are encountered by the Java Virtual Machine, the inserted code increments various counters so that it is possible to tell which instructions have been encountered and which have not.

Saturday, June 26, 2010

Chapter 2: Deadly Diamond of Death (Multiple inheritance)

there is a question I used to hear a lot especially in the interviews: Why Java doesn't support multi-inheritance?

And the answer for this question is that multi-inheritance have some issues the compiler needs to deal with. One of them is Deadly Diamond of Death. If u look to the following diagram.

7c47d9f8-b09c-4cdf-8568-ee7bb689100d

There is two problems in this situation:


1- class D inherit function f implementation 2 times. So which implementation of function f does inherit? In C++ u have to override this function to solve this problem.

2- Class A have member variable i since B & C inherit from A so there's ambiguity. we may want this variable to be separated that means creating two copies of A in D or if we want one copy so we have to to use the virtual inheritance.

==> that's two reasons was enough for java designers to avoid the multi-inheritance in their design.

extracted from what I understand from: http://www.objectmentor.com/resources/articles/javacpp.pdf