Test your C#: Generic overloaded constructors

I love languages.  Here's one for a language nut.

public class Response<T> {

    private T result;
    private string error;

    public Response(T result) { this.result = result; }
    public Response(string message) { this.error = message; }

}

 

You can use this generic class as a wrapper for returning data.

return new Response<int>(1000);

Or to return an abnormal result

return new Response<int>("Something has gone wrong");

 

Question 1

The fun part then, is what happens when you have this?

var result = new Response<string>("Is this a result or an error?");

What is result

 

Question 2


What about this:

public class Sample
{
    public static Response<T> GetSample<T>(T arg)
    {
        return new Response<T>(arg);
    }
}

and then:

var result = Sample.GetSample("Is this an error?");

What is result

Re: Sorry dad, you'll understand, someday

This is a quick blog post, in response to Zac Gorman's excellent Magical Game Time comic.

http://magicalgametime.com/post/19718347285/ill-stop-when-ive-saved-the-world-and-fallen-in

As you play through the game Earthbound as the kid protagonist Ness, your phone would ring every few hours, and your dad would ask you if you'd like to take a break.  If you say Yes, it'd save the game and switch it off.

The comic cleverly replies as Ness: I'll stop when I've saved the world and fallen in love.  (Sorry dad, you'll understand someday).

 

My boy is still three, he doesn't understand about saving the world, or falling in love, yet.  I'm sure he will soon.  And here'd be my response to him:

  • All dads were boys once.
    We already understood.
  • So off you go, save the world.
    Go and fall in love with your girl.
  • You do what you have to do.
    This is your time, we don't expect you to hold back, or stay at home.
  • When you are tired from saving the world, stop by and have some hot chocolate and ice cream.
    We will always be your biggest fan.

 

We will return to our regular SharePoint updates soon. 

AUSPC 2012 quick update

I'm in the strange and calm interlude between day 1 and day 2 of awesomeness in the annual Australian SharePoint Conference (AUSPC) 2012.

Day 1 has been a lot of fun.  Manned the user group booth in the morning with Dan Brown.  Met many of the SharePoint guys in the community that I haven't seen for the last 6 month to a year.  Talked to a number of vendors, and attended a number of awesome sessions on the developer track.

I also got to sit on the panel answering developer questions amongst the legends like Nick Hadlee, Ishai Sagi, Brian Farnhill and Jeremy Thake

The oddest part is probably with MCA SharePoint Wayne Ewington sitting in the audience.  Every time we said something silly he'd start shaking his head and we'd all stop.  Hilarious.

 

Tomorrow morning, my session on Building your own custom REST Service and consuming them with jQuery AJAX is running in the developer track at 10:30am.  Hope to see everyone there.

All my related resources and presentations on this topic are summarized on /rest

Dummy guide to install Win 8 on VHD for Boot to VHD

 

Summarized from:

You'll need:

 

Set up boot to VHD!

  1. Create a VHD

clip_image001

clip_image002

Note: I make this a dynamic disk, although I allocated up to 60GB, it only uses what it needs which was about 10 GB.

 

clip_image003

clip_image004

clip_image005

clip_image006

clip_image007

clip_image008

clip_image009

Created, and attached the VHD to Y:

 

Load the ISO into a virtual CD drive, mine is G:

I use virtualclonedrive to load ISO - this is a free utility.

clip_image001[5]

 

Next install the windows image into the VHD

Easiest way that worked for me is this wonderful powershell script.

 

clip_image001[7]

Remember to unblock this script

 

If you see:

File C:\Install-WindowsImage.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about_signing" for more details.

You will need to allow remote script

PS C:\>set-executionpolicy remotesigned

 

PS C:\> .\Install-WindowsImage.ps1 -WIM G:\sources\install.wim

Index   Image Name

[1]     Windows Consumer Preview

Done.

PS C:\> .\Install-WindowsImage.ps1 -WIM G:\sources\install.wim -Apply -Index 1 -Destination Y:

PS C:\> .\Install-WindowsImage.ps1 -WIM G:\sources\install.wim -Apply -Index 1 -Destination Y:
Applying "Windows 8 Consumer Preview" to Y:...
WARNING: This may take up to 15 minutes...

Elapsed Time: 00:08:40.4870618

PS C:\>

 

Lastly, make the VM a boot record.

 

PS C:\> bcdboot Y:\Windows\
Boot files successfully created.

 

You can check it with bcdedit

PS C:\>bcdedit

Windows Boot Loader
-------------------
identifier              {default}
device                  partition=Y:
path                    \Windows\system32\winload.exe
description             Windows 8 Consumer Preview
locale                  en-us
inherit                 {bootloadersettings}
custom:17000077         352321653
osdevice                partition=Y:
systemroot              \Windows
resumeobject            {1abc7489-8e4b-11e0-877a-af036ca44d2f}
nx                      OptIn
custom:250000c2         1
detecthal               Yes

Windows Boot Loader
-------------------
identifier              {current}
device                  partition=C:
path                    \Windows\system32\winload.exe
description             Windows 7
locale                  en-US
inherit                 {bootloadersettings}
recoverysequence        {1abc7482-8e4b-11e0-877a-af036ca44d2f}
recoveryenabled         Yes
osdevice                partition=C:
systemroot              \Windows
resumeobject            {1abc7480-8e4b-11e0-877a-af036ca44d2f}
nx                      OptIn

 

Restart and you are off to go

 

Your PC will boot into Windows 8, which has a new happy looking boot loader.  If you feel the 30 second delay is too long, you can change the delay to 5 seconds from the boot loader options.

Curiosity drives creativity. The only limit for your kid are there because you put them there.

I watched this YouTube recently, Neil DeGrasse Tyson was being interviewed and was asked a question: what would you do as a nation to increase scientific literacy.

Neil's answer:  What do you do at home?  What do you do with your kids?  Kids needs to be able to explore freely.  The home, he argues, is not a great place for exploration.  Play in the toilet?  No.  Garage?  No.  Kitchen?  No, no, no.

The kid goes to the kitchen and starts to bang pots together, you tell him to stop.  The consequence of stopping a kid, is stopping a kid from exploring.  The seeds of curiosity are the foundations of science.  The parents need to get out of the way. 

If the kid pulls petals from a  $10 flower you bought from the florist, but discovers an interest in biology.  That's the cheapest $10 you've ever spent on his education!

 

iPad, and Technology

fernbedienung2.jpg (700×503)Many of us marvelled at our children being able to pick up an iPad and use it right away.  We say surely this is proof of Apple's solid design principles, even a three year old kid can master this technology at ease.

That may be the case, but I've beginning to really wonder.  When was the last time you let your kid explore your keyboard?  He's banging and breaking your keys?  If you don't let him experiment, how would he know what banging the keys together does? 

Mr 3 presses the back button on the iPad.  It quit his favourite game.  He knows for certain that is NOT the button he wants to press when he is playing his favourite game.

I got a new Samsung LCD TV, it comes with an extremely complicated remote control.  Mr 3 learned how to use it to get to his cartoons in the morning and switch to Simpsons in the evening before sleep.  He can even switch input sources between HDMI (XBox) and normal Digital TV channels!  Look at this thing: My kid can operate this, can you?

 

Dungeons and Dragons, and story telling

I was convinced that he will enjoy playing board game, and in particular, dungeons and dragons with me. 

Lots of parents are doing this.  A game that you can play with your kid, and helps them on mathematics, story telling, spelling, imagination.

Considering that he is still wet behind the ears, I opted for D&D-lite: HeroQuest.

WP_000443

He is three.  He is playing his dwarf hero here, trying to cheat the dice roll because he knows he needs to get "skulls" on the dice to hit the Ogre.  Along the way, he has already fought off:

A goblin, an orc, 3 chaos warriors - one whose helmet is now stuck in the fireplace, and 1 skeleton.  The goblin had a pretty nasty bump on the head - he says the goblin shouldn't sleep on the floor because it's dirty.  We put him on the table, and use the empty treasure chest as a pillow.

  • I asked him as he comes near a door - do you want to open the door?
  • He says: Yes, open the door, see what's inside.
  • I put down a skeleton
  • He says: Skeleton! 
  • I asked him, what are you going to do?
  • He says: Run away - and proceed to yank the dwarf all the way back to the beginning.  I had to stop him and tell him that he can fight by rolling the dice.

Dungeon Master tip for dads:

If your kid is running low on HP, make sure he "finds" a healing potion next time he searches a table, door, monster's dead body.  Don't make things too easy, but don't get them killed.

 

I'm realizing something

This is probably my take home message and something I'll try to remind myself my whole life.

Your kid knows no limits. 

All the limits in his life, are put there by adults

 

People tell him he can't try to do something.  He can't go somewhere.  He isn't tall enough to go on a ride. 

The box on HeroQuest says ages 7+.  Did that stop Mr 3?  Who puts these age limits on game boxes?

You know, I hope it's not yet too late.  I ask him to do something, and he tries, but he fails, and he tells me:

I can't do it

It breaks my heart.  No, it's OK, you can.  Try again, I'll help you, let's try again.

 

Let your kid paint their room

This is something I've read separately, and actually got Lina to agree:

We will leave the interior decoration of our kid's room to himself.  Within his room, he can paint his walls.

We're in a new house.  He is free to paint anywhere on the walls in his room.  Why limit him?  Re-painting his wall is easy.  But the memories and his creativity being cultivated - those are absolutely priceless.

 

Say less No.  Say more Try

This is so much easier to write than to live.  When your kid is being silly and driving you crazy, can you really hold back on the No?

John, let your kid try.  Say less NO, say more TRY.