Tuesday, August 31, 2010

A generator for random person names

During the creation of a project, I often need to generate test data to test the applications. Quite frequently this happens when there is (yet) no database backend available so I need to generate the test data directly inside the program.

Usually, this also involves test data of persons (or users, customers, suppliers etc.). Over time I really got sick of my imaginative creations like “AAA 1”, “ZRIQW 44” and of course the well known “sdsfghsdfj, sdf934md930”.

Thats why I have generated the RandomPersonNameGenerator class that uses the top 30 names from the 1990 census of the U.S. Census Bureau to generate random person names.

The usage is very simple:

RandomPersonNameGenerator rpGen = new RandomPersonNameGenerator();
List<RandomPersonName> list = rpGen.Generate(100);

foreach (RandomPersonName rpn in list)
{
    Console.WriteLine(rpn);
}

The result will look like this:

image

You can also use the static method and directly access one of the properties of the resulting RandomPersonName objects.

List<RandomPersonName> list = RandomPersonNameGenerator.StaticGenerate(100);

foreach (RandomPersonName rpn in list)
{
    Console.WriteLine(rpn.LastCommaFirst);
}

image

 

The class is released under the new BSD license. Enjoy!

 

using System;
using System.Collections.Generic;

#region License

//For an explanation see http://www.opensource.org/licenses/bsd-license.php

/*
Copyright (c) 2010, TeX HeX / Xteq Systems
http://www.texhex.info/ http://www.xteq.com/
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

  * Redistributions of source code must retain the above copyright notice, this
    list of conditions and the following disclaimer.
  * Redistributions in binary form must reproduce the above copyright notice,
    this list of conditions and the following disclaimer in the documentation
    and/or other materials provided with the distribution.
  * Neither the name of the Xteq Systems nor the names of its contributors may
    be used to endorse or promote products derived from this software without
    specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#endregion

namespace RandomGenerator
{
    /// <summary>
    /// This class is used to store a name and give easy access to the differnt parts of it.
    /// </summary>
    public class RandomPersonName
    {
        public string First { get; set; } //          Michael
        public string Last { get; set; } //           Hex
        public string Full { get; set; } //           Michael Hex
        public string LastCommaFirst { get; set; }//  Hex, Michael

        public override string ToString()
        {
            return Full;
        }
    }

    /// <summary>
    /// Can be used to easily generate person name like "Michael Taylor", "Lisa Smith" etc.
    /// All names are returned as a RandomPersonName object.
    /// </summary>
    public class RandomPersonNameGenerator
    {
        #region Name arrays
        //All these names (with slight modifications) retrieved from here:
        //
        //
http://www.census.gov/genealogy/www/data/1990surnames/
        //
        static readonly string[] _firstNameMaleSet =new string[] {
         "James", "John", "Robert", "Michael", "William", "David", "Richard", "Charles", "Joseph",
         "Thomas", "Christopher", "Daniel", "Paul", "Mark", "Donald", "George", "Kenneth",
         "Steven",  "Dirk", "Brian", "Ronald", "Anthony", "Kevin", "Jason", "Matthew", "Gary",
         "Timothy", "Jose", "Larry", "Jeffrey"
        };
        static readonly int _firstNameMaleSetCount = _firstNameMaleSet.GetUpperBound(0)+1;

        static readonly string[] _firstNameFemaleSet = new string[] {
            "Mary", "Patricia", "Linda", "Barbara", "Elizabeth", "Jennifer", "Maria", "Susan",
            "Margaret", "Melanie", "Lisa", "Nancy", "Karen", "Betty", "Helen", "Sandra", "Donna",
            "Carol", "Ruth", "Sharon", "Michelle", "Laura", "Sarah", "Kimberly", "Deborah", "Jessica",
            "Shirley", "Cynthia", "Angela", "Melissa"
        };
        static readonly int _firstNameFemaleSetCount = _firstNameFemaleSet.GetUpperBound(0)+1;

        static readonly string[] _lastNameSet = new string[] {
            "Smith", "Johnson", "Williams", "Jones", "Brown", "Davis", "Miller", "Wilson", "Moore",
            "Taylor", "Anderson", "Parker", "Jackson", "Norris", "Harris", "Hex", "Thompson",
            "Garcia", "Martinez", "Robinson", "Clark", "Rodriguez", "Lewis", "Lee", "Walker", "Hall",
            "Allen", "Young", "Hernandez", "King"
        };
        #endregion
        static readonly int _lastNameSetCount = _lastNameSet.GetUpperBound(0)+1;

        RandomPersonName GenerateOne(Random rndm)
        {
            int iRandomValueMale = rndm.Next(0, _firstNameMaleSetCount);
            int iRandomValueFemale = rndm.Next(0, _firstNameFemaleSetCount);
            int iRandomValueLastName = rndm.Next(0, _lastNameSetCount);
            RandomPersonName rpn = new RandomPersonName();

            rpn.First = rndm.Next(0, 2) == 0 ? _firstNameMaleSet[iRandomValueMale] : _firstNameFemaleSet[iRandomValueFemale];
            rpn.Last = _lastNameSet[iRandomValueLastName];
            rpn.Full = rpn.First + " " + rpn.Last;
            rpn.LastCommaFirst = rpn.Last + ", " + rpn.First;
            return rpn;
        }

        /// <summary>
        /// Returns a list of RandomPersonName objects.
        /// </summary>
        /// <param name="Count">Count of names that should be generated</param>
        /// <returns>List of RandomPersonName objects</returns>
        public List<RandomPersonName> Generate(int Count)
        {
            List<RandomPersonName> list = new List<RandomPersonName>();           

            Random rndm = new Random();

            for (int i = 0; i < Count; i++ )
            {
                list.Add(GenerateOne(rndm));
            }

            return list;
        }

        /// <summary>
        /// Returns a list of RandomPersonName objects (Static function)
        /// </summary>
        /// <param name="Count">Count of names that should be generated</param>
        /// <returns>List of RandomPersonName objects</returns>
        public static List<RandomPersonName> StaticGenerate(int Count)
        {
            RandomPersonNameGenerator rpng = new RandomPersonNameGenerator();
            return rpng.Generate(Count);
        }

    }
}

Thursday, August 26, 2010

Something is wrong with the version number

Maybe we could agree that it wasn’t a version number at all?

version

Friday, August 20, 2010

Error starting Error Reporting

Keep on trying Windows, one day you will succeed…

Error while using error reporting

Wednesday, August 11, 2010

Update or install Flash Player without DLM

As Adobe has released a new version of Flash Player today, I thought I should share how you can update or install Flash Player without using Adobe Download Manager (DLM).

Simply use the link for the browser you want to update below. You can also bookmark them as they will always return the current version.

[Update: Links have changed with Flash Player 11 – Thanks to Explorer]

For Internet Explorer:

32 bit (x86):
http://fpdownload.adobe.com/get/flashplayer/current/install_flash_player_ax_32bit.exe

64 bit (x64):
http://fpdownload.adobe.com/get/flashplayer/current/install_flash_player_ax_64bit.exe

For any other browser (Firefox etc.)

32 bit (x86):
http://fpdownload.adobe.com/get/flashplayer/current/install_flash_player_32bit.exe

64 bit (x64):
http://fpdownload.adobe.com/get/flashplayer/current/install_flash_player_64bit.exe


To test if the installation was successful and if you have the updated version, go to this page:
http://www.adobe.com/software/flash/about/

Wednesday, August 4, 2010

My rambling thoughts about smartphones

To be honest, this post was on my disk for nearly two months now. I have changed it often, but still I think it’s not complete. Anyhow, I doubt that will get any better so I’m publishing it.

 

As my current phone, a Samsung i780, is rather old I started to search for a replacement. I looked at the currently available phones both from a customer perspective as well as from developer view -mobile app development is still a very hot topic.

After all, it came down to the “big three”: Apple iPhone, Google Android and BlackBerry. As an extra, I also checked Windows Phone 7.

I didn’t know BlackBerry quite well but fortunately I have one here as a current client insisted that I use it while working on the project. This was the easiest decision of all: Looking at all the features it’s clear to me that BlackBerry is developed for big enterprises, not the normal customer. For app development, each paid application you submit will cost you 200$ (with 10 updates free). Once you have submitted 10 updates, you need to pay 200$ again. No, not the phone I was looking for.

 

For the Apple iPhone I think you can name it “Best phone with best vendor lock-in”. Without any doubt, the iPhone 4 has the best display money can buy, fits exactly in your hand, runs quite a long time on batteries and iOS is definitely mature. On top, you get the best filled app store around. So this should be a no-brainer, right? No.

Because if you move a little ahead, you end up being limited to what Steve Jobs thinks is good for you. This starts when you want to buy it: You can only get with a mobile phone contract from one vendor. Even if you sign this contract, you can’t simply exchange the SIM card as it has a SIM lock. And this is just the start: Replaceable batteries? No. SD card slot? No. Apps outside the app store? No. Developing apps with something else than Apples C/C++/Objective-C? No. Using cross compilers? No. Tethering out of the box? No. And so on.

There is actually good reason for Apple to behave like this: Profit (of course) and control of the platform. Although the iPhone Developer program is rather cheap with 99$, it isn’t what I was looking for. No Steve, I don’t obey. Please keep your iNo iPhone.

 

Moving over to Windows Phone 7: When the read the first report about Microsoft developing a new “iPhone rival” I have to admit I was really think that this will be my new phone. I really thought they will simply take the pieces Apple did right, remove all the stupid parts (all those “NO” entries above) and add some extra features.

After all, Microsoft should has all needed technologies at hand: Multi Touch (Surface), a great runtime with a sandbox (.NET Framework), a very good graphics engine (DirectX), a nice UI (XAML/Silverlight) and by the way: they are producing operating systems as well.

Well, these were my first thoughts but as now more and more details emerge, I’ve learned that Microsoft has completely copied the Apple way including all the great fails.

To start with that you can’t install apps outside the marketplace, that you have no access to an SD card (only for “extending the internal memory”, not for you to simply exchange data) and so on. Although there are some hardware partners, they are not allowed to extend the phone (e.g. HTC Sense or Samsung TouchWiz). If all hardware is basically the same, why should any vendor build a phone then? Remember, a lot of people buy an HTC device because of Sense.

No doubt that Microsoft has currently the most advanced combination of a good runtime (.NET/Silverlight etc.) with a very good development tool (Visual Studio) but with all these Apple fails build in? Nope.

 

Enter Google Android: An open-source smartphone OS released under an Apache license. As the licensing cost for the OS are nearly zero (OS is free, but some Google apps will cost the manufacturer something) it’s now wonder they are dozens of phones available. There is no form factor that isn’t available.

The app store is the second biggest in the world (70k vs. Apple’s 200k) but you are free to install applications outside the store. Heck, you can even create native applications and call them from your “normal” apps. Replaceable batteries, using any carrier, OS “enhancements”, tethering, cross compilers or SD card access? Yes, you can.

So this is happy land, right? Nope. Android isn’t mature so far. Everywhere you will come across little quirks and major bugs.

For example, there is no build-in setting to simple turn off mobile data in the night or after a given period of inactivity (There’s an app for that). The build-in calendar sometimes goes havoc if you change the synchronized accounts (need a “Clear Cache”) and can’t handle time zones. The music player can’t read MP3 tags correctly nor handle genres at all. Choosing a date using the build-in controls does not show you a calendar. A lot of apps are poorly written and will drain your battery in no time. And so on.

But from my point of view, the advantages of Android out weight the failures: I ordered a Samsung Galaxy S (I9000).

 

 

Final note: Why I always want the “Install apps outside the store” feature?

Because any review process is broken by design. For an example, read this.

And if you still believe that “Reviewing” an app is a good way to prevent “bad” apps, see this. When this was not noticed during the censorship review process, what else “under the hood” functions might exist in other apps?