search question mark in excel (?)

tried to search for the question mark in Excel but it is treated as a wildcard instead.

Found that the escape char in Excel is ~. Which means “~?” to find a question mark, and “~~” to find a tilde.

http://support.microsoft.com/?kbid=214138

Comments

abc.getXyz()

Why is it not good to keep using “abc.getXyz()” in the same method?

1. This is especially important if you are expecting the same value to be returned for each call. A 2nd call can potentially give you a different result from the first, therefore caching it in a local variable is a good idea.

2. The call may be expensive. Each call may be going through a web service to query a database for the return value. If you save it in a local variable it will only be done once. Even if you “know” that it doesn’t now, you should expect polymorphism.

Comments

Reflecting outer class

Given an inner class object, how do you use reflection to obtain a reference to the outer class? this$0.


  Field parent = inner.getClass().getDeclaredField("this$0");
  parent.setAccessible(true);
  Object outer = parent.get(inner);

If it is a nested inner class, increment the 0.

Comments

Track memory usage in QTP with WMI

I used QTP to simulate a repeating user scenario in order to trace a memory leak with YourKit over time. So I’m using this quick & dirty function to poll the application regularly about it’s raw memory usage.


Function GetMemory
	pid = GetWindow().GetROProperty("process id")
	Set wmiService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
	Set resultset = wmiService.ExecQuery("SELECT WorkingSetSize FROM Win32_Process WHERE Handle=" & pid)
	For Each result In resultset
		GetMemory = Int(result.WorkingSetSize)
	Next
End Function

GetWindow() returns a reference to the application window.

It seems even though I SELECT only WorkingSetSize I could get other information such as Handle from the result.

The For Each loop was an easy way out since I didn’t know how to access the first element.

Reference: http://www.learnqtp.com/windows-management-instrumentation-wmi-qtp/

Comments

jedit: Find and Replace

jedit’s Find and Replace feature supports regular expression with capturing groups, so you can match a regular expression in the Find field and use $1 $2 in the Replace field. Together with is “Directory” option you can manipulate file content easily.

Comments