Ultra Useful Regular Expression


# urlify - turn URL's into HTML links
my $text = "Check the website, http://www.oreilly.com/catalog/repr.";
$text =~ 
	s{
		b			# start at word boundary
		(			# capture to $1
		(https?|telnet|gopher|file|wais|ftp) :
					# resource and colon
		[w/#~:.?+=&%@!-] +?	# one or more valid
					# characters
					# but take as little as
					# possible
		)
		(?=			# lookahead
			[.:?-] *	# for possible punct
			(?: [^w/#~:.?+=&%@!-]	# invalid character
			  | $ )		# or end of string
		)
	}{<a href="$1">link</a>}igox;

What is Highway Safety?

Here’s a picture of my Toyota ’95 Pickup. About two weeks after buying it, a rock quary truck dropped a rock the size of a football in front of me on highway 522 (55 MPH == 110 MPH football sized rock) outside Monroe, effectively taking my Toyota logo with it. And seizing my hood shut. Luckily it stopped before it took out my radiator. Luckily no major damage to me!

TagCMA (latest)

In the last July & August I have been rewriting TagML in C#, along with adding a ton of new features. This new version incorporates collaboritive modeling. Which means multiple users will be able to animate a scene of models at the same time. I envision a rag doll, in which several persons each have hold of a different body part. Similar to stop-watch animation, each user can place the head, arms, body, and feet into the desired position for each frame in real-time. Which should cut down in animation time, theoretically.
Tag Applied Collaborative Modeling Application (TagCMA)
(C) Timothy A. Graupmann

Convert MAKEINTRESOURCE to C#

Ran into a small issue. There’s a C++ Macro called MAKEINTRESOURCE that is used heavily in Win32 programming. I’d be very interested in knowing if anyone has ported the macro to C#. Here is an [Article] that explains the problem in detail.

Actually the problem is simplier than I thought. Anything that uses MAKEINTRESOURCE, just pass a UInt16 in the field instead of a LPSTR and it works just fine.

Marshaling Data Types With Platform Invoke in C#

This is worth studying for you game designers/programmers. With DotNet and CSharp a lot of you are going the Windows.Forms route. I just wanted to present to you an alternative. The grunt work is done, so all you need to do is include the CSharp*.cs files and you are ready to go.

For fun I ported “GameTutorials Triangle(First OpenGL Program” to C# using
Win32. It keeps the existing framework of the original tutorial without using
Windows Forms. Take a look. This will safe others time that might want to
program OpenGL with Win32 calls in C#.

Tutorial: “[Triangle – My First OpenGL Program in C#]”

Update: Full Screen Mode now Works. Default Icon is now working. Figured out the MAKEINTRESOURCE problem. Some things that don’t work perfectly yet are commented out. For example, a memory leak that happens during painting. Anyone is welcome to email bugs or fixes.

I should note that I used the OpenGL ports from Nehe, but all the Win32 ports
are mainly from me. I used Pinvoke as a reference and found several answers in forums that blurred by.

[MSDN] Great mapping table between unmanaged types to C#.
Another great resource: [Pinvoke.net]

Creating .NET Web Clients with Mono

If you are not familar with Web References or created web clients that connect to Web Services, here are detailed step by step screenshots (8 in all) that will get you up to speed. You may have Visual Studio .NET or Visual Studio .NET 2003 or Mono MCS. And with these steps you can get a web service up and running at least on Win2k, WinXP, or Win2003. See story for details…
To start we just need a basic C# Console App. Go into Visual Studio .NET. Click [File] – > [New] -> [Project]. Click [Project Types] -> [Visual C# Projects]. Click [Console Application]. The location can be anywhere on your harddrive, so pick a suitable location. The project name will default to ConsoleApplication1. Then click OK.

From the basic Console App, right-click the project name [ConsoleApplication1] and select [Add Web Reference]. This will initiate the Web Reference dialog.

Enter the URL to the Web Service you plan to connect to. This is the same location from the previous [Web Service Tutorial]. Click [Add Web Reference] and this will add the appropriate source files to the project.

Finishing the [Add Web Service Dialog] added the web reference files to the project as you see here. The WSDL file is what I think the coolest part of Web Services & Web References. The file not only defines what each of the method names are in the Web Service, it defines the type of each argument. So if you code ever gets out of sync with the WSDL, this file will tell the compiler about it.

At some point you may decide to change the Web Service method parameters or even add new methods. If you do, you need to update the Web Reference which will automatically get the new changes. If the changes are serious, you will get compile errors which detect that either the method name changed, the number of method arguments changed, or the parameter types changed. If these were just WebRequests you might have never know that changes occurred. Thanks to Web Services, you’ll know right away.

Open the Class1.cs source file. Web References are accessed in an object oriented way. You have to declare them as an object and the initial connection is created by using new. The web service method is invoked here by using objService1.HelloWorld(). The neat part here is that the method is strongly typed. So if you try and pass the wrong parameters, the application won’t even compile. This makes web development really simple. You can use any parameters you like, I just used the default void parameters to make this example simple. The HelloWorld() method returns a String which Console.WriteLine happily outputs to the Console screen.

Hey look! Upon running the application we see “Hello World” which is the String that was returned by the HelloWorld method of WebService1. This may run and close so fast that you need to run from a console. In this example we used a console app. Web References can be used in all the project types. You can even have Web Services that also use Web References to get their data. Although as always, the more layers you add, the slower the app might function. So keep it in mind.

You can download the [project files] associated with this tutorial. Included in the project files is a script called CompileWithMono.cmd which depends on you having Mono installed. If you don’t have Visual Studio .NET you will need to compile with the Mono script.