Showing posts with label code. Show all posts
Showing posts with label code. Show all posts

Thursday, October 09, 2008

Exciting new videos

In the last few weeks, a lot of new videos have been posted to Channel9, Microsofts portal for spreading the word about new software...

A lot of the posts are from the JAOO conference, which was held here in Denmark not too long ago. And just like last year, I've seen almost all the videos, and found the pretty cool. It seems like a lot of the videos are about programming languages and/or parallelism, and the evolution in those fields - very intriguing!

Maybe JAOO is a conference I should attend next year.

Anyway, check it out at http://channel9.msdn.com

Saturday, September 06, 2008

Auto XML sorted

I've been fighting a bug for some hours now bug have finally found the solution!

Here's the deal: I've developed a tool to import the contents of some files into a database. Furthermore there is a UI for CRUD'ing the now database content. The problem was, that when I imported from more than 10 files (don't know why this exact number, it's purely empirical) the data would show up pretty strange. It should have a format like this:

1 (count: 34)
3 (count: 54)
2 (count: 20)

But instead it was showing:

1 (count: 1)
2 (count: 1)
1( count: 1)
1 (count: 1)
3 (count:1)
... etc.

Weird!

At first I was looking at the import tool - I must have made an error somewhere, but no. The solution was to sort the data! The stored procedure selecting the data uses FOR XML AUTO to generate a hierachical structure, and somehow that twisted the data. But after adding "ORDER BY ColumnName" to the SQL it comes out right!

I don't understand why yet - and can't find any other posts regarding the same topic....

Monday, April 14, 2008

ASP.NET Login isn't persistent

I've had a problem with the System.Web.UI.WebControls.Login control on a web application. ASP.NET creates a cookie for the login, which is supposed to be psersistent if the "RememberMe" checkbox is selected. The problem is, however, that if you restart your computer, the cookie is deleted, and you have to login again... I decided to investigate, and found that this is caused by the application pool on the webserver recycling from time to time, and hereby generating a new machine key for the application.

The solution: Generate a static machine key and put it in your web.config.
I found the answer here: http://forums.asp.net/p/947381/1147268.aspx.

See this resource for creating a machine key: http://aspnetresources.com/tools/keycreator.aspx.


Another problem bites the dust!


UPDATE: Well it doesn't seem to be that simple after all. The login still isn't persisten :-(

Thursday, February 07, 2008

Contributing to the blog

Lately I've found some new inspiration in Adobe's Creative Suite 3. I've been toying around with Flash, Photoshop, Illustrator, Fireworks, InDesign, Dreamweaver, Flex and today: Contribute.

More specifically I'm writing this post from inside Contribute :-)

Contribute is an application build to help webmasters, blog owners and the like to keep their website and/or blog updated.

So far, here are some of my thoughts:

  • The editor seems nice - better than NeoOffice for the Mac anyay. It has some well built "Insert link" and "Insert image" dialogs! I'll get back and comment on the HTML it generates when this is posted
  • A well needed change from the web based interface og Blogger (which works great, but is a bit boring)
  • The price tag on the software, I think, will scare off some people. With $169 for a single license, I wouldn't go buy it. I guess people who spend every day maintaining websites may find it reasonable
  • The blogging feature is pretty cool. Contribute seems to integrate well into your chosen blogging system. It supports Blogger, WordPress and Typepad out of the box, and other blog servers through the MetaWebblog API
  • With my system (Blogger) I'm writing the post in-context (screenshot here)
  • I can save a post for finalizing later, as with Bloggers interface. In Contribute there is a list of unpublished posts/pages so you can easily find them again
  • As nice as the above sounds, I'm still not convinced when it comes to "normal" websites. I just don't see Contribute replacing real Content Management Systems any time soon. Too many features are missing (user management, extensibility etc.)

Those were some initial ponderings. I will probably get back about CS3 soon ;-)

Sunday, December 30, 2007

How to make the compiler do your work

Before Christmas I spent a few weeks on a school project in computer science. The choice of technology was up to us, and I naturally took the safe path of .NET and C#. I used Visual Studio 2008 as IDE, as it had just come out, and I wanted to try it out. I also wanted to test C# 3.0, which the new IDE of course facilitated. Later I came to think that my team and I wanted to have the solution running on a web server, so the examiners would be able to see the actual prototype working. As I didn't have any options for running the prototype on a .NET 3.5 server, I had no choice but to make the solution .NET 3.0 compatible. This is no big thing in Visual Studio 2008 – you just change the target framework and recompile. Naturally a lot of compiler errors emerged. But to my surprise, they were all related to references to .NET 3.5 specific assemblies, and not my actual code! This got me thinking, and investigating.

I used "simple properties", which is an easier way of writing simple properties with no get/set logic, other than setting a backing field's value or returning it, a lot. When you write them in C#, it looks like this:

Simple properties

What happens when above is built is that the compiler generates the get_Id() and set_Id(int value) methods as before, but then also generates a backing field that reverse engineered looks something like this:

Backing field

The funny thing is the naming of the generated field. Note the < and > symbols; they are used in order to avoid C# code accessing the field! If I try to get access to the field from a C# method, I will get a compiler error, as < and > are not allowed in the context.

The full property will look like this after being compiled:

Compiled property


I never thought of this, but as all the features of C# 3.0 are "syntactic sugar" changing the target framework while keeping the C# 3.0 compiler, I can have all the features, even though everything is compiled to C# 2.0! Great!

Oh, and by the way: Note the [CompilerGenerated] attribute. I want all of my compiled code to have that!

Friday, September 07, 2007

How did I not see that?

I had a nice experience today. I have been developing a website that uses the native ASP.NET 2.0 provider model. To save time I've just installed the default provider implementations for the MembershipProvider and RoleProvider and am using them.

So now I am in the process of creating an administration-system for the entire website, including the providers, and found myself having an insane bug/error. I had two users in my database, myself and a test person (Hans Hansen). When I updated the users everything was fine, unless I wanted to change the users' roles. If I was editing my own user it worked. If I wanted to edit Hans Hansen, however, the app crashed. The error message was something like: "Cannot update user name ''" (empty user name).

Now, I am pretty sure the user name isn't empty, so I began debugging. After about 2 hours of hopeless looking through code (even the ASP.NET provider stored procedures!), and plenty of theories about the origin of the error (including one or two angry thoughts to Microsoft), I developed a theory. What if the user name was required to be minimum 3 chars? Hans Hansens ("hh") was only two, but my own ("mgj") was three, and for the latter everything worked! Well, I changed "hh" to "hah", and suddenly everything worked! So now I'm thinking, that Microsoft is behind the error, and begin looking quite deeply into their stored procedures looking for the unwanted feature.

After another hour down there, I coincidentally passed the [aspnet_UsersInRoles] table, and lost my jaw. I had finally found the problem. In the aspnet_UsersInRoles table, a previous test user had not been deleted. And he happened to have the same username as Hans Hansen ("hh").

So, in the words of Sting, "I hate to say it, but it's probably me"


Note to self: Make sure test environment isn't corrupted, before pointing fingers!

Tuesday, August 07, 2007

The replacement has been found

Okay, so the aoa.dk domain name has been sold, as I mentioned earlier, and the new domain name to take it's place has been found: www.AoA.nu

Not a very drastic change but still a change...

Be sure to check out the relics section - that's where we're putting all the classic stuff. A lot is already out there, and more will come as we dig deeper into our hard drives in search of fun stuff that previously has been a part of out aoa.dk website.

I also have some more news, but you'll have to wait for that a bit longer...

Thursday, May 31, 2007

XSLT is definetly the way to go

Lately I've been working on a project for at customer, when I was able to get away from all the things happening at CBS.
The project is a very complex website, build on top of the open source CMS and web site framework, umbraco.
The important thing here is, that umbraco relies heavily on XSLT for formating and rendering custom modules. It's been a while since I've had the opportunity to develop things with XSLT, anyway, I almost forgot just how nice it is... In little time, I made a functional dropdown navigation, a vertical navigation tree, a list of media from umbraco, a sitemap, breadcrumbs and a dynamic title-tag for the HTML page.

Lovely :-)

Monday, April 23, 2007

Something about ID3 tags

I've been wanting to research ID3 tagging of MP3 files, and have spent some time trying to read the tags using C# - without luck :-(

The streams I'm reading always seem to be flawed in some way. Well I've found an example where you use the shell32.dll Windows native library to read the tags. I'm looking forward to trying this out to see if it's me thats wrong ;-)

http://www.codeproject.com/csharp/ShellID3TagReader.asp

Thursday, November 23, 2006

LINQ to Desktop Search

Yes! Yet another interview with Anders Hejlsberg on Channel9.

In this one he talks to Chris McConnel who is the architect for the Windows Desktop Search product. It's really cool to hear his takes on the world, and how LINQ fits into it. And as a new thing in Channel9 the person asking questions is actually not the interviewer but the interviewee (ie. Chris McConnell asks Anders questions). It seems like he's asking all the right things, and we get Anders' views on a lot of different problems in the programming world, for example:
- functional programming
- intentional programming
- LINQ to desktop search
- WinFS


Nice stuf...


Well, here's the link:
http://channel9.msdn.com/ShowPost.aspx?PostID=260202#260202

Friday, November 10, 2006

I fucking hate caps lock

I hate it when it happens: You're typing your user name and password, but it doesn't work. Then you do it again, and it doesn't work.. Then you do it AGAIN, and it doesn't work. Then you look at the little Logitech stand for your wireless desktop and realize caps lock is on !!!!

I have partly stolen, and partly adjusted and perfected this little JavaScript code snippet to check if caps lock is on, and displays a message if it is:


var capsLockOnMessageDisplayed = false;

function checkCapsLock( e )
{
var keyCode = 0;
var shiftKeyOn = false;

if ( document.all )
{
keyCode = e.keyCode;
shiftKeyOn = e.shiftKey;
}
else if ( document.layers )
{
keyCode=e.which;
shiftKeyOn = ( keyCode == 16 ) ? true : false;
}
else if ( document.getElementById )
{
keyCode = e.which;
shiftKeyOn = ( keyCode == 16 ) ? true : false;
}
if ( ( keyCode >= 65 && keyCode <= 90 ) && !shiftKeyOn ) { displayMessage(); } else if ( ( keyCode >= 97 && keyCode <= 122 ) & shiftKeyOn ) { displayMessage(); } } function displayMessage() { if( !capsLockOnMessageDisplayed ) { alert( 'Caps Lock is On.\n\nTo prevent entering your password incorrectly,\nyou should press Caps Lock to turn it off.' ); capsLockOnMessageDisplayed = true; } }


Ps. check this out: CAPSoff