R.I.P. Jay Reatard 1980 - 2010

Filed Under (music) by sith on 01-14-2010

Man, another awesome one goes down.

For those of you that never saw/heard Jay, check out the brilliance that we were left with at [www.jayreatard.com].

Python, SMB shares, OS X and a little bit o’ sexy

Filed Under (development) by sith on 12-09-2009

Tagged Under : , , ,

I had the extreme privilege of watching my friend help me solve a problem today.

I needed to find a better way to manage my mount points for SMB shares on the Windows boxes at work. The old Finder just wasn’t playing nicely. Using “Connect to Server” was flaky at best. Sometimes it wanted to work, other times it just sat there spinning.

I figured that I had certain shares that I hit a lot of times during the day, so why not automate the mounting of them. So I broke out a bash script and started hacking away. Sure I could do it, but it just didn’t seem like fun. It looked like a big batch file and nothing that I would brag to my kids about.

Why not sexy it up a bit? I broke out python. I started banging away at it and immediately had trouble with looping through the possible directories that needed to be checked if they were mounted. My friend boogied on over to my desk, broke open the interactive python and started showing me the wonders of being able to write a line of code, test it, change it, test it again, love it, move on.

He showed me how to test “os.listdir” and see the return. We were happy, so we changed it to assign its return to a variable.

Then we tested “os.path.ismount” by shoving in a known mount. It returned true. We tested it again with a regular directory. It returned false.

With this information, I was then able to pieced together my first function.

dirs = os.listdir(homePath)

    for s in dirs:
        isMounted = os.path.ismount(homePath + s)
    ...

I know it doesn’t seem like much right now, but I guess the point that I was trying to make was how much fun it was to shift the paradigm from the normal everyday programming model (using languages like Delphi and c#) to this more interactive and functional version. I could have hacked this together using bash in 5 minutes, but the end product just wouldn’t have been as sexy.

And sexy is good, right?

Here is the working version of my script to mount SMB shares in OS X. [SlaMBack.py]

Aaarrgghhh…what to learn?

Filed Under (development) by sith on 12-04-2009

Tagged Under : ,

I’m frustrated.

I feel I’m a jack of all trades, but a master of none.  What to learn next?

That’s the problem, isn’t it? Whenever you sit down to learn the next “latest greatest”, somebody outdoes it and comes along with the next shiny toy.  Learn AJAX, no wait…learn ASP.Net, no wait…learn ASP.Net MVC…no wait…learn Silverlight…

I keep hearing about the “next level” from my peers (and I’m as guilty of this as the next dev); about what we should be looking at to forge ahead into the future.  I think we’re making a mistake.

We need to go back to the beginning. We need to start understanding, not only what we are coding, but why we are coding.  A friend of mine wrote about the garbage collector the other day. He made a good point. Why do we just take somebody’s word that it works.  It’s there for us to see how it works.  Why don’t we figure it out…just to make sure.

At work today, I wrote something as simple as a delegate to pass info back and forth between two forms.  I’m not sure some of the people that I work with will be able to figure out how it works.  Why?  Because they don’t care.  They don’t want to know what’s going on, or the best way to do something.  Or even just a different way to do something.  It’s not shiny enough (for some) and it’s too “out there” (for others).

I think I’m starting to rant a bit here, so I think I’ll just fire up emacs and learn some lisp.

Anybody else wanna learn, too?  Check out Practical Common Lisp.

If chefs cook, coders should program

Filed Under (development) by sith on 11-30-2009

Tagged Under : , ,

Would you eat at a restaurant if you just found out that the chef doesn’t like to cook at home?  Would you let a carpenter build your new home if you just found out that they have never built anything on their own?  Would you let a dentist look after your teeth if you found out that they hate to brush their own teeth?

Sounds ridiculous, doesn’t it? Yet, look around your office and try to pick out the developers that actually code in their “off” time.  I can’t tell you how frustrating it is when you realize how small the number may be.  I mean, why wouldn’t you want to be the best coder that you can be. The people that I work with and respect most are always writing new code at home. They are always reading code and books about code.  They eat code. They touch code in it’s private spaces.

To try to cultivate a bit of pride, I have even placed a few copies of Code Complete around the office, and you know what? They are covered in dust, cause the coders in the office that would actually read it, already own it.  The others that should be reading it, just ignore that its even there.

It’s even odd how there is no hero worship. I’m sure that all hockey players look up to those that played the sport before them.  If I threw out the names Stallman, Carmac, Berners-Lee and (the funniest one for me) Hejlsberg; there are very few that I have worked with that would know any of these names, or what they were known for creating.

So, if you really want to call yourself a coder, coders should program.

Recommended reading:

Anything by Steve McConnell

Asus M50Sv-A1, Ubuntu and my eyes

Filed Under (boring blag) by sith on 09-27-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 09-22-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 09-22-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 09-21-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 09-21-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 09-18-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…