Adjacency tables

2009-02-24

I’m well aware that adjacency tables aren’t the newest way of storing hierarchies in a database. Personally I prefer to use nested sets. But on this one project I had to work with a legacy database. It took me quite a while to find out how to retrieve an entire tree in one requests. This is obviously needed to speed up queries on large amounts of data.

This query is here to help me remember how to do it.

DROP TABLE People;

CREATE TABLE People (
id INT NOT NULL PRIMARY KEY IDENTITY
, boss_id INT
, name VARCHAR(50)
);

SET IDENTITY_INSERT People ON

INSERT INTO People (id, boss_id, name)
          SELECT 1, NULL, 'Bert'
UNION ALL SELECT 2, 1, 'Sylvie'
UNION ALL SELECT 3, 1, 'Sylvia'
UNION ALL SELECT 4, 2, 'Davy'
UNION ALL SELECT 5, 2, 'Xavier'
UNION ALL SELECT 6, 3, 'Kristof'
UNION ALL SELECT 7, 3, 'Piet';

WITH Bosses (id, boss_id, name, depth, hierarchy)
AS (
	SELECT id
	, boss_id
	, name
	, 0
	, name
	FROM People
	WHERE boss_id IS NULL
	
	UNION ALL
	
	SELECT People.id
	, People.boss_id
	, People.name
	, Bosses.depth + 1
	, CONVERT(VARCHAR(50), Bosses.hierarchy + ' > ' + People.name)
	FROM People
	, Bosses
	WHERE People.boss_id = Bosses.id
)
SELECT * 
FROM Bosses
ORDER BY Bosses.hierarchy;
id boss_id name depth hierarchy
1 NULL Bert 0 Bert
3 1 Sylvia 1 Bert > Sylvia
6 3 Kristof 2 Bert > Sylvia > Kristof
7 3 Piet 2 Bert > Sylvia > Piet
2 1 Sylvie 1 Bert > Sylvie
4 2 Davy 2 Bert > Sylvie > Davy
5 2 Xavier 2 Bert > Sylvie > Xavier

Css in Flex

2008-08-29

I had some issues today to change the background color of a button in Flex. The up-skin was set for the Button selector which meant setting the fill-colors property for the Button.special selector had no effect. Setting the up-skin to null was the only solution. This was easy to do in code with setStyle, but I wanted to do it in css. Writing null wasn’t quite enough. Apearently you need to use ClassReference(null). Hope this helps someone out.

Button {
  up-skin: Embed(source='img/example.png');
}
Button.special{
  up-skin: ClassReference(null);
  fill-alphas: 1.0, 1.0;
  fill-colors: #00FF00, #00FF00;
}

2M08 Silverlight

2008-05-23

A hands-on workshop about Silverlight 2.0.

The many MacBooks that are available are probably set up for the Air session this afternoon. Our speaker informs us "We wont be using those", quickly followed by "Silverlight is a cross platform …".

Blend has loads of panels and properties. Nesting controls is possible. You can have a video inside a button.

Changes in Blend are detected in Visual studio. It helps to do a rebuild in Blend to make shure Visual studio isn’t working on an old version. Design view isn’t fully supported there yet. Double clicking on a button doesn’t get you a onClick handler yet.

Silverlight uses layout managers like Flex. Buttons have a content property which enables design and programming to be done separately. You can create some kind of color palette of Brush Resources in Blend which translates to SolidColorBrush elements in XAML. Visual studio has intellisence for XAML which makes it easier to type in there than in Blend. Fullscreen is supported but must be initiated by the user. Controls have a background and a border while other elements have a fill and a stroke. Blend has some glitches when setting properties on multiple controls. Switching to XAML code is the normal reaction to that. Not shure how designers will react to that. Hope these things are fixed when it goes out of beta.

The presentation was quite good, but I’m not sure weather I’m going to dump flash for this.

on Air Brussels

2008-04-23

A long overdue overview of the on Air event in Brussels.

Read the rest of this entry »

Parsing plist files in asp with Microsoft.XMLDOM

2008-04-18

Plist files are more and more ubiquitous. Apple uses them for its configuration files and we use them to describe exercise content. They aren’t very pleasant to read for humans, but that doesn’t mean computers dislike reading them. So I wrote a little javascript to parse a plist file to an object. Hope you like it.

Read the rest of this entry »

Silver Explorer

2008-02-27

As most of my friends know, I’m partially colorblind. Most webdevelopers have no idea what their site looks like for someone like me. Thanks to the power of Adobe Air I’m now capable of letting you experience it firsthand.

Silver Explorer is a browser that lets you surf the net in grayscale.

silverexplorer.air
Flash version 9.0.115 required

full-screen mode in Actionscript 2

2008-02-19

How to use full-screen mode in Actionscript 2:

_root.btn_mc.onRelease = function(){
    if(Stage["displayState"] == "normal"){
        Stage["displayState"] = "fullScreen";
    }else{
        Stage["displayState"] = "normal";
    }
}

var listener:Object = {};
listener.onFullScreen = function(isFullscreen:Boolean){
    if(isFullscreen){
        trace("entered full-screen mode");
    }else{
        trace("exited full-screen mode");
    }
}
Stage.addListener(listener);

Also see Exploring full-screen mode in Flash Player 9.

forceSmoothing

2008-02-15

Rotating and scaling pictures in flash is easy. Just use _rotation, _xscale and _yscale. Except when you publish an swf for Flash Player 8 or newer. Every image you rotate or scale will become jagged. Very anoying. To remedy this you can either publish for Flash 7 or use a complicated loadBitmapSmoothed function that uses BitmapData.

When Flash Player 8.5 came out it introduced the forceSmoothing property. This property is also available in as2. Now all we need to do is set it to true when we load images. Don’t forget that this will have no effect in Flash players older than version 8.5!

It works quite well. In the example below you can clearly see the left picture is more jagged than the right one.

Read the rest of this entry »

pong0.5k, a game in 510bytes

2008-01-30

Mr.doob created a 1k pong game in as3. Which made my fingers itch to do better. So here it is, in as2, less than half the filesize and the same functionality.

Read the rest of this entry »

AIR afterhours

2008-01-18

I’ve been to a great afterhours session about AIR with Peter Elst. He’s writing a book on the subject so obviously there was lots he had to teach. He covered the windowing, file, dragdrop, sqlite and upgrade apis. This was a bring-your-own-laptop session so all the people present were experimenting with the code. We found a few oddities that you usually learn the hard way.

FileFilter behaves differently on mac and windows. On windows the extension parameter must start with an asterisk "*.html", on mac both "*.html" and ".html" seem to work.

Creating and manipulating NativeWindows works great, but adding flex components to the stage of a new NativeWindow doesn’t seem to work. Daniel Dura had a workaround for this, but that doesn’t seem to work anymore.

He gifted a few books at the end. ActionScript 3.0 Design Patterns is now mine. Thanks Peter!

Update: Peter has remembered how to use mx.core.Window as a a native window.