Monday, January 30, 2012

How to add syntax highlighting to Blogspot posts

Sorry, I didn't have time to create a "how-to", but the link for the Syntax Highlighter is here: http://alexgorbatchev.com/SyntaxHighlighter/

And here's a random post I just pulled up on Google that should show how to set it up (I didn't actually read it, heh): http://www.bloggermint.com/2010/02/how-to-add-syntax-highlighter-for-bloggerblogspot/

PowerShell: Lock/Unlock Site Collections

Simple enough: locks or unlocks sites (change the -LockState flag to either relfect "ReadOnly" or "Unlock"). Faster than changing the Delta value on a content database to prevent new sites from being created...

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
$webApp = Get-SPWebApplication "web_application_name_here"
foreach ($site in $webApp.Sites)
     {
          for($i=0; $i -lt $site.AllWebs.Count; $i++)
          {
               // Set to "ReadOnly" to lock; "Unlock" to unlock.
               Set-SPSite -Identity $site -LockState "Unlock"
          }
     }

PowerShell: Reset all sites to default site definition

This PowerShell script will reset all sites within a site collection in SharePoint 2010 to t heir default site definition file. Very handy after doing a migration from MOSS 2007 to SPS2010, if you run into pages being broken due to formatting, etc.

// Will reset all sub-sites in a site collection
// to their default site definition.

$sitesToReset = @("http://contoso.sharepoint.com/")

$sitesToReset | ForEach-Object 
    {
 // Don't wait for user input.

        $DebugPreference = "SilentlyContinue"
        $web = Get-SPWeb $_

        $DebugPreference = "Continue"
        
        Write-Debug "Reghosting all pages in site ($($web.Url))..."

 // Reset definition.
        $web.RevertAllDocumentContentStreams()

 // Dispose site object.
        $web.Dispose()
    }

Friday, January 27, 2012

PowerShell: IISRESET Multiple Web Servers

The following script will perform an IISRESET.  Use this to reset Internet Information Services on Windows 2008 Servers with the Web Server role enabled.  It is best to run it on one of the servers, and not from your desktop (unless your account has Administrator or Power User rights to the server).

##########################################################################
###                                                                    ###
###     Array contains the server names.  Change these if needed.      ###
###                                                                    ###
##########################################################################
FILENAME = "MASS-IISRESET.PS1"
[Array]$servers = "Web_Server_1","Web_Server_2"
foreach ($server in $servers)
{
 Write-Host "Restarting IIS on $server..."
 IISRESET $server /noforce
 Write-Host "$server IIS Status: "
 IISRESET $server /status
}
Write-Host IIS has been restarted.  Sites will be up in a moment.

Monday, January 23, 2012

Chapter 3, Thoughts.

Chapter 3 was interesting to me in a number of ways.  While all but one topic of discussion was something that I had learned previously, I found it great that the book delved into basic exception handling and type casting, which I think are important to cover early on.  This also allows students to learn the way it "should" be done, rather than coming up with their own round-about solutions.  For instance:

// Convert the Ultimate Answer To Life, The Universe, and Everything from string literal to decimal.
            try
            {
                ultimateAnswerToLifeTheUniverseAndEverything = decimal.Parse(HitchhikerGuideToTheGalaxy.Text);
// Display the number '42'
                MessageBox.Show(ultimateAnswerToLifeTheUniverseAndEverything);
            }

Can be worked around by just showing the .Text field in the MessageBox, which of course means that you cannot really "work" with the answer as a number of type Int/Float/Decimal/Double, but rather just "show" it:

// Convert the Ultimate Answer To Life, The Universe, and Everything from string literal to decimal.
            try
            {
// Display the number '42'
                MessageBox.Show(HitchhikerGuideToTheGalaxy.Text);
            }

I am especially impressed by them introducing the

            try
            {
                // Try statements here.
            }
            catch (Exception errMsg)
            {
                // Catch exceptions, handle error.
            }

statements before introducing statements like IF/THEN/ELSE and SELECT CASE:

// IF/ELSE/THEN example:
    static int Example(int myVar)
    {
 if (myVar == 0) // myVar is equal to 0.
 {
     return -1;
 }
 else if (myVar <= 10) // myVar was less or equal to than 10.
 {
     return 0;
 }
 else  // myVar is not equal to zero, and not less than 10 (meaning it was greater than 10).
 {
     return 2;
 }
    }

// SELECT/CASE/SWITCH Example:
 switch (myVar )
 {
     case -1:  // myVar was equal to 0.
  MessageBox.Show(myVar);
  break;
     case 0:  // myVar was less or equal to than 10.
  MessageBox.Show(myVar);
  break;
     case 2:  // myVar was greater than 10
  MessageBox.Show(myVar);
  break;
 }
    }

Most tutorials/books that I've read usually teach If/ELSE/THEN, move into a SELECT/CASE (in C# it uses the "switch" statement, I guess, and THEN get into Try/Catch. I wonder if this book covers boxing/unboxing (similar to type casting, but instead of casting a specific type for a variable, it converts the value type to a reference type.  Mainly used when an object's parameters require it, but we don't care about the "type" of the parameter). I should probably just read ahead, but I haven't had the time!

Tuesday, January 17, 2012

Installing Visual Studio 2010

Just a quick tip, although I'm sure everyone has already installed VS2010 on their home computers:

If you're hurting for hard drive space, or just don't want the (notoriously long) install of Visual Studio 2010 to take forever, be sure to UNCHECK the options for languages that we won't be using: F#, J#, Visual Basic, JScript, etc.  Also be sure, when installing the SDK (Software Development Kit) and Documentation, that you reflect those choices here as well.

Rather than taking close to an hour to download the documentation and updates (especially if you have a slow internet connection), it should take no longer than 15 to 30 minutes at maximum (on an average cable connection).

Review: Chapters 1 & 2

Class,

Overall, there wasn't anything in these two chapters that I had not already learned before.   I've been in the programming, hardware, and system administration areas as both a hobbyist and a professional so long, that all of this stuff has been hammered into my skull on multiple occasions.

Our first two programming assignments seem good for the novice to gain familiarity with moving between design and code views of a project, as well as creating event handlers for objects on the form.  Again, something I already knew, but I can see how this can help new programmers learn more about what event handlers can do, without having to create them by hand (as in other languages).  I remember my first experience with them in Visual Basic 6: forcing the user to use the "exit" button by having the event handler for the program close by clicking the "x" in the corner of the window, or any other reason, not work.  It would throw a Messagebox.Show("Please use the Exit button to close this program.") instead.

When I read our first assignments, anticipation sparked when reading the title of "Latin Translator" and "Orion Constellation", as I love languages, and am an amateur astronomer.  Ideas went floating through my head about possibly using the Google API to gain access to http://www.google.com/translate in order to create an application that would translate and display phrases...and then I realized that it was only three words that needed translation.  Maybe later, eh?

The "Orion Constellation" program piqued my interest, however there was a mistake made with the star names, so I made the necessary correction and went back to doing math homework ;-)  The star labeled "Meissa" is actually the star "Bellatrix".  Meissa is the "head" of Orion, and if you draw a line from Betelgeuse to Bellatrix, and then intersect that (forming a cross) by drawing a line up from Alnilam, Meissa would be an arcsecond or two (about 1/6 of an inch on our image) above that Betelgeuse/Bellatrix line, sitting on the Alnilam line.  Hope that makes sense ;-)  Ha!

Birthday Pizza: Pick Your Favorite

Kindergartener Parents:

Please use the poll at the top of my blog to make a choice for which style of pizza you and your child(ren) would like at the birthday party.  If you do not prefer any of the listed types, please contact me via the email listed on the birthday invitation card.

Have fun,

- Ken

Sunday, January 15, 2012

Quiz and Exam Questions

Greetings, Class.

Did anyone happen to find some of the answers to the Study Guide (Quiz, Optional) or Exam for chapters 1 & 2 as being incorrect, when they were correct? 

I've e-mailed Ms. Mah through WebStudy with a list of 5 that I found (the only 5 that I missed, as it were), but wanted to ask if anyone else ran into this problem.  I gave her references to the book that verified my answers as being correct, but just wanted to make sure that I'm not insane.

Then again, it's almost 3:30 AM...