Posts
17
Comments
28
Trackbacks
1
August 2008 Entries
MacBook Air Software Update

Apple has issued a software update that is expected to solve a problem which was in my opinion the worst issue with MacBook Airs. When my MacBook Air gets hot, specially while watching videos, one of the processor cores gets shut down while the other one sticks to 100% usage and in activity monitor, there is an item called "kernel_task" that seems to be eating up CPU cycles. I personally think it's a driver bug that gets triggered as the system gets hot. Today, I opened up Software Update and I was amazed to see an update for this bug which has been disturbing me from the beginning. I just installed it and I'm going to stress test my laptop to see if it is effective or not.

posted @ Saturday, August 23, 2008 10:36 AM | Feedback (0)
Compression and Encryption

Implementing applications that communicate over the wire imposes many challenges to the developer. You suddenly have to think much more about the security and performance of your application. To protect data from unauthorized use, we can encrypt it. In .NET, classes that deal with cryptography were available since the first release. In order to improve the performance while transferring data over low-bandwidth channels, we'll compress it. Fortunately, classes that help us with compression has been shipped with the .NET Framework since version 2.0. In many cases, we want to compress and encrypt data at the same time. Moreover, they're all based on streams, so it's very easy to plug them together as demonstrated by the following code snippet:

using System;
using System.IO;
using System.IO.Compression;
using System.Security.Cryptography;

class Program
{
    static void Main(string[] args)
    {
        using (FileStream inputStream = new FileStream(@"D:\Desktop\blog.xml", FileMode.Open))
        using (FileStream outputStream = new FileStream("Output.out", FileMode.CreateNew))
        using (DeflateStream compressor = new DeflateStream(outputStream, CompressionMode.Compress))
        using (CryptoStream encryptor = new CryptoStream(compressor, 
            new RijndaelManaged().CreateEncryptor(), CryptoStreamMode.Write))
        {
            byte[] buffer = new byte[2048];
            int count;
            while ((count = inputStream.Read(buffer, 0, buffer.Length)) != 0)
                encryptor.Write(buffer, 0, count);
        }
    }
}

As you can see, the output of the encryption algorithm is passed to a compression stream and it outputs it to a file. This code works correctly, but is it the ideal way to do so? The answer is no. It's not the correct way of doing so. There's an important thing you should make sure of when you're compressing and encrypting data in general. You should compress data before encryption. Why? Let's take a high level look at how they work. Most compression algorithms are based on recognizing redundant patterns in the input and replacing them with smaller tokens. They usually use Huffman coding in some way to accomplish this task. Achieving a good level of compression is all about good level of pattern recognition. Compression ratios also depend on the nature of input data since if there are no redundant sequences, there'll be nothing to replace. A characteristic of a good encryption algorithm is that you should not be able to distinguish its output from random data. After all, it's their goal to ruin every possible pattern in the output. Did you notice a theme here? The output of a good encryption algorithm is the worst input you can feed to a compression algorithm! Compressing encrypted data usually increases its size. The above code should be written as:

using (FileStream inputStream = new FileStream(@"D:\Desktop\blog.xml", FileMode.Open))
using (FileStream outputStream = new FileStream("Output.out", FileMode.CreateNew))
using (CryptoStream encryptor = new CryptoStream(outputStream, 
    new RijndaelManaged().CreateEncryptor(), CryptoStreamMode.Write))
using (DeflateStream compressor = new DeflateStream(encryptor, CompressionMode.Compress))
{
    byte[] buffer = new byte[2048];
    int count;
    while ((count = inputStream.Read(buffer, 0, buffer.Length)) != 0)
        compressor.Write(buffer, 0, count);
}

This is essentially the same code snippet with the order of encryption and compression reversed. I compared the size of the output file generated by running different methods on a 44KB XML document:

Original document 44KB
Compressed only 12KB
Encrypted only 45KB
Compressed then encrypted 12KB
Encrypted then compressed 68KB

It'll make a huge difference if you switch the order of encryption and compression. Never compress encrypted data. It's basically useless.

posted @ Tuesday, August 19, 2008 5:16 AM | Feedback (2)
Visual Studio 2008 and .NET Framework 3.5 Service Pack 1 Released

The past few days have been terrific from a .NET developer standpoint. To make devs have more fun, Microsoft just shipped the final release of Visual Studio 2008 and .NET Framework 3.5 Service Pack 1which is much more than a simple update. There are some new features in areas such as WPF, data abstraction, ....

Another thing that's worth mentioning is the availability of .NET Client Framework which is a stripped down version of the full .NET Framework (just like J2SE/J2EE). It helps deployment of client applications by reducing the framework's footprint.

You can download the service pack here.

posted @ Monday, August 11, 2008 12:58 PM | Feedback (0)
SQL Server 2008 is out!

After the long wait (well, not as long as 2000-2005 wait) Microsoft finally released SQL Server 2008 to manufacturing.

SQL Server 2008 is built upon the solid and well-celebrated SQL Server 2005 foundation and adds many new features specially tailored for the newest trends in the industry. My favorite is the spatial data type support. SQL Server is now much more suitable for GIS applications. For example you can now natively write queries to find the cheapest gas station in 5 miles! Ain't it amazing?

I'm currently considering to migrate some of our about to release projects to SQL Server 2008.

Long ago, I skimmed the new features of SQL Server 2005 and I'm planning to write a summary of cool new features in SQL Server 2008 soon.

You can download SQL Server 2008 RTM Trial here.

By the way, SQL Server Express is now available in native x64 version (previously, it had to be run under WoW64 subsystem).

At the end, I want to thank SQL Server team at Microsoft that did a great job providing a high quality (SQL Server 2008 is really stable and well-tested) release.

posted @ Thursday, August 07, 2008 2:26 AM | Feedback (0)
Monolingual - Remove Unnecessary OS X Resources

Mac OS X is a bloated operating system. When an operating system wants to support different architectures and different languages all in the same software package, on the same disk, it has no other choice to duplicate resources for different CPU architectures and different languages. It cannot do magic so it takes up your valuable disk space (it's specially valuable if you're using a MacBook Air with a Boot Camp partition, not to mention the 64GB SSD version).

Fortunately, there's a solution for this problem that will effectively free up your disk space by removing unnecessary languages, keyboard layouts and binary code from you applications and the operating system.

An open source project named "Monolingual." does the task painlessly and reliably. I haven't had any problems with it so far.

posted @ Monday, August 04, 2008 3:03 PM | Feedback (0)
Blog, Blog Server, Blog Client

When I was going to start this blog, I was looking for a good blog engine to run. I looked at several .NET blog engines and I couldn't find one suitable for a personal blog. Most of them are offering much more functionality than I need for a simple blog. I preferred a simple, elegant blog engine and none of them offered this simplicity and elegance. Even the Persian blog engine I personally wrote which will hopefully be released soon, doesn't bring the simplicity I liked. In fact, it's not their fault. They have to be full featured engines supporting many users, multi-author blogs, user customizable templates and much more. I want to have full control on my blog so free blog providers were out of choice. I decided to write a very light and simple blog engine myself for my personal use. Since I didn't have spare time to do so, I decided to install community server and use it for a while until I write my own engine. I haven't had enough time to do so yet and I'm still going with it. As I remember, community server was started from ASP.NET forums open source project by a then-Microsoft employee named Rob Howard (I remember he was mostly the ASP.NET caching guy) who left MS and started to develop community server. From a simple forum project, it grew to support blogs, gallery and much more for a multi-user environment and now it's really a big project. As a side note, I remember many of the ideas and patterns that are now part of ASP.NET itself started from that forums project (like roles, membership, data provider pattern, etc.).

I hate writing blog posts in a browser. I like Windows Live Writer very much and I really wish there was a similar thing on Mac OS X for free. If I have enough time, after I wrote my light blogging engine, I will write a blogging client for Mac OS X Leopard and possibly iPhone OS 2.0.

By the way, I know this blog looks like crap in Firefox. It has something to do with the theme used. I don't know if it was broken from the start or I broke it. I primarily use Safari on Leopard and IE7 on Vista and it looks OK on them. I agree this is unprofessional but it doesn't worth fixing as I want to rewrite the engine from scratch. I promise I'll support Firefox on my own engine. Until then blame everything on community server guys :)

posted @ Monday, August 04, 2008 12:57 PM | Feedback (0)