Archive for the ‘Programming’ Category

I’ve been trying out various ways of intracting with Windows Services from C# code. From what I’ve seen, basically you have the following methods:

  • WMI Queries via classes in the System.Management namespace,
  • Strongly-typed WMI proxy classes generated using MgmtClassGen.exe, and
  • The System.ServiceProcess.ServiceController class.

Keep reading »

If you are getting a 0x80070005 COM exception (or UnauthorizedAccessException in C#) while attempting a remote WMI connection to a Windows XP host, even though you are connecting as an admin user in the remote host and you are providing the correct username and password, you may wish to check if ForceGuest is enabled on that host. It is enabled by default.

In C# it happens when you call the Connect() method of the ManagementScope object.

Set the value of the forceguest key to 0 in the following registry location:

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa

This should fix the problem.

Drag-n-Drop with HTML Canvas

Sunday, 24th April 2011 by

This example shows how to implement drag-&-drop in a HTML Canvas using javascript. It’s done using plain old Javascript, i.e. without using any libraries like JQuery or moo-tools etc.

The main pitfall to look out for is any scaling done as a result of CSS sizing. The actual width and height of any visual element as calculated by the browser is a combination of all styles that match the element, and as such it may differ from the size specified in the html attribute, as well as to that of any single CSS definition. You should get this in JavaScript using the offsetWidth, and offsetHeight properties of the object.

Anyway, here is the code for the example …

HTML

<canvas id="canvas" width="400" height="300"></canvas>
<div id="status"></div>

Keep reading »

If you are loading scripts from a number of 3rd party sources, such as Google Analytics, Ads, Twitter, Buzz, and Facebook etc., your page load-time can go through the roof. You can get around these by adding them to the document ready event handler. But the problem is, you may want to run some scripts once the remote script has successfully loaded. For scripts hosted in your domain you can use AJAX, but unfortunately there isn’t general way of doing this for scripts on a different domain.

Some of these third parties, however, trigger ready events for their script when it has completely loaded. Facebook has such a feature for their all.js script. Let’s take a look at how to use it. We’ll use jQuery to defer the script loading.

The event triggered by the all.js script is called fbAsyncInit, and it is attached to the window object. We’ll need to add a handler for this event:
window.fbAsyncInit = function() { alert('Facebook script loaded!'); };

And then we simply have the jQuery $(document).ready event load the Facebook script:
var fbscript = document.createElement('script');
fbscript.type = 'text/javascript';
fbscript.src = 'http://connect.facebook.net/en_US/all.js#xfbml=1';
document.getElementsByTagName('head')[0].appendChild(fbscript);

Now what happens is that, when the page has completed loading the second code block adds a reference to the facebook script, which gets loaded and starts executing. When it is done, it triggers the function we added in the first code block. Of course, you can replace that with something more usefull than a message saying it’s loaded! Or, you can get rid of it all together if you are just interested in the deferred load, and do not need to execute anything after the script has loaded.

WordPress has a tendency to sprinkle an abundance of p tags in your blog posts wherever you have lots of spaces between paragraphs. In most cases it is exactly what you want. You want the paragraph spacing to be nice and consistent. But there are times it works against you. I tend to put all code extracts in my blog posts in code tags. I use css to style any code that should be a block. The problem is code tends to have consecutive line breaks. Wodpress goes and separates the codeblock where it finds more than one line-break and wraps them in a p element.

So, what do you do? Well, the solution is the wp-includes/formatting.php in a function called wpautop(). Apart from finding a whole bunch of pee jokes in this function (with variable names like pee and tinkle), you will see that it cleans up line breaks and replaces a lot of them with P tags. You will also see that pre tags are treated specially.
Keep reading »

Android SDK, Windows 7, and Java

Sunday, 12th December 2010 by

When you’re installing Android SDK (on Windows 7 64-bit – perhaps on other versions too?), it can’t seem to find your JDK installation. When you click next on the first screen, it will present you with a screen saying Java SE Development Kit (JDK) not found.

When that happens, just click back, and then click next. Lo and behold … it’s found Java now! :D

Setting up a subversion server

Sunday, 11th July 2010 by

In this article we’ll set up a subversion server that will allow remote access. We will use Ubuntu, but the process isn’t that different if you are using a different distro.

First of all install the subversion package. In ubuntu thats:

sudo apt-get install subversion

Create a directory where you will store the subversion repositories. (we use /var/repos in this example.) Then, add a user for the svn (we’ll use the username svn), and give it ownership of the repos directory.
Keep reading »

Web development tools

Saturday, 12th July 2008 by

I’m putting up all tools and scriptlets I make for helping me with web developmet up in the Lab section of my site.

Check ‘em out. You might find them helpful.

Javaworld has an interesting article on using OpenOffice as the server for a web based spreadsheet like Google Spreadsheets. They use servlets running on Tomcat to communicate with OpenOffice.org, while using Dojo for the web tier.

It handles all the standard spreadsheet functions, but I’m thinking this could be a very useful resource for people needing web based mathematical/statistical applications. It appears you can integrate it with a Java/J2EE application with a little effort, saving you from reinventing the wheel.

Links:
http://www.javaworld.com/javaworld/jw-05-2008/jw-05-spreadsheets.html

Minimum and Maximum widths in IE6 CSS

Tuesday, 19th February 2008 by

In a previous article I showed you how easy it is to create a constrained fluid layout i.e. one with a minimum and maximum widths. While this works on all standards compliant browsers, it doesn’t work in Internet Explorer 6. Keep reading »