Sunday, August 30, 2009

News from the Mobile Front

Someone recently asked me where I lived.  This is a interesting question, since for the last year I have not really had a permanent residence.  I pretty much live out 5 suitcases and a plastic Tupperware tub.  After this gig is done in Portland I plan on dropping that to 4 suitcases and a laptop bag.

Since I live alone and travel alone I can travel pretty light.  Currently I have a extended stay hotel in Portland that I live in and rent by the month.  My current contract ends in May of 2010. At the time I will decide if I am staying in Portland or moving on.

My work is now pretty much contract work.  Go in take a gig for 3 months to a year and move on. I spent 10 years in Boise putting down roots, and I have no desire to do that again, so I am planning on staying mobile.   I also like the nature of contract work.  I can be very technical, solve the problem and move on.  No need for the politics of a company or the drama.  I enjoy the technical challenges of developing software, not so much the politics. 

As for my collections, when I lived in Boise I had a extensive CD, DVD and Book collection.  Around 5000 hard bound books, over 1000 music cd’s and over 1000 movies.  Now that I have pretty much gone mobile and all these collections are digital. 

I currently have over 40,000 digital books.  This includes books in EPUB and Kindle (mobi) format.  Both public domain works and books I have purchased.  As I mentioned before I really like http://oreilly.com/ for technical books since the have them in a variety of formats, but I also get a lot of technical books from APRESS as PDF’s and Amazon.com for my Kindle.  I try not to buy any physical copies, since those are hard to carry around :-).  Most of my older science fictions I get from Baen books.  Other books not available in EPUB format I but from Amazon.com and have them on my Kindle DX.  My current electronic book collection is a little over 15 gig in size.

I have over 12,000 tracks of mp3’s I buy from Amazon.com.  Most of these are classic rock, but I admit I  have some pretty weird albums in my collection :-).  I have my album collection stored on my two laptops, my 512 gig passport and finally the main copy is on my IPOD classic (120 gig). My current music, audio book and podcast collection is about 100 gig in size.

Movies I get through either net flicks or purchase them from amazons video on demand service.  My digital movie collection on Amazon.com is now about the same size as my old collection used to be.  Most of these I leave on the Amazon servers.  Only a few have I downloaded.

My software is stored as ISO images.  All my software from Microsoft I get from my TechNet subscription and store it as ISO images.  I then mount this using Magic Disc (a very cool utility that gives me a ton of virtual CD’s). If the software comes on a CD then where possible I take a CD and copy it to an ISO image and then mount the ISO image.  I store the CD’s in my CD case.  These are my biggest headache currently.  I am trying to get all my software digitally so I can get rid of the CD’s.  Sadly the biggest issue is the software CD’s for portability.  Sigh…

Email and document storage is all courtesy of Google apps.  I have several gigs of email on Gmail and am quite happy with it.  Everything else is stored on my laptops and my passport.  This combination makes it very easy to have all my primary files available digitally.  Digital pictures I keep on a a 16gig SD card and then stored on the passport and the IPOD.

So there you have it.  Over a year and most of my life is nothing but bits stored on local drives or in the cloud.  Kind of scary when I put it that way :-).

Sunday, July 12, 2009

Sony Ebook Reader or a book shelf of half a million plus…

I recently picked up a new gig in Portland at just about the same time as my Kindle died.  With the death of my Kindle I was looking for a new ebook reader.  The kindle2 was out but I really liked the specs on the KindleDX.  Problem was the DX was not going to be out for a while.  To aggravate the situation I now have a 45 minute commute into town on the train. 

Now don’t get me wrong, the train is a great way to go.  No traffic and I get some exercise walking back and forth to the train station (2 miles a day).   The problem is a 45 minute ride leaves me bored to tears.  My lifestyle is such that I no longer want to collect a ton of hardcover or paper back books.  I have over 5000 of these in storage in Idaho and don’t need anymore. The kindle worked great for me because all my books were digital and I could carry them around in my hand.  

I really wanted the DX, but those are all on back order and anyone who knows me knows I hate waiting for toys.  I decided to get a Sony PR700 series ebook reader for the short term.  I will still probably get a DX so I can read the Wall Street Journal on the way to work and because it is easier to read my PDF’s on.

I have started to collect a lot of ebooks and wanted to switch to a standard format that I keep my main library in.  I have standardized on the epub format because it is a open standard that has no DRM.  This means I can easily play with books in that format using .NET since an epub is simply a zip file containg a standard set of files a content in html.  These files include:

  1. A xml file containing the bibliographic data for the publication (title, author, publisher, etc…) in Dublin Core format
  2. A xml file containing the table of contents
  3. The contents of the publication in a series of html files
    So it is easy to build up a collection of EPUB files that are self contained and highly compressed.  The entire Gutenberg collection of 28000+ epub books takes less then 11 gig of space.  In addition, with Sony you have access to the entire Google library of over half a million public domain books (all in epub format).    I should stress here that it does not require a Sony reader to access this library. 

OReilly is publishing their books in EPub, PDF and mobi (Kindle) format.  So if you want to read Programming WCF Services on your Kindle, Sony or even IPhone it is easy enough to do. 

Finally the relevance to the title above.  You can download any of Google’s Library of EPUB books easily without owning a Sony reader (say you want to read them with Stanza on your IPHONE).  To do this:

  1. Download the Sony Reader from http://ebookstore.sony.com/google-ebooks/
  2. Register with the site
  3. Click on the Unearth a Classic link on the far right
  4. Search Google books for books of interest
  5. Download those you want

You may also get free science fictions in EPUB/Stanza format from Baen books, and there are other source all over the net.  Almost all of Project Gutenberg is now available in EPUB format.  I will be posting a mass downloading utility for Gutenburg in a later post that allows you to download all 38,000 plus epub books from project Gutenburg. 

So there you go.  EBooks have more then arrived, they have over run the competition :-).  Believe me my 40K+ ebook collection is much more portable then my 5000 book collection was (and is easier to search).

The only drawback I have discovered so far is no EBook reader on the market today can handle the collection I have acquired.  So like any good developer I am writing my own.  More to come on that later.

Darrel

Saturday, May 16, 2009

LINDUG: The LinkedIn .NET Users group

If you do not make your regular user group meetings, or don’t have a user group in your area, you may want to join the Linked .NET Users Group on www.linkedin.com.  It is a virtual .NET Users group of 24,000+ members.  They sponsor webinars and have some decent discussions. 

Some upcoming webinars include

For that matter you can always join the Elegant Code group on linked in.  If nothing else it keeps David out of trouble :-).

Friday, April 17, 2009

C Style operators in SQL Server 2008

I started off my programming career developing C applications.  This was primarily because I did my work on Mini computers running UNIX.  Almost unheard of at the time :-).  For the first 14 years from 1982 to 1996 I developed my applications in C.  During that same time frame SQL came along for relational databases.  Now I had SQL, C and Embedded SQL for C.  Throw in curses for developing screen applications and what more could a developer want? :-).

In late 1996 I began developing applications in Visual Basic 4, and found events.   Very cool.  But I still missed some of the features I had grown to love in C.

Recently I noticed the section on compound operators in SQL Server 2008.  This is interesting since these are the first new operators added to SQL Server in at least the last 8 years.  SQL server 2005 and SQL server 2000 both had the same list of operators.  Now Microsoft has added some new ones.  In addition adding the BackSlash operator is just a nice little bonus (now if I could just get my ternary operator (?:)).

I guess a good thing about starting my career developing C has been that all the new languages (including SQL server) are going back and picking up some of the concepts from C.  K&R should be proud :-).

New expression operations in SQL Server 2008 Tranasact-SQL

  • += (Add EQUALS) (Transact-SQL)
  • -= (Subtract EQUALS) (Transact-SQL)
  • *= (Multiply EQUALS) (Transact-SQL)
  • /= (Divide EQUALS) (Transact-SQL)
  • \ (Backslash) (Transact-SQL)
  • %= (Modulo EQUALS) (Transact-SQL)
  • &= (Bitwise AND EQUALS) (Transact-SQL)
  • |= (Bitwise OR EQUALS) (Transact-SQL)
  • ^= (Bitwise Exclusive OR EQUALS) (Transact-SQL)
  • ~ (Bitwise NOT) (Transact-SQL)

  • Thursday, April 2, 2009

    Some Themes and a Little Crimson and Gray

    image

    I have been working on themes for WPF and Silverlight applications.  I found this one for SilverLight and WPF.  It is called shiny red.  Gotta love that.  Nice bit of crimson and gray.

    As some of you know I am a bit of a WSU fan, so I love this theme.  They also have a couple of purple ones.  Needless to say I deleted those.  Pure evil they were… :-).

    Thursday, March 19, 2009

    On Further Review…

    Never mind.  Microsoft has a CTP of the 2.0 version of the Open XML SDK that does this much better.  Check out http://www.microsoft.com/downloads/thankyou.aspx?familyId=c6e744e5-36e9-45f5-8d8c-331df206e0d0&displayLang=en

    Wednesday, March 18, 2009

    Reading a Office 2007 docx file using C# and SharpZipLib

    I found myself needing to read a office 2007 docx file to get the xml of the document., so I went and got the ECMA spec for OfficeOpenXML. That is a heavy 1500 page heavy read :-).  So I decided to keep it handy and just write some code to see how bad it would be. So far it has not been as bad as I thought it would be so I thought I would post some code on it.  It has been a while since I have posted anything, so here goes.

    The docx file is actually just a zip archive of a bunch of files.  The trick here is to read the zip and pull out the content.  I decided I wanted to load the data to a class hierarchy so I could do some Linq to objects work with it.

    So I will start this with some simple code.  First the DocumentPart.cs class holds the document content and some information from it’s zip file.  The document content is stored as a linq to XML XDocument..

     

        1 using System;
        2 using System.Xml.Linq;
        3 
        4 namespace OfficeOpenXML.Package
        5 {
        6     /// <summary>
        7     /// A document part in the OfficeOpenXML Package
        8     /// </summary>
        9     public class DocumentPart
       10     {
       11         public string Name {get; set; }
       12         public string Comment { get; set; }
       13         public long CompressedSize { get; set; }
       14         public DateTime EntryDate { get; set; }
       15         public long Size { get; set; }
       16         public XDocument Content { get; set; }
       17     }
       18 }

    It is pretty basic so far (love those automatic properties).


    Now how do you read the zip file?  I use the SharpZipLib to read the zip file and then store each member of the zip archive into a dictionary of DocumentPart with the filename as the Dictionary key.

     

        1 using System;
        2 using System.Collections.Generic;
        3 using System.IO;
        4 using System.Text;
        5 using System.Xml.Linq;
        6 using ICSharpCode.SharpZipLib.Zip;
        7 
        8 namespace OfficeOpenXML.Package
        9 {
       10   public class Parts
       11   {
       12     public Dictionary<string, DocumentPart> DocumentParts { get; set; }
       13     public string FilePath { get; set; }
       14 
       15     public void OpenPackage(string filePath)
       16     {
       17         ZipEntry Entry;
       18         XDocument contents;
       19         StringBuilder XMLDocument;
       20         byte[] Buffer = new Byte[8192];
       21         int bytesRead;
       22 
       23         using (ZipInputStream Package =
       24           new ZipInputStream(new StreamReader(filePath).BaseStream))
       25         {
       26           while ((Entry = Package.GetNextEntry()) != null)
       27           {
       28             XMLDocument = new StringBuilder();
       29             while ((bytesRead = Package.Read(Buffer, 0, Buffer.Length)) != 0)
       30             {
       31               XMLDocument.Append(
       32                 ASCIIEncoding.ASCII.GetString(Buffer, 0, bytesRead));
       33             }
       34             contents = XDocument.Parse(XMLDocument.ToString());
       35             DocumentParts.Add(Entry.Name, new DocumentPart() 
       36               { Name=Entry.Name, Size=Entry.Size, 
       37                 Comment=Entry.Comment, 
       38                 CompressedSize=Entry.CompressedSize, 
       39                 EntryDate=Entry.DateTime, Content=contents });
       40           }
       41         }
       42     }
       43 
       44     /// <summary>
       45     /// Construct the class
       46     /// </summary>
       47     /// <param name="filePath">The office Open XML document</param>
       48     public Parts(string filePath)
       49     {
       50         FilePath = FilePath;
       51         DocumentParts = new Dictionary<string, DocumentPart>();
       52     }
       53   }
       54 }

    I use the using statement (on line 23) to handle the opening the docx file and then process the zip archive using the GetNextEntry.  The inner while loop (at line 28) reads the content of the entry into a string.  Finally while the DocumentParts.Add() adds the document dictionary. 


    A simple NUnit test (not exhaustive by any means) is:


     

        1 using NUnit.Framework;
        2 
        3 namespace OfficeOpenXML.UnitTests.Package
        4 {
        5     [TestFixture]
        6     public class PartTests
        7     {
        8         [Test]
        9         public void OpenPackageTest()
       10         {
       11             OfficeOpenXML.Package.Parts p = new OfficeOpenXML.Package.Parts();
       12             p.OpenPackage("../../TestData/AbilitiesandConditions.docx");
       13             Assert.IsTrue(p.DocumentParts.ContainsKey("[Content_Types].xml"), "No Content_Types?");
       14         }
       15     }
       16 }

    In my next post I will show how to use the information from the [Content_Types].xml entry and the docsprops/app.xml and docprops/core.xml files to create an object that has information about the document being read (using some Linq to XML to populate the Class).  


    Darrel

    Wednesday, March 11, 2009

    Red, Green, Re-factor

    I find my self getting more and more into the test driven development paradigm.  I am working on some fairly heavy OO code with a great requirement specification (it is actually and ISO standard).


    The application is growing pretty much via the unit tests.  Write the test, then make sure the code fits.  It is amazing how many times I am not sure how a piece of code is going to work so I just put together the unit test to fit the standard and then code the class.  I can then re-factor as needed.



    I am using the speech API’s to drive the interface so the speech api simply outputs a string of text that I can use to execute the program commands.  I wanted the program to be able to be both driven by speech commands and through the standard GUI approach.  Since I am working on a compiler, interpreter I have simply added the speech grammar as another grammar in the compiler.  .I will probably do the same to parse the command line options.


    Makes for some interesting code :-).

    Tuesday, March 10, 2009

    Not posting much lately

    I have been working on several projects.  They are starting to come to completion and I hope to post some more on them at the beginning of April.  I have also been busy with contracts and life in general, but I will get back to some posts in a few weeks.