Tuesday, September 29, 2009

How to list the items in a Resource class

When you want to enumerate through the items in a Resource class, you find that its ResourceManager class doesn't have a method for it, only GetString or GetObject for when you know the key. The solution to get all of the items in a Resource class comes with the GetResourceSet method of the ResourceManager, which returns an IEnumerable class, but not a collection. The enumerator can be of different types, but by default it is a HashTable, therefore the items the enumerator returns are of the type of DictionaryEntry.

So the code is as follows:
var resourceSet = ResourceClass.ResourceManager.GetResourceSet(CultureInfo.CurrentCulture, false, true);
foreach (DictionaryEntry resource in resourceSet)
{
DoSomethingWith(resource.Key, resource.Value);
}

Monday, September 28, 2009

There are 19 extra pixels in my scrollHeight and the scroll bar is showing!

I had this situation where in Internet Explorer, in quirks mode, I would open a dropdown calendar (so showing an absolutely positioned element that was until then hidden) and the scrollHeight of the entire page would increase by a magical 19px.

This was caused by a fix for another problem, where the displayed calendar would not position itself under the text input element where it should have positioned, so I made it so that the displayed calendar would be the last child of the body element. This way it would always show in the correct position, but displaying this situation when elements were trying to fit in the height of the page.

I could not find the cause other than a problem in the Internet Explorer render engine, but I did find a fix. Instead of placing it at the end of the body element, place it at the beginning. With jQuery that simply translates into:
if (!elem.parent().is('body')) $('body').prepend(elem);
Notice my use of prepend instead of append.

Tuesday, September 22, 2009

The Internet as an utopian tool

It has been a while since I've posted an entry about TED. In case you don't know what it is, go to ted.com and marvel of the interesting things one can find there. Well, in this post I am going to post two talks about the Internet. One talks about how concepts that would never have worked in real life have caught on in cyberspace (see Wikipedia, where people add information voluntarily, without any remuneration) and the second is about how the Internet can be used by totalitarian(?) states to oppress, rather than being a magic tool that spwens democracy. My comments are at the end of the post.





I have to say that Jonathan Zittrain's talk made me immediately think of Fidonet. Long before there was the ubiquitous Internet, amateurs would host Bulletin Board Systems where people could connect and send/read mail, download files and engage in social activities. Actually, one could think even further back, to pirate radio stations, that people would run on their own money (and seldom their own risk) without any chance of a profit.

So yes, given a method of reducing the cost of help significantly, I think a vast majority of people would help others without considering it a bother. However, to adapt the theory that any altruistic person is helping others because of personal reasons, therefore it is a form of egotism, I think a better way of putting it is: given a method of reducing the cost of coagulating in a group, people will enlarge their concept of clan and start doing stuff they would do for themselves for a lot more people.

That brings me to the second talk, Evgeni Morozov's,that would have been a lot more powerful if the guy would have stopped a few times to take a breath, right? :) He talks about the ease of using the Internet to determine the network structure of groups of people (clans again) and then striking where it is most effective with minimal cost to the establishment. There are mathematical algorithms that can do this automatically, just give them a graph of people and they will determine the leaders of opinion, the hubs of information. Then you can either persuade or remove them, giving you the power to control their entire "flock", just like pruning a bonsai tree to make it look like you want it to. And I think this system is a lot more used in democracies, rather than in totalitarian regimes, for the simple reason that despots have other options.

Both ideas seem to have a point in common, in my view, that in any strongly connected group of people leaders will naturally emerge , without any other reason than that they feel good about it, and stear a lot of passive people, whether in opinion or action. In an ideal situation, where all connections between people would be transparent (and I imagine Google is not far from having this kind of information), the entire humanity could be reduced to an active minority and an inertial mass of people.

This is interesting as a case study, because I am talking of an elite group of people, and not one that is organized, but one that is emerging naturally from chaotic personal behaviour. Something like Asimov's psychohistory could use that, with the axioms slightly modified to talk about "active population" as opposed to total population.

OutOfMemoryException in System.Drawing.Graphics.DrawImage

I was using these GIF images stored as embedded resources and suddenly I got an Out of memory exception from a component that I had no control over. All images were icon size, 16x16 or a little more, so a lot of the explanations for the error based on "you don't have enough memory!" (duh!) were not helpful. The images did have transparent pixels, and my gut feeling is that it all came from there.

I still don't know what caused it, but I did find a solution. Where I get the image I add an additional
image = image.GetThumbnailImage(image.Width, image.Height, null, IntPtr.Zero);
I know it's not something very intuitive, but it solved the problem.

The only significant difference between the image before and after the thumbnailization is the PixelFormat property that changed from PixelFormat.Format8bppIndexed to PixelFormat.Format32bppArgb.

The stack looks like this:
   at System.Drawing.Graphics.CheckErrorStatus(Int32 status)
at System.Drawing.Graphics.DrawImage(Image image, Rectangle destRect, Int32 srcX, Int32 srcY, Int32 srcWidth, Int32 srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttrs, DrawImageAbort callback, IntPtr callbackData)
at System.Drawing.Graphics.DrawImage(Image image, Rectangle destRect, Int32 srcX, Int32 srcY, Int32 srcWidth, Int32 srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback)
at System.Drawing.Graphics.DrawImage(Image image, Rectangle destRect, Int32 srcX, Int32 srcY, Int32 srcWidth, Int32 srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttr)


And, using Reflector, I could go as far as pinpointing the error to the method System.Drawing.SafeNativeMethods.Gdip.GdipDrawImageRectRectI which wraps the gdiplus.dll GdipDrawImageRectRectI function. It returns error status 3, which is Out of memory, and that is that. I couldn't find a C++ code for the GdiPlus library and even if I had, who I am kidding? :)

Saturday, September 19, 2009

The Teaching Company. Realy nice courses on just about anything

My world view is limited by the data that comes to me. I have my tiny slice of reality, a few friends, my work, then there are movies, news, documentaries, the Internet and so on. You will notice that I placed them in a certain order, it is the order that to me seems to go from more bullshit and less information to more information. I never believed the expression "Truth is stranger than fiction", so lets set the slice of reality aside. And, being first on my list... full of bullshit :)

Movies teach me a lot, but there is just as much untruth and deceit in them as there is stuff worth knowing. News are focused on a part of life that normally doesn't interest me, but they still have a higher percent of useful information. Then there are the documentaries, stuff from Discovery Channel and the likes. Well, I have mixed feelings about those. There are things that they teach me and they do it in a pleasant manner, yet, by the time they end, I feel like there is so much more that I wanted to know and that it all just stopped when it got interesting. On further analysis, it seems the quantum of information in an hour of film was something I could blog in two or three paragraphs.

And then there is the Internet. It is bursting with information, if only I knew where to look and only if I had the discipline of researching, summarising and storing that information. I am working on that, even this blog is used to store what I find, but I am still only an amateur. There is something that attracted me a while ago, something called Open Courseware. There were courses from the largest universities, freely available on the net. However, they left me feeling disappointed as they were mostly text, the few that were in media format were mostly audio and, in the end, they were only poor recordings of classroom courses, sounds of scribling on the blackboard included.

Enter The Teaching Company, a company that produces recordings of lectures by nationally top-ranked university professors as well as high-school teachers. The lectures are well done, they feature some guy or gal that present the information without having to write stuff on blackboards. If anything is to be shown, it will be a computer slide or animation, while the details on spoken information are added to the screen (for example the names of people). Wonderful stuff, only it is not free.

If you go to the official site you will find courses on just about anything, priced at around 35$ per download and 70$ per DVD if they are "on sale" and the rest of them going to about 250$, with a range of 20-40 lectures per course. Of course, there is the option of looking for "TTC torrent" on Google and see what you find there. For the people in Africa that just got an Internet cable installed, I mean.

I had the luck to start with linguistics (Understanding Linguistics: The Science of Language by John McWhorter), lucky not because linguistics is so interesting, but because John McWhorter was really charismatic and had a very well constructed set of lectures. And because linguistics is an interesting topic, at least at the introductory level of this course. It was funny, too, the guy is what I imagine a typical New Yorker to be. He is black with a Scottish name, he talks a lot of Broadway plays and old movies, he is socially astute; very cosmopolitan.

Then I went for astronomy (New Frontiers: Modern Perspectives on Our Solar System by Frank Summers). If you like those National Geographic documentaries about the solar system, you will love this. Towards the end it got detailed in a bad way, but only compared with the beginning of the course, which was really well done. The lectures are about the Solar System, from the standpoint of a modern astronomer, in light of all the recent discoveries. Also, a very well made point about why the structure of the solar system was revised and Pluto got demoted. At the end it talks of other star systems and what are the methods to detect and study them.

Not all the courses are so good, though. I had the misfortune of trying out Superstring Theory: The DNA of Reality by Sylvester James Gates, Jr. The guy is a black man in his late fifties who tries to explain Superstring theory without using any mathematics. He starts by repeating a lot of what he said in previous lectures and, indeed, in the same one earlier on, then goes asking these stupid questions that repeat what he said again. Something like "As I said in a previous lecture this and this and this happened. But why did this and this and this happen?". Ugh. If it was only about that, I would have finished watching the course, but it was something completely unstructured, boring and dragging. After 12 lectures out of 24 I knew nothing about string theory, except vague things like "if I imagine a ball that goes towards another ball and they shout at each other and the waves make other balls while the previous balls disappear but wait they appear again...". What I knew is that I had to stop watching. Sorry, Mr. Gates, lecturing... just not your thing. Stick to short appearances on Nova PBS shows.

Right now I am on Building Great Sentences: Exploring the Writer's Craft by Brooks Landon. It talks about constructing good sentences in order to improve one's writing. I have the feeling that the guy uses more detail than necessary. Like when he explains a concept he has to give at least 5 examples, when 2 or 3 would have been enough. But then again, maybe I am wrong. I will have to finish the course to give you a definite opinion.

Next on my list:
Quantum Mechanics: The Physics of the Microscopic World by Benjamin Schumacher
Understanding Genetics: DNA, Genes, and Their Real-World Applications by David Sadava
Introduction to Number Theory by Edward B. Burger
Understanding the Brain by Jeanette Norden

Does all this make me a very smart person? Not really. Remember that most of these are introductory courses. They do not contain exercises or books that you need to read, nor do they require a very high level of previous knowledge in order to understand them. They are, pure and simple, like those Discovery Channel shows, only they don't end when they get interesting and they are not so full of bullshit. After watching one of these courses (or, indeed, listening to them as podcasts while you are going to work) you will have an idea on where to go digging deeper for the topics that interest you.

Good learning!

Thursday, September 17, 2009

Creating a self validating ASP.Net control

It started with a simple request for a custom control to perform some validation. Seems easy enough, but it is not. Sure, there is an easy solution and that is to create a composite control, containing the original control and a normal validator, but that means you don't inherit from either control and you have to copy all the properties and methods you are interested in. If, as I did, you do not like this solution, you will soon find out that there are a lots of obstacles to be conquered if you want all the features of a validator, the first of which being that a control cannot easily change the Controls collection of its parent. It would be bad design. Therefore simply adding a Validator from inside the control does not work.

Let's start with what others did: Self Validating ASP.NET Text Box. This CodeProject article shows how you can build a control that is validated only on the server side and implements the IValidator interface. However, you will notice that it did not implement the ValidationGroup behaviour. And that is due to a simple fact: there is a method of the Page class called GetValidators(string validationGroup) that is used all around ASP.Net. It looks kind of like this:

public ValidatorCollection GetValidators(string validationGroup)
{
if (validationGroup == null)
{
validationGroup = string.Empty;
}
ValidatorCollection validators = new ValidatorCollection();
if (this._validators != null)
{
for (int i = 0; i < this.Validators.Count; i++)
{
BaseValidator validator = this.Validators[i] as BaseValidator;
if (validator != null)
{
if (string.Compare(validator.ValidationGroup,
validationGroup, StringComparison.Ordinal) == 0)
{
validators.Add(validator);
}
}
else if (validationGroup.Length == 0)
{
validators.Add(this.Validators[i]);
}
}
}
return validators;
}
Notice anything? There is no mention of IValidator, instead only BaseValidators are sought and the reason the IValidator approach works at all is the line before last where a validator is added to the list if the validationGroup parameter is empty. That is, it will work with IValidators but only on Buttons or other postback controls that have an empty ValidationGroup.

So let's start from the idea of the original article: an IValidator TextBox control with server validation only. For simplicity I will compare the value of the control with a constant string and fail the validation if the comparison fails.

Click to expand


You notice that the entire logic of this method is that the validators in the Page.Validators collection will be validated when need arises. In order to implement the ValidationGroup behaviour, we need to either fool the GetValidators method or to actually add a BaseValidator to the collection, not the IValidator control. I would have preferred the first method, but GetValidators is executed not only in Page.Validate but, being public, can also be executed in other situations (and in fact it is called by every control that wants to cause a postback).

My first attempt was to simply add a dummy validator to the collection, with the proper ValidationGroup set. It worked for the client side (we'll get to that) but then it failed miserably when Page.Validate tried to loop through the collection. I was forced to create my own validator control that inherits from BaseValidator. Do not worry, though, it is very lightweight and does not need to be added to the Controls collection. Here is the source:
Click to expand

public class DummyValidator:BaseValidator
{
private readonly IValidator _realValidator;

public DummyValidator(IValidator realValidator)
{
_realValidator = realValidator;
}

protected override bool EvaluateIsValid()
{
_realValidator.Validate();
return _realValidator.IsValid;
}

protected override bool ControlPropertiesValid()
{
return true;
}
}


Note: the following code has a property called ValidationGroup. The TextBox already has it, for its own AutoPostBack behaviour. I left it there, though, because you might want to use this on a control that doesn't have it natively.

Now the code for the ValidatedTextBox class looks like this:
Click to expand

private DummyValidator _dummyValidator;

protected override void OnInit(EventArgs e)
{
base.OnInit(e);
if (Page != null)
{
_dummyValidator = new DummyValidator(this){ValidationGroup = ValidationGroup};
Page.Validators.Add(_dummyValidator);
//Page.Validators.Add(this);
}
}

protected override void OnUnload(EventArgs e)
{
if (Page != null)
{
//Page.Validators.Remove(this);
Page.Validators.Remove(_dummyValidator);
}
base.OnUnload(e);
}

private string _validationGroup;

public string ValidationGroup
{
get
{
if (_validationGroup == null)
{
if (ViewState["ValidationGroup"] == null)
ValidationGroup = "";
else
ValidationGroup = (string) ViewState["ValidationGroup"];
}
return _validationGroup;
}
set
{
_validationGroup = value;
ViewState["ValidationGroup"] = value;
}
}


So the ValidationGroup is now working on the server side since there is an actual BaseValidator in the Validators collection calling the Validate method of our control. Since the DummyValidator class doesn't implement any specific behaviour, it can be reused for any type of validated control.

Now for the client side part. The client validation scripts work with a javascript array called Page_Validators. The validators are rendered as span elements (where the error message is displayed) and the array holds all these elements, with some extra properties like isValid, errorMessage, evaluationfunction, controltovalidate, validationGroup, focusOnError, enabled and display. The first three are like the IValidator members, only in javascript, controltovalidate is the client id of the control to be validated while focusOnError is used to scroll the page/container in order to see the invalid control without looking all over the page to find it.

All the ASP.Net validation functions are in a javascript file called WebUIValidation.js and embedded in the System.Web.dll library. We need to load it in order for validation to work. Then we need to render a span element and set its attributes. Lastly, but most important of all, we must create a function that will evaluate the validity of the control.

I will just post the entire source, since all the client code is practically copied from the BaseValidator code.

Click to expand


There are several things you need to take care of.
One of them is the client display of the validators. Normally, a validator's span element is rendered with the ErrorMessage as inner html. The ASP.Net framework then changes the visibility of the span depending on the validity of the control. I have chosen to not render the error message, as I wanted a different behaviour (in this case, a red background). The span element is still shown and hidden, but being empty, there is no visible effect.
Another thing is when you would use validation summaries. The error message is being rendered as a property of the span. It WILL be used in the summary, even if it is not normally displayed.

This code will work with almost no change for any control, so you could encapsulate it into a ValidatorHelper class or something. The only variants are the Validate method and evaluatefunction function.

Also note that having inherited from BaseValidator, I bypassed the normal functionality of the default validator controls. If you want to inherit from one of those, like RegularExpressionValidator, you might encounter problems, especially for controls that are not normally validated and for which the normal validator controls try to get their value. Take a look at the ValidationProperty attribute that you might need to use to decorate your control in order to work with default validators. Also, the javascript behaviour is to look for a control that has a value attribute. If not found it searches deeper into the children. So if you want to use a default validator, you might want to add script to keep a value attribute updated on the validated control HTML element.

And that was all.

The Prefect by Alastair Reynolds

Book coverUgh! The fifth book of the Revelation Space series , The Prefect, is the worst so far. Not only is it standalone, but it is also a prequel, something that happends pre-plague. All the characters seem to have been lobotomized some time in the past (possibly in an operation that also mixed their brains around so that they all sound and act the same), including the bad guys, and the story is completely boring. Nothing in this novel makes any sense, nor does it make you feel anything special, quite the contrary, the scenes that were supposed to bring out feelings for the reader felt really forced and had the opposite effect.

The only good thing in the book was the ClockMaker, all 10 pages of it or whatever. Couldn't you start with the ClockMaker, continue with the ClockMaker and end with the ClockMaker and forget all about the stupid and randomly emotional people, mr Reynolds?

Tuesday, September 15, 2009

Getting rid of Surround SCM .MySCMServerInfo files from the Visual Studio solution tree

It is weird that this doesn't happen with all types of Visual Studio projects, but only with Web apps. You have all those annoying .MySCMServerInfo files that pop-up in your check-in window and then cause errors because SCM knows they should not be checked in.

Enter StackOverflow with a really good solution: Hidding source control files within Visual Studio’s solution tree. No need for me to copy paste, just remember you need to restart Visual Studio for this to work.

Friday, September 11, 2009

Alan Turing and the gay thing

I didn't know about this, however, through a weird series of events, I have read about this in a book, then heard about it from a friend, then wiki'ed it and got really disgusted, then found it in the news, as the UK government finally issued an apology to one of the great men of computing.

Here is the government apology link and (apparently, the apology was too much for the Brits to leave on their web site for too long. Instead, you have to read the text from the historical archives of the government site here)another link from a blog I am reading which says just about what I was going to say.

I have to say that governments scare the shit out of me. The things they can do are so horrendous that most people refuse to think about it. And as the sleep of reason produces monsters, they usually become monstrous. After all, what are they than a big clump of responsability that every citizen sheds in order to feel good about doing nothing?

So, sorry, Alan Turing, for being part of the species that did this to you! I truly feel ashamed.

Update 24 December 2013: The UK government issued a pardon for Alan Turing. Posthumous, a gesture that would be rather pointless if it weren't for the chronic inability of authority to admit to their mistakes (not to mention actually pay for them).

Thursday, September 10, 2009

Can dogs speak?

We all know that dogs are smart. They understand verbal commands and can make complex decisions in new situations. However, they can't speak. Well, there are some weird rare cases of dogs sort of snarling "mama", but it's not real speach.

Right now, though, I've had an epiphany: dogs WON'T SPEAK, because they simply are not equipped to. They are smart enough to try and learn from their failures. However, the dog that lives next to my office now howls to the same notes as the ambulances that pass by the building. Also there are numerous cases where dogs are howling in the tune of a song they hear.

Now this is my idea: what if dogs are able of speach, just not human one? What if a properly constructed highly vocal and high pitched language would work for dogs? WE could not speak dog then, but we are smart, we have devices and computers and stuff like that.

Update: Having thought a bit more about this I have come to a conclusion. It makes sense that dogs should be able to communicate by howling. Duh! They are descended from wolves. They are still, genetically speaking, wolves. What about the barking? Wolves bark when they are pups. Somehow, the domestication process makes canides retain some youthful characterstics. Therefore, it only makes sense that they should be able of communication at a higher level through howling rather than barking. Although, dogs being smart as they are, it is only one hypothesis that needs proof.

My friend, Meaflux, by his own description "an anthropology buff", reminded me of the other "smart animals", the Cetacea order, whales and dolphins and such. They sing, they use high pitched wails (whails? :D) to communicate. I agree, it makes sense underwater, but since they are descended from a wolf like ancestor and since fish don't use this communication system, I would say there is a strong connection.

So, in conclusion, it is possible that the pack communication method of wolf howling combined with the millenia old dog interaction with humans could result, with some training, in sone sort of meaningful conversation skills? If only people working with dogs and apes would read my blog...

Wednesday, September 09, 2009

Weird Internet Explorer width behaviour

Today I've updated my computer with the latest patches from Microsoft and then, starting a project, I noticed that it didn't look right in Internet Explorer 8. For example a table with an empty td of width 1px looked as if having 4px. Setting it to 2px or above made it look of having 2px or whatever value I had chosen. I have solved the situation by adding content to the td in question (a simple &nbsp;), but before today I have not had this problem.

Update: This blog post was previously called "Microsoft updates breaking changes?" but in the meanwhile I have determined what the problem was. It was the zoom! I had my IE set to 75% zoom. That caused the weird behaviours and appearance.

The solution is still working, but the problem should be rephrased as "Why do the widths of td elements behave strangely when setting smaller zoom in Internet Explorer?".

Just for kicks I tried duplicating the problem using the zoom:75% style setting on body and, even if it looked bad too, it was a completely different behaviour.

Tuesday, September 08, 2009

Cannot add content of type '...' to an object of type 'System.Windows.ResourceDictionary'

You may get an error of the form Cannot add content of type 'System.Windows.Style' to an object of type 'System.Windows.ResourceDictionary' when working with WPF and your first reaction would be "What?! Why not!?". Well, the issue is very simple, only it stems from another source entirely: you've just tried to add a Style with the same key as another previously entered style.

Visualizing sound - Cymatics

First time I've ever heard of cymatics and I am intrigued. basically you use some (physical) devices to visualize soundwaves. Here is a small TED presentation about it:



My question is simple: can this be used to "understand" sounds for deaf people or are the pattern transitions too complex? googling for cymatics I've found a lot of videos about water and cornstarch moved by sound and links to "sound healing" and even some technical papers that never seem to have left academia. I think this could be interesting enough to emulate on a computer, yet I have not found code for it yet.

Saturday, September 05, 2009

Video Lan Player 1.0.1 buggy streaming over the web from command line

This is mostly a rant, but also it should help people trying to do this as well to stop trying until there is some sort of solution from the VLC side.

I was trying to see how a web cam can be streamed over the web using VLC, a software that otherwise am very satisfied with as a video player. Recently they did a 1.0.0 version, which is quite something for free software that comes from the Linux world; usually they are 0.8 something and with a lot of alpha-beta-zeta afterward. So, as I was saying, recently VLC jumped from the 0.9.x version to 1.0.0, with a much more user friendly user interface and (at least so it seems to me) less adaptability than before. What I mean is that, in extreme cases, it throws errors that previous versions were able to circumvent, like when using partial or damaged video files. Also, it crashes on some older videos as well and I am forced to use the ancient (but sturdy) mplayer.

Back to business, I read the comprehensive command line help file that is almost 250k long, found what I was looking for, then tried. No success. I really felt like an idiot, as it wouldn't work whatever I did. In the end I just gave up and tried to start the streaming from the GUI, not from the command line. IT WORKED! Copying the exact command line parameters that the GUI would generate did not work. Saving the WORKING streaming to a playlist and then loading the playlist DID NOT WORK.

Here I have to say two things: when I say that it worked, it means that I had to fight it to be able to stream what I wanted and not HOW I wanted. Basically, the streaming will not work AT ALL if transcoding is not activated, which I personally think it makes it unusable anyway.

So, bottom line is that if you are trying to use VLC 1.0 from the command line, you are pretty much screwed. At least the flag that I was interested in (--dshow-vdev) would not select my web cam if its life depended on it. And it sort of did. Not likely I will use VLC in my business application.

I've even tried to go to one of those old style PHP forums that they have on the Videolan site. I waited for half an hour to receive the registration email and at that time I had given up completely. They had like 60.000 messages on the forums anyway and I doubt I would have gotten a reply any more intelligent than the usual RTFM. Yeah, I know, I sound very Linux unfriendly, but actually I am not, I've worked on Linux quite some time. What I am not friendly towards are the borderline psychotic assholes that only answer when they have nothing to actually say to help.

Thursday, September 03, 2009

Making content not resize with its container in WPF

I believe this is something that any decent WPF programmer will laugh about, but there it is: I had this control derived from ContentControl and, of course, somewhere in the template I had a ContentPresenter. It all worked very well until I added a resizable option. I had two of these controls on the page, the first would contain a Grid, the other an ItemsControl. When I resized vertically the control, the ItemsControl would remain unchanged whether I made the height bigger or smaller. The Grid, though, would remain the same if enlarging the container and then squash when the size of the container got smaller than its auto size.

I have to say that I think my solution is really silly, but since it works: I've put a ScrollViewer control around the ContentPresenter in the my control template and then set its VerticalScrollBarVisibility to Hidden. This more or less is the same thing as setting overflow:hidden on the web.

Visual Studio external build commands weirdness

Short (but true) story: I was compiling this solution with a lot of projects in it. And one of these projects had some post-build events set to run which copied the resulting dll in an Assemblies folder. Only it failed.

On building the project I was getting an error: The command "[Complete command]" exited with code 1.

What was weird about it is that if I copied the command in a batch file and ran it, it would work perfectly. After trying a zillion things I've stumbled upon the condition of build events Run the post-build event: which was set to On successful build. I set it to Always and voila, it worked.

But I still needed to know what was going on, especially since it would make no sense to run the copy command if the build has failed. So I switched it back to On successful build. Surprize! It also worked.

Therefore, the silly solution for a problem that doesn't make much sense is to switch to always run the build events, build successfully, then switch back and build again. Fun!

Wednesday, September 02, 2009

Absolution Gap by Alastair Reynolds

Book cover
The fourth book by Alastair Reynolds that I've read recently, Absolution Gap follows the adventures of the ship Nostalgia for Infinity as it flees the "culling" of the Delta Pavonis star system by the swarm like machines called the Inhibitors. There is no purpose in reading the book without the others, as the story starts where it had left and continues to a more or less open ending.

This felt like the best book so far, however the enjoyment that I got from it had its very brutal ups and downs. While the beginning starts with full force and made me want to not let go of the book until I finish it, there was a side story that seemed not to have any connection with the main arc. When they finally met, they left me with that "What the fuck?" feeling. The ending was a jiggly up and down ranging from very cool and completely dumb. Not that the writing style faltered, but the behaviour of some of the characters really annoyed the crap out of me.

I would have to say that the ending was the most anticlimactic of all the books in the series, but the book is definitely the best yet.

Tuesday, September 01, 2009

I have extra 16px width or height in my web page!

Usually this happends in IE, but it may happen in a various other situations, given that Internet Explorer is famously bad, but also has to fight with all the backward compatibility and that new "innovative" browsers are on the way.

Let me make this easy: if it's a weird sixteen pixels difference (or somewhere around 16) then you probably are in one of these situations:
  • scrollbars - that you may not see, but they are there. I've just met this issue with a table of 100 percent width placed in a div of 100 percent width and it happened in IE8!
  • line-height - this is usually with Internet Explorer 6 or less, divs that are 16px in height when they have no content and have a specified lower height
  • font-size - also something from the older browsers