From No Clue to 3 Websites with Django in 1 week

I started “40 hours ago” without much knowledge of Python or Django (I had played with both for a couple hours a while back). Now I have three mini-sites using the Django framework live.

Thus, my first few experiences with Django on Python have been remarkable. Read the rest of this entry »

LamongeRe Launched

In addition to a real crunch at the day job, I have tried to put in a few hours every week to finish up another project. That’s why there have been no new posts. It will be pretty quiet around here for another month or so until we wrap up major milestones at my employer. But for now, go check out the new map-based MLS real estate search at www.lamongere.com.

Model Katja Jung

This is a little off-topic: My sister just announced that she started a blog! She works a a model on the side while going to med school to become a pediatrician. I guess the blog’s purpose is to stay in touch with her fans. The blog is in German, so if you can read German, check it out: http://www.katjajung.de/blog/.

Posted in none. Tags: . No Comments »

javascript img src

People keep searching for “javascript img src” … maybe this is what they’re looking for:

How to create an image DOM element dynamically and place it on the page

There are many ways of doing this, here’s one in a code snippet:

<html>
<body onload="LoadImage();">

<div id="ImageContainer">
An image will go here:<br />
</div>

<script type="text/javascript">
//<![CDATA[

function LoadImage() {
	// get a reference to the DIV into which we want to put the image [1]
	var container = document.getElementById("ImageContainer");

	// create a new image element [2]
	var anImage = document.createElement("IMG");

	// when the image is loaded, attach this image element to the container DIV
	// (but not earlier) [3]
	anImage.onload = function() {
	 	container.appendChild(this);
	}

	// set the image to load [4]
	anImage.src = "http://www.google.com/intl/en_ALL/images/logo.gif";
}

//]]>
</script>

<body>
</html>

What’s going on:

  • When the page is done loading, a JavaScript function to load the image is called.
  • [1] This functions gets an object reference to the DOM node of the DIV container to hold the image when it’s loaded.
  • [2] It then creates a new Image element DOM node, that is not yet part of the page’s node tree (and therefore does not get displayed).
  • [3] The onload handler for that node is created as a function that simply attaches the loaded image to the container. Note that this is essentially asynchronous programming: This function does not get executed until the image has been completely loaded (which may be never!). This function also uses what is called a closure over the variable context as it was defined when the function was created, meaning that all the variables outside of it’s function body are available inside, for example container.
  • [4] (Almost) as soon as an image URL is assigned to the image, the browser begins loading it.

The function defined in [3] will always execute after [4].

Posted in none. No Comments »

Detect IE6

Since people keep looking for this, here is how you can identify IE 6 (and IE 6 only):

<script type="text/javascript">
//<![CDATA[
var is_ie6 = (
	window.external &&
	typeof window.XMLHttpRequest == "undefined"
);
//]]>
</script>

This is reliable and even Opera is not pretending to be IE6 with this check. This is mostly useful to determine whether the PNG/Alpha Image Loader hack needs to be applied.

Posted in none. Tags: , . No Comments »

Real Productivity & How Not Having ReSharper Really Hurts

Synopsis: ReSharper is a productivity-improving tool for Visual Studio. NOT having it really hurts after getting used to it.

As part of our team evaluation, I have been running ReSharper for the last month. Even though it improved my daily coding routine, I was not able to quantify whether it would be worth the money to buy a license to run it on Visual Studio for me and/or others in the team.

Then we decided to move to Visual Studio 2008 a few days ago. The migration worked fine for everyone except me. I was getting a really weird exception from ReSharper when trying to edit comments. There was also a problem with the key mappings. The only option for me to continue work properly was to uninstall ReSharper.

Now I know how much it really hurts my productivity to not to have this tool.

ReSharper isn’t perfect, by all means. Besides the bug described, it does not execute the NUnit 2.4-style GlobalSetup steps in unit tests, which means I cannot use their beautifully integrated unit testing tools. This has been a known shortcoming for over a year and the fact that JetBrains is not in a rush to fix this worries me. Sometimes I also get stuck in the parameter list popup, which hijacks my cursor keys and cannot be closed with ESC–but maybe that’s just a user error.

But there’s a lot to like: The code quality analyzer running on an open file is very helpful. I made it part of my coding quality process to only commit files that pass the analysis and have the green little square in the upper right corner. The refactoring support is decent (certainly better then what comes with Visual Studio).

I cannot wait for them to fix the comment bug so I can continue using it. There are not any real alternatives to Visual Studio when it comes to .Net and C# development. I would guesstimate that my productivity is down 20% without it (which does not include long-term effects from having lower-quality code because of my oversights that ReSharper’s analysis process would have caught).

The Eclipse Difference

I should note that if I were developing in Java, I would not have any of these problems. Eclipse does most of what the Visual Studio/ReSharper combo does, some of it better. And it’s completely free. Alas, we’re not using Java for this project and–quite frankly–I am currently more fond of C#/.Net for various reasons …

Sooner or later, I will host this blog myself …

… and am making this mental note here for my own purposes: WordPress Configuration

Posted in none. Tags: , . No Comments »

Unit Testing: Allowing Access to Internal Members of Types in Another Assembly

Create a Friend Assembly by adding [assembly: InternalsVisibleTo("Other.Assembly")] in AssemblyInfo.cs to allow that Other.Assembly access to this assembly’s types’ internal members.

Good object-oriented design involves guarding access to members of types appropriately. Part of a domain object’s state may only be mutated by other types in the same assembly (for example during creation). Those members will be protected with the internal keyword (in .Net).

This causes issues when trying to achieve 100% coverage during testing. Unit tests are usually located in another assembly (even if the namespace is shared for simplicity). That unit test assembly will not have access to the internal members and therefore some important states of a domain object cannot be tested. Assume you have the following domain object assembly:

// assembly Acme.Model
namespace Acme.Model
{
  public class Stuff
  {
    private List _data = new List();
    public ICollection Data { get { _data; } }
    internal void AddData(string data)
    {
       _data.Add(data);
    }
  }
}

We want to test the above class with 100% coverage, meaning we have to get Data added to it. The associated unit test would pretty much look like this, but not compile, because of the inaccessible internal member:

// assembly Acme.UnitTests.Model
namespace Acme.Model
{
  [TestFixture]
  public class TestStuff
  {
    [Test]
    public void TestData()
    {
       Stuff stuff = new Stuff();
       stuff.AddData("data"); // this is not going to compile
       Assert.AreEqual(1, stuff.Data.Count);
    }
  }
}

Declaring a Friend Assembly is a very quick and simple fix for this problem. In Acme.Model’s AssemblyInfo.cs, just add the following line at the end:

[assembly: InternalsVisibleTo("Acme.UnitTests.Model")]

For more on that topic, see Friend Assemblies on MSDN.

Building My Own HDTV Antenna

Synopsis: The self-made antenna worked–for my friend. HDTV antennas are just conventional UHF/VHF antennas. iTunes may turn out to be the cheapest solution for our viewing patterns.

The Self-Made Antenna Experiment

Like any scientist, I consider all experiments carried all the way through a success, even if one negates my initial assumptions and expectations. It is even better if new insights can be gained. In that context, I had success with my DYI HDTV Antenna.

The coaxial cabling in my house is so bad that I cannot receive standard TV channels properly on my HDTV. The latest season of Lost has just started & the wife wants me to make TV happen. My options were

  1. calling the cable company to fix it (accompanied with the hollow threat that I would switch to FIOS if they didn’t, which I had attempted several times but given up on after Verizon’s online application was not able to recognize my address and their sales interactive voice response system gave me a 15-minute run-around asking for my [non-existing] Verizon phone number) or
  2. buying a commercial HDTV in-house antenna.

I picked option 3, which was to build my own antenna according to the instructions in this video on MetaCafe:
Coat Hanger HDTV Antenna

Since I was fresh out of coat hangers, baluns and various other hardware, I spent about $15 on materials from various places, which I considered a decent price to pay for some fun. A friend of mine and I then commenced to leisurely put the antenna together whilst taking care of the kids (the latter causing this to be an hour-long project).

I had purposefully kept my expectations low about whether this contraption would work, so I was positively surprised when the HDTV tuner picked up 20 HDTV channels on our second attempt (after having “straightened out” a few parts of the antenna that apparently were causing some problems). The 11 religious & church channels among those channels found came in crystal-clear without skipped frames, pixelization or missing sound. We were not so lucky with the major networks’ channels, though and even after several more minutes of tweaking the antenna and moving it about the living room, we had to concede defeat (on that end). All the important channels had such poor reception that we often saw nothing but a “receiving data” message that would not go away or the dreaded “no signal” message. If we got a picture, it was a still frame that refreshed every minute with many artifacts. There was no sound.

How could it be that half of the channels found had no issues while the other half was pretty much unusable? I asked my friend to take the antenna with him to his Portland East-Side home and try it there, just to get another data point (of view, literally) for the experiment.

He called the next morning with the good news that for all but two channels, our self-made HDTV antenna was performing better than the commercial, amplified HDTV antenna he had bought a while ago. He gave me his old, commercial antenna to see whether I would have more luck with it (which I didn’t).

Where’s The Tower?

It dawned on me that the awkward location of my house on the south side of a hill in South-West Portland may have something to do with the poor reception. After few minutes of research I found the location of TV transmitters for several major Portland-area networks, which is at the Sylvan Ridge in the West Hills at the corner of SW Barnes Road and SW Skyline Blvd (Map View). The FCC provided a helpful resource to find TV stations, channels and transmitters. Consumer Electronics Association’s AntennaWeb is also helpful for selecting antennas. You can plug the longitude and latitude for locations found into Google Maps using the following format: 45° 31′ 14″ N, 122° 44′ 37″ W (the first one is the latitude, the second the longitude).

Using Google Earth I discovered that even though the towers are only 4.5 miles directly north of my residence, there’s a hill blocking the line-of-sight. I would have to erect a 70 feet tall tower to get line-of-sight.

Electro-magnetic ground-effects can be funny. I once tried to get a high-speed wireless Internet connection over a distance of only 3 miles, but there was a little bump in between the radio tower and my office location. The technician doing the site survey said that even though the station was in line-of-sight, the bump messed with the signal sufficiently enough for it not work. More details about this can be found here: Fading & Multi-path Interference

So, What Now?

In order to overcome the signal limitations I have to deal with, I would have to spend some serious money on a mast and at least two highly directional, high-gain antennas. That’s not really an option, for aesthetic reasons alone.

I will probably call the cable company and have them fix everything. My drop is almost 100 feet long and its using regular R6 when it should be R11. I am just concerned about losing my Internet connection and not getting it back.

In order to get cable HDTV, I would need to pay $6.50/month extra with Comcast and still have to watch commercials during shows.

Maybe the convenience is worth the small premium over all this hassle and iTunes ends up being the best deal? But it’s not HDTV, so I am not sure …

Sweet Memories

This whole experience reminded me of a time during my childhood, growing up in socialist East Germany. The West Germans (and presumably Americans) had put powerful terrestrial TV and radio antennas along the border between East & West Germany, blasting the signal as far into “enemy territory” as they could. East German engineers (privately) devised antennas and amplifiers to pick up those signals.

Together with our duplex neighbors, we put a 10 feet tall mast on top of our 20 feet tall house and attached several 6 to 10 feet long high-gain antennas with amplifiers to it. We then would align the antennas in the direction of the approximate location of the “capitalist” radio & TV towers, turn on the TV, tune for the channel (by hand!) and then slowly move the antenna in 1/4 inch steps (or smaller) until the signal was clear. We would repeat that for each of the 3 (or 4?) antennas. After every major storm.

The towers from which we received the signals were over 80 miles (127 km) away.

Outsourcing with Elance, Guru & GetAFreelancer.com

Different freelancer networks have different strengths (duh!). Use them in combination.

I have been using Elance in the past to invite other people to help me on projects. Now I had a very urgent fulfillment request from one of my clients and needed some business research done in less than 3 days from posting the project to final delivery. For all web development-related projects I posted on Elance in the past, I had received bids within minutes of making the project description public, but no-one responded to this research request within a few hours. So I decided to give two other places I knew about a first chance: Guru & GetAFreelancer.com.

I got bids on both within the first hour or so and ended up with 5 or more bids on each. Both providers in the U.S. and abroad had similar prices, with the top-rated ones all bidding essentially the same amount (at the upper end of the limit I had set for the project). I found both sites more cumbersome to use than Elance, but GetAFreelancer seems to have a lot more provider diversity and Guru is more established and mature. GetAFreelancer also makes the buyer pay for transaction fees, which I find inappropriate. But maybe the margins for providers are better there and therefore the providers more motivated? The future will tell.

The real proof is going to be in the pudding, which will be delivered by the end of tomorrow. Lets see whether the project winner can meet expectations. My success with Elance providers has been “mixed.”

Update: The provider I picked with Guru delivered decent work. Not quite what I expected for the money I paid, but the client was happy (which is really all that counts). I read recently (I wish I’d remember where) that in order to successfully delegate, I will have to accept that the job is only going to be done 80% as good as if I had done it myself and account for that gap. In this case it was close. I got maybe 60% to 65% of what I asked for (partially because of the tight deadline), so I had to fudge it a little to make it work.

This experience also teaches me that I need to “train” the client better to not to ask me for stuff “last minute”.