Friday, March 20, 2009

MSIL : Running MSIL code inside Visual Studio

Using Visual Studio 2005.

Project Create - choose Visual C++ and then "Makefile Project".

This simple example will add two numbers so call the project AddTwoNum.

This bring up a wizard.

Click "Next". For Debug settings, in the "Build Command Line" type:

build.bat

Then click "Finish".

In the Solution Explorer, delete "readme.txt".

Add a text file called "Build.bat" to the project.

It contains:

ilasm /nologo /debug AddTwoNum.il


(ilasm is the command line MSIL assembler).

Add a text file called "AddTwoNum.il" to the project.

It contains:

.assembly AddTwoNum {}

.method static public void main() il managed
{
.entrypoint

.maxstack 10

.locals init (int32 firstNum,
int32 secondNum,
int32 resultNum)

ldc.i4 11
stloc firstNum
ldc.i4 22
stloc secondNum
ldloc firstNum
ldloc secondNum
add
stloc resultNum

ldstr "{0} + {1} = {2}"

ldloc firstNum
box int32

ldloc secondNum
box int32

ldloc resultNum
box int32

call void [mscorlib]System.Console::WriteLine(string, object, object, object)

// This bit just waits for a key to keep the command line prompt open

ldstr "Press Enter to continue"
call void [mscorlib]System.Console::WriteLine(class System.String)

// Call the System.Console.Read function
call int32 [mscorlib]System.Console::Read()

// The pop instruction removes the top element from the stack.
// (remove number returned by Read() function)
pop

ret
}


Now press "F6". Project should assemble cleanly.

Press "F5" to run it.

Answer "Yes" to "The project is out of date - Rebuild?"

Command prompt will display:


11 + 22 = 33
Press Enter to continue


You can set breakpoints in the normal way, step through the code in the usual way and the "Locals" debug window will display the values of the three variables.

Enjoy!

Monday, March 16, 2009

Java : Checking version on your PC

Came across a nice feature that does this from the Sun web site.

Verify Java installation

If your installation is out-of-date, just click on the link and the latest one is installed.

Very handy!

Enjoy!

Thursday, March 12, 2009

XP : TortoiseSVN and Explorer

We've moved from VSS to Subversion and I downloaded TortoiseSVN as my Windows client.
Every time I right-clicked on a folder, I get"

"Windows Explorer has encountered a problem and has to close"

Mr. Google to the rescue - took me a while - but eventually I discovered that the problem was with PowerDesk which I rarely use anymore.

So I uninstalled it and now all is well!

Enjoy!

Misc : A good day on Stackoverflow



Check this out.

100 rep - 3 badges - heck, I can live with that.

Enjoy!

Friday, March 06, 2009

Misc : Google Sites

OK - have a home page on Google Sites:

Home page

Enjoy!

Misc : Top Google search result





Searching Google for "DOS grep equivalent" shows "Random thoughts and collisions" is the top dog!

It's 1 out of about 62,000.

Check it out by double-clicking on the image above.

Enjoy!

Wednesday, February 25, 2009

Misc : Setting up and adding your gravatar

What is a gravatar? As per the site, "A gravatar, or globally recognized avatar, is quite simply an image that follows you from site to site appearing beside your name when you do things".

As per Wikipedia, "A Gravatar avatar can be up to 512 pixels wide, is always square and is displayed at 80 by 80 pixels by default. If the uploaded avatar is larger or smaller, the avatar is scaled appropriately".

I wanted to add one to Stack Overflow.

So I searched Google Images for a small image and saved it to my hard drive as a .jpg.

Then I used the ubiquitous Paint to open it. Under "Image / Attributes", it showed as:

Width = 60, Height = 40.

To keep it square, I needed to make the width 40. Simple maths shows that I needed it to be reduced by a third. So "Image / Stretch/Skew" and type 67 (i.e. 67 %) into the "Horizontal" box for "Stretch".

Another "Image / Attributes" showed it was pretty much as required. Save on the hard drive.

So logon to Gravatar. "My Account / Manage" Click "Add a new image". Browse to where the file was saved, select the file, crop as appropriate (I just dragged the box to fit the image), select the content type (hopefully it's "G"!) and you're done.

Now any site that uses gravatars will display your new image.

Enjoy!

Monday, February 16, 2009

XP : DOS equivalent of Traceroute

I've used Traceroute often to trace the path between two hosts and highlight potential bottlenecks.

But it is not a Windows program. However, "PathPing" is a network utility in XP.

"It combines the functionality of Ping with that of Traceroute (in Windows: tracert), by providing details of the path between two hosts and Ping-like statistics for each node in the path based on samples taken over a time period".


C:\>pathping

Usage: pathping [-g host-list] [-h maximum_hops] [-i address] [-n]
[-p period] [-q num_queries] [-w timeout] [-P] [-R] [-T]
[-4] [-6] target_name

Options:
-g host-list Loose source route along host-list.
-h maximum_hops Maximum number of hops to search for target.
-i address Use the specified source address.
-n Do not resolve addresses to hostnames.
-p period Wait period milliseconds between pings.
-q num_queries Number of queries per hop.
-w timeout Wait timeout milliseconds for each reply.
-P Test for RSVP PATH connectivity.
-R Test if each hop is RSVP aware.
-T Test connectivity to each hop with Layer-2 priority tags.
-4 Force using IPv4.
-6 Force using IPv6.


Or (as above), use tracert.


C:\>tracert

Usage: tracert [-d] [-h maximum_hops] [-j host-list] [-w timeout] target_name

Options:
-d Do not resolve addresses to hostnames.
-h maximum_hops Maximum number of hops to search for target.
-j host-list Loose source route along host-list.
-w timeout Wait timeout milliseconds for each reply.


Enjoy!

Friday, January 30, 2009

C# : Removing non-ASCII characters

I was trying to filter some files and remove all the non-ASCII characters. Using Mr. Google lead me to this very helpful
post.

Essentially:


string s = "søme string";
s = Regex.Replace(s, @"[^\u0000-\u007F]", "");


I didn't want control characters so my filter was \u0020-\u007F.

Enjoy!

Thursday, December 04, 2008

Java : Axis2 client and Log4J

I was busy testing a client developed using the Eclipse plug-ins in the previous post.

This came up with the following error message.

log4j:WARN No appenders could be found for logger (org.apache.axis2.description.AxisService).
log4j:WARN Please initialize the log4j system properly.

To set this up inside an Eclipse project:

* Create a new folder in the project called e.g. "log4j".
* Add a file to that folder called log4j.properties which contains something like:


# Set root category priority to INFO and set its only appender to A1
log4j.rootCategory=INFO, A1

# A1 is set to be a ConsoleAppender (writes to system console).
log4j.appender.A1=org.apache.log4j.ConsoleAppender

# A1 uses PatternLayout.
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n


* In the project's "Run Dialog", click on the "Classpath" tab / "Advanced" / "Add folder" and then browse to the "log4j" folder previously created.
* That's it

Enjoy!

Java : Tomcat / Eclipse and Axis2

I needed to develop a Java web service that ran inside Tomcat and used Axis2 as the web server component.

I use Eclipse as my Java IDE and was looking around for plug-ins that would automate and simplify the whole process.

Came across this excellent tutorial - Developing Web Services Using Apache Axis2 Eclipse Plugins - Part 1

This uses two Eclipse plug-ins:

Apache Axis2 Service Archive Generator Wizard and
Apache Axis2 Code Generator Wizard

which generate the proxies and then wrap everything up for deployment to Tomcat.

I highly recommend working through the tutorial and then using that knowledge to develop and deploy your own.

Enjoy!

Java : Finding jars and classes

I seem to spend half my life looking for jars and classes to solve the ubiquitous "Class not defined" problem.

Found this very useful resource which allows you to find which jar files contain the required class and then download them if needed.

Enjoy!