Slave Hack Companion… Open Source?

As some of you have seen, there have been a couple of requests that I release the source code for my little Slave Hack Companion project. This is just a quick shout out to see who would be interested in contributing if I started a sourceforge project page for it and released the source code?  It’s only small and could use a few updates but I havnt had time of late, what with being sick and work pressures.

So, drop me a line or leave a comment and let me know if you’re interested.  It’d be released under the GPL, which means you would be expected to release your changes and modifications under the same licence (preferably back to me so I can encapsulate them into the main distribution.).

If enough people are interested to make it worth the effort, i’ll do it.  Let yourself be heard.

Advertisements

IE Bugs

I hate internet explorer.  No really, I do.  I yearn for the day when I can develop for a main browser that can actually properly display CSS without bugs and idiosyncracies.  That day may never come, but hopefully vista and ie7 will be a step in the right direction.  The company I work for aren’t about to migrate to firefox, so i’m stuck with ie6 for my webapps for now.

I just recently started trying to get my application to display css tooltips.  That is, little roll-over popup messages that don’t require javascript, just pure css, and work in IE 6 so I can use them to explain a small confusing part of my application.

I found a great site on it, it’s here.

Of course, if that was the end of it, I wouldn’t be here whinging now would I 😉  No, no matter what I did I couldn’t get that example to work.  It requires one more addition to the a.info:hover css that isn’t listed in his tutorial.  It took me two hours to track down the solution to this particular IE bug.  (Did I mention I hate IE?)

The problem was likely due to my changing things to fit the app I was developing. I didn’t want a background colour change on hover forinstance, just a text color change.  So here is what I had, and what I had to add to fix it.

a.info:hover
{
    z-index: 25;
    color: red;
    background:;   
}

See the strange “background:;” statement that does absolutely nothing? Thats the lifesaver under IE.  It would appear that on hover, ie decides the only thing that needs to be redrawn is that anchor text itself.  Now, as the tooltip is displayed as a block somewhere entirely different, it never gets shown at all.  The background element, even though it is not used and makes no difference, seems to trigger IE to redraw the entire page rather than just the anchor.  Thus then, the popups work.

When programs trying to be smart get real stupid.

Did I tell you that I hate IE?

Sorry for the lack of posts lately, I was quite ill and didn’t even go near a computer for a week.  (Anyone who knows me knows that means I was near death 🙂 )

Strange Visual Studio 2003 issue

I found an issue with the debugger and “Watch” functionality today that was quite odd and puzzled me for a short while until I noticed the problem.  I was attempting to compare two values stored in hash tables.  The reason it wasn’t working was that I was forgetting to cast them to strings, so the program was comparing object references.  The code went something like this.

If (dataValue[“SomeKey”] != otherData[“AnotherKey”])
{
    Do something horrific.
}

So the code should trigger when the two items arn’t equal.  Unfortunately it was triggering on code that was equal as well (the solution is to add “as string” after each dataValue – or your own preferred method of casting.)

The real trouble was however that when I copied that boolean function into my watch and debugged through it, the watch evaluates it as true!  It would appear that the watch evaluates by doing an automatic convert whilst the program doesn’t, thus giving completely different values and confusing the hell out of me as I tried to solve the problem.

I guess it pays to remember when we’re hunting bugs that they can exist in our tools as well as our code.

Javascript and Asp .Net…. Oh the pain.

Asp .Net makes some things very easy.  In particular, it makes adding controls that cause postbacks very very easy indeed.  You can do all of your web application event handling in this way without any problems whatsoever.

Of course, you migh not want to.

I’ve been investigating css as a mechanism for styling pages with a view to doing some work with Ajax – Asynchronous Javascript and XML.  Ajax has been used very successfully with a number of popular webapps, such as google mail, to provide application-like functionality and UI response from web apps, which have otherwise been lacking in this area.

So it was I came across the my little problem.  Whilst its easy to program server side events and control handling in Asp .Net, information on client-side scripting whilst using Asp .Net is a little harder to come by.

First things first, the control code in javascript.  It took quite some time before I was able to understand how to get a reference to a server control in a javascript function.  It’s possible to used [form_name].[control_name].[attribute] when dealing with plain html controls, though I think even that is frowned upon by w3c these days.  The answer lies in the getElementById function.  It works like this:-

document.getElementById(‘myTextBox’).value = “Value for a textbox”;

So, in order to test this I set up a little function that would check my check box and display a message if it was checked.  This was testing both my ability to poll a checkbox, and my ability to have the checkbox call the event handler.

The text for the function is below:-

function checkBoxChecker()
{
    if (document.getElementById(‘checkBox1’).checked)
       alert(“w00t! It worked!”);
}

As you can see, a very simple function.  It wouldn’t work – I could not find a way to attach this function to my asp:checkbox function.

So, I replaced the asp:checkbox’s with default html <input type=checkboxes> and the code worked fine.  The first problem, the javascript, was solved.

However, this raises another issue.  I want to later be able to check the checkboxes from my server code.  Which, strangely enough, cannot be done on html controls without some nasty text parsing which I didn’t want to get into at all. Not even a little.

So, we’re back to server controls.  Here is the control definition:

<asp:CheckBox id=”checkBox1″ runat=”server”></asp:CheckBox>

I tried adding the OnCheckedChange event handler to this description, that causes an error.  To be exact, it causes this error: CS0117:  does not contain a definition for – I removed the identifiers there to make it easier to search for in google. 

This happens because the compiler assumes you’re trying to link to a server side code event, rather than a javascript.  I finally found a note in msdn that says you -can- add a client side event, but not in the definition. It has to be done via code!  A-Ha!

So in our code behind file, in our Page_Load function we need to add the following:-

checkBox1.Attributes.Add(“onclick”, “checkBoxChecker();”);

and baboom.  Thats the same as adding the onclick to the underlying html control manually.  Now it works.  Finally.

All Reading Weekend

Spent most of this weekend past reading. I was out and about a bit, managed to take friday off due to accumlated overtime so I again was able to see the benefit of my iPaq.  A library in my pocket.

I read two pulp adventure books (the first two in the Richard Blade series) which are not literary classics by any measure but are quite entertaining.  The main character is a big, muscular, brave, manly man.  An MI6 agent (in the vein of bond, but tougher and less classy) who was chosen to be a guinea pig in a weird computer experiment that tried to pump memories and knowledge directly into his brain. It malfunctioned and instead sent him/allowed him to percieve another dimension.  (This part isn’t well explained but hey, whats to expect.)  The novels then seem to be based on his explorations of these new dimensions, a new one every book.  Whilst there he has adventures, kills bad guys, meets beautiful women and throws them down and has manly sex with them in such a way as to leave them quivering with desire and love so they go on to despair when he is away from them and build massive jade statues in his god-like image.  (That actually happened in the second book.)

Mindless, exciting escapism.  When did that become such a dirty thing? I love the dark realities of Steven Erikson’s novels, the alternate histories of Sara Douglass and the sweeping epic of Robject Jordan as much as the next man – they are books that have seriously altered my outlook on both life and what is possible in fiction.  When though did these works of art become the -only- thing that was on offer?

Perhaps action movies have stolen a lot of the need for pulp action novels but I for one mourn their passing.

Another book I read this weekend was entitled Pgp and Gpg – Email Security for the Practical Paranoid.  An excellent book on the practical matters of using public key encryption to secure your email, either with the commercial Pgp program or the open source GnuPG program. Both are fairly similar and run under the OpenPGP framework, this book covers the generalities and the explicit quirks of each.

Its not really aimed at people who have a lot of experience or knoweledge of cryptography and pki, much of the main meat of the book was just a rehash of things i’d already done and already knew.  The first chapter on the history of PGP is interesting for those who don’t know the full story.

In anycase, it is a practical book about how to get up and running in your home or organisation, rather than a deep technical or theoretical treatise.  As such, its an excellent book that I wholeheartedly recommend.

The Three Great Virtues of the Programmer

I found an interesting page today that quotes the three great virtues of the programmer.  I have all three in spades 😉  Apparently these were coined by Larry Wall.

Laziness
The quality that makes you go to great effort to reduce overall energy expenditure. It makes you write labor-saving programs that other people will find useful, and document what you wrote so you don’t have to answer so many questions about it. Hence, the first great virtue of a programmer. Also hence, this book.
See also impatience and hubris.
Impatience
The anger you feel when the computer is being lazy. This makes you write programs that don’t just react to your needs, but actually anticipate them. Or at least pretend to. Hence, the second great virtue of a programmer.
See also laziness and hubris.

Hubris
Excessive pride, the sort of thing Zeus zaps you for. Also the quality that makes you write (and maintain) programs that other people won’t want to say bad things about. Hence, the third great virtue of a programmer.
See also laziness and impatience.

I got them from this page.  They tend to waffle on a bit there though.  Also see this page – “Why good programmers are dumb and lazy.”  I heckled a bit about the dumb part, but what he suggests is the ‘dumb’ approach actually approaches the socratic dialog approach of finding the truth.  Thus, not dumb, but quite smart.  I think he’s using “dumb” to mean “simple”.  Either way, theres some good advice there.  Now if you’ll excuse me, i’ve got some laziness to cultivate.