Archive for November, 2007

Envy Code R coding font v0.7 preview

November 2007 – May 2008 Fonts (, , ) • 10,166 views • 14 responses

Envy Code R font preview #7 highlighting some of the characters in a chart.The next version of my Envy Code R font especially designed for programming (monospaced, easily distinguishable characters) is nearing completion and represents a very response-driven update to feedback, specifically:

  • ReadOnly, Greg Jandl: Comma clarified and change applied to full quotation marks, semi-colons and various accented letters
  • Adrian Bool, Greg Jandl: The slash on the zero has been redrawn to be less heavy
  • jxp: The Euro symbol has been redrawn from scratch
  • Aristotle Pagaltzis: Braces are more curvy and a full set of box-drawing characters have been added
  • IRC: Hash sign with longer legs

I have also fleshed out a number of additional symbols and accented letters that has seen the number of code pages supported increase to 12 pages and made a large number of tweaks to the italic version which was a last-minute addition to 0.6 (PR6) and had a number of errors especially round the accented letters.

Of course what you really want to know is how the new version looks in Visual Studio with that lovely Humane theme of mine:

Envy Code R font at 10 point in Visual Studio 2008 with my Humane theme.

There is still some work to do on the sizes above and below 10 point (again) as well as fleshing out a few more symbols, letters and italicising additional letters such as a curly k and rounder e which I hope will be finished towards the end of this week.

The observant followers may have noticed a pixel has been shaved off the vertical height which now brings it in line with the bitmapped Envy Code B coding font. I had intended on making the change for some time and the box characters practically demanded it to ensure the centres were whole pixels and not off-centre but some people may not like it…

A newer version of Envy Code R is available.

[)amien

Shrinking JS or CSS is premature optimization

November 2007 – December 2007 .NET (, , ) • 1,319 views • 7 responses

Rick Strahl has a post on a JavaScript minifier utility the sole job of which is to shrink the size of your JavaScript whilst making it almost impossible to read in order to save a few kilobytes.I thought I’d take a quick look at what the gain would be and fed it the latest version (1.6) of the very popular Prototype library:

File (KB) GZip (KB)
Standard 121.0 26.7
Shrunk/minified 90.5 22.0
Saving 30.7 4.7

The 30.7 KB saving looks great at first glance but bear in mind that external JavaScript files are cached on the client between page requests and it looses some appeal.If you also consider the fact that most browsers and clients support GZip compression and the savings there are around 4.7 KB and you might wonder if you are wasting your time.In computer science there is a term for blindly attempting to optimize systems without adequate measurement or justification and that term is premature optimization.As Sir Tony Hoare wrote (and Donald Knuth paraphrased)

We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil.

And he was working on computers throughout the 60′s and 70′s that had much less resources than those today.By all means if your server bandwidth is an issue delve into the stats, identify the cause and take it from there. Going with Yahoo’s YSlow plug-in for Firefox/Firebug is a great starting point but remember to analyse the statistics from your own context.

Rick’s tool had shortcomings with non-ASCII characters such as accents, symbols and non-US currency symbols which goes to show how optimization can have other unintended and undesirable effects.

[)amien

Calculating Elf-32 in C# and .NET

November 2007 – October 2009 .NET (, , ) • 1,702 views • 4 responses

Because you can never have enough hashing algorithms at your disposal this one is compatible with the elf_hash function that forms part of the Executable and Linkable Format.

using System;
using System.Security.Cryptography;

public class Elf32 : HashAlgorithm {
   private UInt32 hash;

   public Elf32() {
      Initialize();
   }

   public override void Initialize() {
      hash = 0;
   }

   protected override void HashCore(byte[] buffer, int start, int length) {
      hash = CalculateHash(hash, buffer, start, length);
   }

   protected override byte[] HashFinal() {
      byte[] hashBuffer = UInt32ToBigEndianBytes(hash);
      this.HashValue = hashBuffer;
      return hashBuffer;
   }

   public override int HashSize { get { return 32; } }

   public static UInt32 Compute(UInt32 polynomial, UInt32 seed, byte[] buffer) {
      return CalculateHash(seed, buffer, 0, buffer.Length);
   }

   private static UInt32 CalculateHash(UInt32 seed, byte[] buffer, int start, int size) {
      UInt32 hash = seed;

      for (int i = start; i < size; i++)
         unchecked {
            hash = (hash << 4) + buffer[i];
            UInt32 work = (hash & 0xf0000000);
            if (work != 0)
               hash ^= (work >> 24);
            hash &= ~work;
         }
      return hash;
   }

   private byte[] UInt32ToBigEndianBytes(UInt32 x) {
      return new byte[] {
         (byte)((x >> 24) & 0xff),
         (byte)((x >> 16) & 0xff),
         (byte)((x >> 8) & 0xff),
         (byte)(x & 0xff)
      };
   }
}

[)amien

Publishing .NET applications with prerequisites

November 2007 .NET (, , ) • 1,011 views • no response

Now .NET 3.5 is shipping I took the opportunity to update one of our internal applications and elected to have it install the necessary components (in this case the .NET Framework 3.5) using the Download prerequisites from the same location as my application option.

When trying to install the application via the IIS web server the installer would fail with a download error.

A little testing later I realised the publishing mechanism had placed .msu and .msp files for prerequisites onto the server and of course IIS 6.0 does not serve unknown MIME types.

Both .msu and .msp extensions must be added into the MIME database as application/octet-stream via MMC.

And all was well again.

[)amien