Sep
30.
2005

Another day, another year...

Posted by: Drazen Dotlic in Categories: general.
Tags:

age++;

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
1 Comments
Sep
27.
2005

Distributing (HD) content

Posted by: Drazen Dotlic in Categories: rant.
Tags:

Quite an intriguing piece over on Marc Cuban's blog about what's gonna be the best way to distribute the content (audio or video) in the future. Many interesting points (check out the part about the vending machines) but I think some of his claims are not based in reality.

The core of Marc's post is that in the future, the best way to deliver content to consumers will be through hard drives due to the constantly increasing storage requirements for a movie. HDTV requires about 18GB per hour for a really good quality. You can't put that much content through the net nor can you put enough movies on a DVD and could squeeze only one  movie or so on a next gen DVD standard.

I agree that HDTV is the future (for some it is already a present) and that most future content will be HD. However I don't see people being that much obsessed with quality. If quality was a number one concern Beta would win over VHS in no time. Heck, look at a recent battle between HD-DVD and Blue-Ray: even though the latter is technologically better the former is cheaper and has easier upgrade path.

What I see as the future is still the 'net. It is the easiest way to deliver content to the consumer and modern distribution channels like P2P are much better than any kind of unicasting techniques. And the quality? Well, let's have a look at what kind of quality you can get through popular P2P networks. While testing my BitTorrent client I ran into what seems to be new quality bar these days - one episode of a TV series encoded from HDTV signal downsized to 960x528 (XVID, essentially a MPEG4) with AC3 2.0 sound. Great quality, fits on one 700 MB CD. Current gold standard (most of the TV episodes are encoded like this) seems to be 624x352 XVID with MP3 audio, also encoded from HDTV source, fits to half of a 700 MB CD. Very good quality.

What we need is a way to legalize the distribution over the Internet. It is quite feasible to distribute full movie with HDTV resolution (1280x720) and AC3 5.1 sound  using a secure P2P platform in a matter of hours. ADSL2+ brings speeds of over 20Mb for prices close to 30-40€ range. P2P already consumes about 33% (at least!) of all bandwidth and it can't all be the music - only video content can consume that much so the need is obviously there.

Forget hard drives - give people good enough content for a decent price and see how it goes.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
0 Comments
Sep
18.
2005

Another interesting Ruby feature should eventually become available in C# and VB.NET. Consider the following Ruby code (from the book Programming Ruby):

module Summable
  def sum
    inject {|v,n| v+n }
  end
end
class Array
  include Summable
end
[ 1, 2, 3, 4, 5 ].sum -> 15

The idea is that in order to overcome Ruby's single inheritance you can group code in modules and just include it in your classes - the methods automatically become member methods of the instances of your class (the situation is actually a bit more complicated and detailed discussion is out of scope of this blog post).

In order to achieve this in C# we'd have to use LINQ preview (therefore this functionality is not going to be available for quite some time) and write something like this:

static class Summable
{
  public static int Sum(this IEnumerable<int> arg)
  {
    int s = 0;
    foreach(int i in arg)
      s += i;
    return s;
  }
}
// new int[] { 1, 2, 3, 4, 5 }.Sum() -> 15

Several things are important to note here. First, we have to struggle with generics in order to generalize a bit the extension method(s). Second, due to the relatively narrow choice of generic type(s), I couldn't have written

T Sum<T>(this IEnumerable<T> arg) where T:??

because you can't assign 0 (zero) to any T and you can't use += operator on any T. At the same time, you can't find suitable type to replace question marks as well, so we are stuck with "hard-coded" ints. Ruby allows for any type that supports + operator.

I can only guess that a VB.NET version could actually be pretty close to Ruby and allow for more flexibility at the cost of runtime evaluation (and possibly error whereas with C# you are guaranteed a compile time error if there is any).

Either way, using early or late bound style, this is cool as it allows yet another simple but powerful way to extend functionality of your classes without inheritance. In fact (I just tried) it allows you to extend sealed classes with new methods!

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
0 Comments
Sep
18.
2005

I have recently discovered that VB.NET already* supports duck typing and without resorting to generics too boot. The solution is purely dynamic, just like with Ruby. Here's the analogous code sample I've been using in my other post about duck typing:

Class Customer
    Dim _first_name, _last_name As String
    Public Sub New(ByVal first_name As String, ByVal last_name As String)
      _first_name = first_name
      _last_name = last_name
    End Sub
    Public Sub append_name_to_file(ByVal file)
      file &= _first_name & _last_name
    End Sub
  End Class

I used different operator here (&) but the point is that file parameter has no type declared, is not implicitly treated as Object and is dynamically checked for existence of said operator (&). Quite cool.

*Tested with Visual Studio 2005 which will be available in 7 weeks. I think this won't work in 2003 (at least not in this manner).

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
0 Comments
Sep
17.
2005

Surreal video of my heart

Posted by: Drazen Dotlic in Categories: general.
Tags:

Due to the tragic history of heart diseases in my family and some recent chest pain I was feeling my wife finally persuaded me to do some check-ups. I ended up doing three test the last one of which was the most detailed one. Basically they insert a tiny tube into you, push it all the way to the heart and then pump contrast liquid and take pictures/videos to see if all your arteries are OK. I was relieved to find out that I'm just fine. At the end of the test I got a CD containing videos they took during the exam. This video is the proof that I have a heart ;)

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
1 Comments
Sep
16.
2005

Contests everywhere

Posted by: Drazen Dotlic in Categories: general.
Tags:

It seems like just yesterday Microsoft's Channel9 PDC coding challenge finished only to be followed by numerous Visual Studio related contests. Now we even have MSN, Web services and Windows Vista contest. It's a great season for developers who have some free time and are competitive. Let's see:

  1. Larkware coding contest, build something using Visual Studio 2005 (RC just came out) by the launch date (November 7th) and you could win several expensive developer software packages
  2. MSN Messenger world's best app, if you have l33t DHTML skills build something using Messenger Activity API and you could win a cool Alienware laptop and Visual Studio 2005 Professional
  3. Microsoft/Amazon Web Services Developer contest, build something cool using Visual Studio 2005 and Amazon Web Services and you could win $5000
  4. NewsGator API developer competition, use NewsGator API to build a cool app and you could win a cool Dell/Mac laptop
  5. Virtual Earth competition, use Virtual Earth API and build something cool and you could win $1000
  6. The Code Master challenge, build a Windows Vista app and win a piece of $125000 (!) in prizes; not all details are known yet and contest starts beginning 2006

Whew. If I had 48 hour days I guess I'd manage to build something for at least some of these :). I did compete in Channel9 challenge and am most likely to participate in Larkware coding contest, still undecided about the rest.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
0 Comments
Sep
14.
2005

I just run into a problem trying to call a Windows API from Ruby and wanted to document it here so that me and others can benefit from the solution. I was trying to call a Windows API using the excellent dl (I guess it stands for "dynamic load") module (comes with Ruby). Here's the code sample:

require 'dl/import'
module NTKernel
  extend DL::Importable
  dlload "kernel32.dll"
  extern "int GetStdHandle(int)"
end
#get the handle of the standard output
result = NTKernel.GetStdHandle(-11)

Just standard stuff, nothing fancy. MSDN documentation helps with the API declaration and constants. Based on all we know, this should work, no?

Not quite. Ruby has a convention where all methods start with lowercase letters, and dl library silently respects this by renaming GetStdHandle into getStdHandle - ouch!

It took me some time to figure this out - I had to use reflection to see which methods are defined for my module (you can get a list of methods for a class or module by calling methods method).

So the call that works is actually NTKernel.getStdHandle(-11).

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
1 Comments
Sep
13.
2005

With all the craze surrounding PDC 2005 and availability of many downloads (RC of Visual Studio 2005 is already available!) for both MSDN subscribers and general public it is now appropriate to improve upon the ruby script that validates MSDN downloads using Microsoft provided SHA1 hash. This time I have added the ability to provide a text file with the list of file names and hashes to validate. The format of the file is simple:

full_path_to_file_for_validation|hash_lowercase

In order to use this file you call msdnh like so:

msdnh.rb --list list_file_name.txt

Script is slightly bigger than the last time:

require 'digest/sha1'
def validate(file, hash)
  hsh = Digest::SHA1.new
  File.open(file, "rb") { |f| hsh << f.read(1024*1024) while !f.eof? }
  if hash.downcase != hsh.hexdigest
    puts "Hashes do NOT match, file '#{file}' is invalid."
  else
    puts "Hashes match, file '#{file}' is valid."
  end
end
if ARGV.length != 2
  puts "Usage: msdnh (--list file_with_list | file_to_hash hash_as_hex)"
elsif ARGV[0] == "--list" && File.exist?(ARGV[1])
  File.new(ARGV[1], "r").readlines.each { |line| validate(*line.split('|')) }
else
  validate(ARGV[0], ARGV[1])
end

Enjoy!

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
0 Comments
Sep
12.
2005

There has been a lot of commotion regarding mapping online and the tools that should allow us to do great things. However, most if not all of these tools/maps have poor coverage. Unless you live in the USA that is in which case you'll enjoy great detail and excellent imagery.

I vote that Virtual Earth and similar products get renamed to Virtual USA until we get decent maps of the rest of the world. I'd really like to play with the API that Microsoft is exposing but I can't use USA maps only - I have no idea what to look for there. If there were European maps (and similar to that people in Asia can probably use better maps of their locale) that would be a different story.

Actually Microsoft has had excellent support for at least road maps in Europe in the shape of the MapPoint and similar products. Why can't we have at least that?

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5
0 Comments
Sep
9.
2005

I should have known - tasks like this are well suited for script/dynamic languages. So today I give you MSDN hash validator in Ruby:

require 'digest/sha1'
if ARGV.length != 2 then puts "Usage: msdnh file_to_hash hash_as_hex"
else 
  hasher = Digest::SHA1.new 
  File.open(ARGV[0], "rb") { |f| hasher << f.read(1024*1024) while !f.eof? }
  if ARGV[1].downcase != hasher.hexdigest then puts "Hashes do NOT match, file is invalid."
  else puts "Hashes match, file is valid."
  end
end

It's not much shorter than C# version - main savings are that there is less "usings" (called "require" in Ruby) and the fact that SHA1 hasher can spit out hex string of the hash directly. C# version saves on not having to load bytes and stuff them in the hasher but Ruby stays one-liner here thanks to it's blocks, iterators and "while" modifier.

Be the first to rate this post

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