Archive for the 'Programming' Category

Anders Hejlsberg talks about C# 4.0

Channel 9 has posted a great talk by Anders Hejlsberg, the original author of Turbo Pascal, the chief architect of Delphi, and the lead architect of C#.

History lesson: Anders was lured away from Borland by Microsoft with a hefty offer of a $1.5 million signing bonus, a base salary of up to $200,000, and options to buy 75,000 shares of Microsoft stock.

Looks like it was worth it, as each C# release has added many interesting and powerful features, while maintaining a fine balance between complexity and simplicity.

Trimming in ActionScript jQuery-style

Sometimes we want to remove whitespace from the ends of our strings. In fact, this task is so common on the web that the ubiquitous jQuery library includes a utility method for that purpose.

What about in ActionScript 3? Well, not so much. The String class in AS3 is, in my opinion, a bit lacking compared to languages like C# and Scala. What’s worse, you can’t augment prototypes easily like you can in JavaScript to add missing methods (see update at the end for more information on this).

Read more »

SpriteFactory — an AS3 library for creating multiple sprites using the same bitmap

While working on Flash sidescroller stuff I noticed that there was no easy way (that I could find) to create multiple sprites from a single bitmap (something you’d do when doing a tile-based graphics layout).

Sooo… I made my own simple library called SpriteFactory.

Here’s some example usage:

var factory:SpriteFactory = new SpriteFactory("assets/sprites");
factory.loadBitmap("grass", "block-grass.png");
var grass1:Sprite = factory.newSprite("grass");
var grass2:Sprite = factory.newSprite("grass");

Check out the project page for more information.

The jQuery animate() step callback function

If you’ve ever needed to do more complex animations than fades and slides, then you’ve probably encountered the jQuery animate function. The animate function allows you quite a bit more flexibility than just using fadeOut or slideDown. In fact, the oft-used fades and slides simply wrap calls to animate.

If you’ve ever looked at the jQuery animate docs at api.jquery.com you might have noticed that one of the optional arguments you can define is step which is defined as:

A function to be called after each step of the animation.

…and that’s it. If you search for “step” on the page, you won’t see another mention of it.

Read more »

Inconsistencies in the .NET Enum class

During a recent project of mine, I had to do a lot of enum manipulation using the .NET Enum class and I have to say I wasn’t impressed. Besides the shortcoming of it not being a generic class (and thus not being especially type-safe), Enum also has some strange inconsistencies in terms of how it handles matched integral types.

Read more »

Why your custom EnumStringType might not be working

I recently spent a couple hours yesterday to fix a problem I was having with my custom EnumStringType (see this post).

Basically, what was happening was when my repository was making a call to ICriteria.List(), which in turn called the Set method of EnumStringType, it was always passing in a lowercase string instead of an enum instance.

Read more »

How to put spaces in your NHibernate enums

NHibernate lets you map C# enums to database columns. This can be quite convenient in cases where you have a database column for something like gender. To map them, you follow the procedure outlined here.

That works all fine and dandy, as long as the strings you want to store in the database are valid C# identifiers.

Read more »

How to (kinda) fix Firefox’s showModalDialog

As someone who has had to write a lot of IE-only code (against my will, I swear!), I was pleased to hear that Firefox 3.0 added support for the IE JavaScript function window.showModalDialog. Being in the middle of re-writing an IE-only web application, I thought this would simplify rewriting the modal dialogs to be compatible with both browsers.

Unfortunately, I don’t think the folks at Mozilla put their best effort into this one.

Read more »

Joshua Bloch’s Builder Pattern in C#

Having spent a lot of time programming in Java over the last two years, I’ve made heavy use of Joshua Bloch‘s Java Builder pattern (also Effective Java Item 2).

Recently, I’ve started a fairly large project in C# 3.0. As it happens, there came a point where I wanted to use a pattern similar to Bloch’s Builder. However, as anyone who tries to use this pattern in C# will quickly find out, Bloch’s Builder doesn’t translate perfectly to C#.

Read more »

Convert PHP date format string to .NET DateTime format string

I recently had to convert some JavaScript code I’d written that used a PHP-style date format string to a .NET DateTime-style date format string.

It would’ve been a helluva lot faster to have had some sort of conversation table. After a little searching on Google, I found nothing so I decided to make one myself. Behold, the fruits of my labour!

Read more »

« Previous PageNext Page »