Asus M50Sv-A1, Ubuntu and my eyes

Filed Under (boring blag) by sith on 27-09-2008

While watching Martha Stewart Presents Everyday Foods, on PBS this morning, I noticed that I could barely see the screen on my laptop.  Off to the Internet!!!

After digging through bazillions of postings, there it was…

The light sensor on my laptop doesn’t function properly under Heron. You can prove this by taking a flashlight and placing it directly over the light sensor (right beside the “Altec Lansing” logo). WOWZEE!!! Bright screen…take it away, dimness reigns.

So, popping open my trusty terminal, I entered the following commands:

sudo su  <hit Enter…then follow it up with your password. Mine is “imalazyboy”>
echo 0 > /sys/devices/platform/asus-laptop/ls_switch  <hit Enter>

Once again…WOWZEE!!! Bright screen.

I’m so happy. So lazy, but so happy.

Back to PBS…

Star Wars: The Clone Wars

Filed Under (movies, tv) by sith on 22-09-2008

Tagged Under : , ,

Took my cool kids to see it this weekend. It was fantastic. Lots of action and didn’t feel anything like Episodes 1, 2 or 3…it actually felt more like Genndy Tartakovsky’s version, so that made it really good.

Can’t wait for the season premiere of the show on October 5th…CTV, here in Canada.

Enjoy.

No IsInteger() in C#?

Filed Under (development) by sith on 22-09-2008

Tagged Under : ,

(* this is a legacy post from one of my earlier blogging attempts, better formatting to come)

Unless I just can’t find it, there doesn”t seem to be a method to test a value for whether it is a valid integer (or at least could be turned into a valid integer) in C#. For example, today I needed a way to test a string value before converting it to an integer. The original code looked something like this:

int ConvertedNumber = Convert.ToInt32(TextBox1.Text);

Of course, we all see major issues with this line of code. What if TextBox1 doesn’t contain a number? What if TextBox1 doesn’t contain anything at all? It wouldn’t have been so bad if there was some protection around this, but there wasn’t. So…the need to write an IsInteger() method kicked in, and here’s what we came up with.

private static Regex _isNumber = new Regex(@"^\\d+$");

public static bool IsInteger(string theValue)
{
    bool result = false;

    Match m = _isNumber.Match(theValue);
    return m.Success;
}

During my initial testing, this looked like it was going to work perfectly, until I found the following scenario…what if a user typed in “01″? They would be expecting this to be converted to a “1″. Unfortunately, my regular expression couldn”t handle it, so the following hack is what we came up with:

public static bool IsInteger(string theValue)
{
    bool result = false;

    Match m = _isNumber.Match(theValue);
    result = m.Success;

    if (!result)
    {
        try
        {
            int ConvertedNumber = Convert.ToInt32(theValue);
            result = true;
        }
        catch
        {
            result = false;
        }
    }
    return result;
}

I really don’t like using try…catch to handle normal code flow, but I’m still learning regular expressions, and couldn’t figure out how to handle this scenario. If anybody out there wants to help me out, that would be appreciated. If I end up figuring it out myself, I’ll update this article.

Maybe this is a good time to start a common methods assembly. :)

How to create a COM Interop DLL in C# (simple example)

Filed Under (development) by sith on 21-09-2008

Tagged Under : , ,

(* this is a legacy post from one of my earlier blogging attempts, better formatting to come)

Well, it finally happened. I had to force myself to figure out how the fsck to call a method in a C# assembly from a Delphi 5 Win32 application. The following is the culmination of all of the buttons that I clicked and swearing that I sweared…

And now our feature presentation.

1. Create a new Class Library project in Visual Studio 2005. Let’’s call it “InteropExample”.
2. Open the AssemblyInfo.cs file and set the COM visible attribute to true.

[assembly: ComVisible(true)]

3. Go to Project Properties –> Build. Check the option Register for Com Interop to “Selected”.
4. Open your class file and add the foloowing to the using clause

using System.Runtime.InteropServices;

5. In this class file, create the interface that will help expose methods to the unmanaged world.

public interface IMathFunctions
{
    int Add(int Number1, int Number2);
}

6. Create the method that will be called.

[ClassInterface(ClassInterfaceType.None)]
public class ComInteropExample : IMathFunctions
{
    public int Add(int Number1, int Number2)
    {
        try
        {
            return Number1 + Number2;
        }
        catch
        {
            return 0;
        }
    }
}

7. Now it’’s time to create the type library that we will use in Delphi (or any other unmanaged language). This type library can be used for late binding. In our example, the assembly will be private, so copy the assembly into the folder where the Delphi compiled executable will be (they need to live in the same folder). If this assembly is going to be public, you need to assign a strong key to the assembly. I”ll cover that in another tutorial (when I learn more about it myself…hahahahah).

Open a command prompt and type the following:

regasm InteropExample.dll /tlb:InteropExample.tlb

8. Switch over to Delphi, create or open a project and click Project –> Import Type Library. Select your InteropExample.tlb and click Create Unit. The pascal file that is created can now be used in your program to call the managed methods.
9. In your main unit, add “ComObj” and “InteropExample_TLB” (or whatever your generated unit is called) to your uses list.
10. Now we can slap some code in to run this bad boy

procedure TForm1.Button1Click(Sender: TObject);
var
  intfMath: IMathFunctions;
  result: Integer;
begin
  intfMath := CreateComObject(CLASS_InteropExample) as IMathFunctions;
  result := intfMath.Add(2, 2);
  ...
end;

* CLASS_InteropExample might not be the actual name, review the pascal file that was created in Step 8

11. THE MOMENT OF TRUTH…

Run your Delphi app, click the button and watch the magic…

12. When deploying on another machine, you will probably have to register the C# assembly. Make sure that the assembly is living in the same folder as the Delphi executable, then from a command line

regasm InteropExample.dll

Enjoy.

NUnit and me

Filed Under (development) by sith on 21-09-2008

Tagged Under : , , , ,

So begins my latest foray into unit testing. Don’t ask why, but watching Conan The Barbarian has somehow inspired me to actually work at this a bit and finally try to figure out why/how to unit test.

I’m armed with a copy of Pragmatic Unit Testing in C# with Nunit, and a fresh attitude…so, here I go…

…after Conan is over. Oh yeah, if I do figure this out, maybe I’ll try putting together some tutorials that might help other monkeys out.

Tools for Small Dev Team

Filed Under (development) by sith on 18-09-2008

Tagged Under : ,

Sitting around at lunch today, The Developer Formerly Named Monkey and I were trying to come up with a list of good open-source or free software that would help a developer, or small team, set up and manage a project.

Here’s a list of stuff that we’ve come up with so far:

Web Server and tools XAMPP
Source control server Subversion
Source control client TortoiseSVN
Idea organizer ToDoList
Installer Inno Setup
Project management Open Workbench
Bug Tracking Mantis

 

The only softie that we couldn’t come up with was a good diagramming tool (for flowcharting, etc). We looked at Dia, but it didn’t seem strong enough for daily use. It had kind of a klunky feel to it. Still looking…

Oh, Metallica…why?

Filed Under (music) by sith on 11-09-2008

Tagged Under : ,

So I’ve heard it….hmmm.

I can’t say that’s it’s bad. Other bands would probably kill to make a record like Death Magnetic, but this is Metallica. This is the band that created the masterpieces Ride The Lightning and Master of Puppets. So, I also can’t say it’s good.

I was getting a bit giddy through the first song…I thought we might have a winner, but then the rest of the album started proving what I had figured was going to happen. Each song had a strong part, and a weak part…at least it was consistant.

Basically, what it stems down to is: the dudes in Metallica are older, no longer all that angry and have more money than Jesus, so they write different music now. I guess that’s alright. I still love them for the first 4 or 5 albums that they created (and Garage Days Re-Revisited…which is brilliant).

So, let’s all enjoy a blast from the past and hope that they all go bankrupt.