Effects of a missing initializeBase call...

Posted on January 29, 2008 00:26 by Mamanze

Just ran into a very unexpected issue. I've been developing an app for the past two months, mostly AJAX work. Turn off debugging for the first time today to do a production deploy and boom, I get errors. Long story short, turns out that in debug mode, a missing initializeBase call doesn't really matter. ASP.Net Ajax must be doing the extra plumbing for me. In release mode though, the method call is required before the prototypes are flushed out.

 

So, if you do a release build and get the nice error that "a.beginUpdate is undefined', check your intializeBase calls.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

The danger of trusting Microsoft

Posted on January 21, 2008 15:47 by Mamanze

To enable some downloads the other day I placed https://*.microsoft.com into my trusted sites zone. All well and good, until I tried to log into MSDN subscriptions today. Follow along with me:

 

Step 1: Go to MSDN subscriptions homepage, http://msdn2.microsoft.com/subscriptions

Step 2: Hit sign on.

Step 3: Redirects to live to get passport credentials, https://something.live.com/somehing

Step 4: Credentials found (via live toolbar), redirect back

Step 5: Browser sent back to http://msdn.one.microsoft.com

 

Those paying close attention will notice that we've bounced from the Internet Zone to the Trusted sites zone and back to the Internet zone. Now, given that MS is great with security, ponder this: Does the site in step 5 have access to the passport credentials retrieved in step 4?

 

The answer would be no.

 

Great, what does it do then? Loop back to step 3. Indefinitely.

 

To make this even more fun, each time IE bounces between zones, it opens a new tab in the IE window currently configured to that zone.

 

I must say, my "kill IE as fast as possible" skills have gotten very rusty. Haven't had a need for them in a long time.

 

So, note to those out there willing to trust Microsoft: You must either trust them or not, no half measures.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Adhere to Common Standards

Posted on January 16, 2008 21:34 by Mamanze

Alright, I don't think it will come as a surprise to anyone who has worked with JavaScript for more than a few seconds that there's a long held standard of using camel case for names. Particularly, method names. Just take a gander at the DOM. Ok?

 

So why is it then that I keep seeing JS libraries that use Pascal Case for method names?

 

Particularly annoying to me of late is the Virtual Earth API. Can't tell you how many times my fingers have typed something in camel case only to have it break as soon as I debug. Argh!

 

While I don't think all standards are golden, not following something simple like this is just stupid.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

QT: Virtual Earth Tip

Posted on January 16, 2008 09:17 by Mamanze

Make sure the container is visible before calling LoadMap(). I was trying to pre-load the map into a popup... no workie, it couldn't figure out where it was ;)

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Consulting

Posted on January 14, 2008 08:29 by Mamanze

Consulting is usually a tough business. Not many of us last long. Most of the time, we're being beaten down by frustrations, whether our own or our clients'. In the 4 years I've been consulting since leaving college, I've never left a project that fit all of these:

  • Client is happy
  • I am happy
  • Project is complete
  • Project is successful
  • I am satisfied with the result

Until yesterday that is. 60% is pretty common. 80% less, but has still happened a few times. This is the first time for 100% though.

Hasn't quite sunken in yet.

Woot!

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

QT: Free, Simple Icon Extraction

Posted on January 12, 2008 13:21 by Mamanze

Combo of tools:

 

1) Batch Icon Extractor: http://www.rw-designer.com/batch-icon-extractor

Pass the DLL path as a command line parameter and it'll extract everything to ./icons

2) Paint.Net with Icon file type plugin: http://paintdotnet.forumer.com/viewtopic.php?t=1152

Allows Paint.Net to open any icon file.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Outlook Ruler

Posted on January 10, 2008 13:53 by Mamanze

I tend to mix my mouse & keyboard usage. I'm not strictly mouse, and not strictly keyboard, but somewhere in between. I invariably end up abandoning the mouse once I've got the window I want open to a point where I can use the keyboard for everything else. Abandoning the mouse though can be a problem.

 

Normally this is fine, but once in a while, the place where I just abandoned the mouse has special meaning in the popup. Take for example the Outlook Message Window's Ruler. I just did this for the 100th time. I click a message in the folder item list, switch to keyboard, hit ctrl + F and start typing. Unfortunately, once in a while, the place where I left the mouse corresponds to the something like the ruler expansion area. Now, that _should_ be fine but being that A) it is a slick animation and B) outlook is now searching for contacts (because I've started typing into the recipients field) , outlook comes to a near complete stop until both operations are complete. Now, why these two would fight for the same resources I'm not sure, but there it is.

 

Anyone else noticed this behavior? Wish we had a proper outlet for these frustrations...

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

ToBase16()

Posted on January 9, 2008 14:44 by Mamanze

Useful snippet, converts a byte array to base 16:

 

public static class Extensions {
	public static string ToBase16(this byte[] input) {
		return string.Concat((from x in input
				    select x.ToString("x2")).ToArray());
	}
}

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

A Couple Useful Controls

Posted on January 9, 2008 01:06 by Mamanze

Ran into a scenario today where I needed to add a base tag to my page. Couldn't find a clean way to do it with the stock asp.net controls, so created a couple quickies:

 

public class HtmlEmptyControl : HtmlControl {

	protected override void Render(HtmlTextWriter writer) {
		writer.WriteBeginTag(this.TagName);
		this.RenderAttributes(writer);
		writer.Write(" />");
	}
}

Very simple, just renders an empty element (self closing tag). Code there is borrowed from the HtmlLink control.

 

public class HtmlBase : HtmlEmptyControl {

	public override string TagName {
		get {
			return "base";
		}
	}

	public string Href { get; set; }

	public string Target { get; set; }

	protected override void OnInit(EventArgs e) {

		Uri requestUri = Page.Request.Url;

		string relativePath = Page.Request.CurrentExecutionFilePath;
		string relativeRoot = VirtualPathUtility.GetDirectory(relativePath);

		UriBuilder baseUri = new UriBuilder() {
			Scheme = requestUri.Scheme,
			Host = requestUri.Host,
			Port = requestUri.Port,
			Path = VirtualPathUtility.AppendTrailingSlash(relativeRoot)
		};

		this.Href = baseUri.ToString();

		base.OnInit(e);
	}

	protected override void RenderAttributes(HtmlTextWriter writer) {

		if (!string.IsNullOrEmpty(this.Href))
			this.Attributes.Add("href", this.Href);

		if (!string.IsNullOrEmpty(this.Target))
			this.Attributes.Add("target", this.Target);

		base.RenderAttributes(writer);
	}
}
 

A self initializing base tag. Usage like so:

 

this.Page.Header.Controls.AddAt(0, new HtmlBase());

 

Which I just threw in my Master Page's OnPreRender. This is useful for cases where the request's PathInfo starts with a / (i.e. page.aspx/foo/bar).

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

WCF & Json - Complete Output Control

Posted on January 7, 2008 01:46 by Mamanze

One issue I've run into a couple times while working on restive WCF messages is the need to have complete control over the output. For example, when I wanted to generate a custom proxy for my rest service, I wanted to take over the /jsdebug UriTemplate and output plain JS (not JSON).

 

When I initially wrote that proxy generator, I used some reflection to hack the XML Writer into doing what I needed. Then, digging around the JSON Error Handlers, I noticed the framework had an internal class to output raw text. What it boils down to is:

 

Byte[] buffer = Encoding.UTF8.GetBytes(messageBody);

writer.WriteStartElement("Binary", string.Empty);
writer.WriteValue(buffer);
writer.WriteEndElement();

 

Unfortunately, they take a very difficult route of doing that. To ease things, I've created this RawMessage class which wraps up a string and spits it out in raw format:

 

 

Hopefully that'll save someone a few minutes in the future.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5