<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-6011603498138679949</atom:id><lastBuildDate>Fri, 17 May 2013 19:36:09 +0000</lastBuildDate><category>VBScript</category><category>MSSQL</category><category>DLR</category><category>CSS</category><category>Cloud Computing</category><category>Library</category><category>WP7</category><category>XML</category><category>Bookmarklet</category><category>Parallel Programming</category><category>Windows</category><category>Fun</category><category>ZXing</category><category>Watin</category><category>OSS</category><category>XAML</category><category>AWS</category><category>Testing</category><category>Interop</category><category>Poker</category><category>Regex</category><category>userscript</category><category>PowerShell</category><category>Parallel</category><category>Tips n Tricks</category><category>HTML</category><category>Data Binding</category><category>Tools</category><category>WTF</category><category>Hardware</category><category>PopUp</category><category>CyanogenMod</category><category>Samsung</category><category>Cookies</category><category>JavaScript</category><category>IronPython</category><category>Servers</category><category>Android</category><category>Video</category><category>WPF</category><category>Over Complicated</category><category>Analysis</category><category>Silverlight</category><category>.NET</category><category>Excel</category><title>CodeBlog.TheG2.NET</title><description>Random code postings for various programing languages.</description><link>http://codeblog.theg2.net/</link><managingEditor>noreply@blogger.com (Greg Bray)</managingEditor><generator>Blogger</generator><openSearch:totalResults>37</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/TheG2NetCode" /><feedburner:info uri="theg2netcode" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6011603498138679949.post-8942500297874183692</guid><pubDate>Wed, 13 Feb 2013 05:39:00 +0000</pubDate><atom:updated>2013-02-12T22:39:57.290-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Video</category><category domain="http://www.blogger.com/atom/ns#">Samsung</category><category domain="http://www.blogger.com/atom/ns#">Android</category><category domain="http://www.blogger.com/atom/ns#">CyanogenMod</category><title>Samsung Epic 4G CyanogenMod Notes and Links</title><description>&lt;p&gt;Up until a few months ago I very much enjoyed having the Samsung Epic 4G as my personal phone. It is the best Android phone with full QWERTY keyboard that I have ever used, but the hardware is a bit dated and the WiMax speeds were not as fast as LTE, so I decided to upgrade to the Galaxy Note II on Verizon. Samsung stopped updating the software on the Epic 4G a while ago, but the &lt;a href="http://www.cyanogenmod.org/" target="_blank"&gt;CyanogenMod&lt;/a&gt; community has done a great job at supporting the phone and even has Android Jelly Bean 4.1 ROMs with full functionality. I still have friends with the Epic 4G so I thought I would post all the links I used for loading custom ROMs.&lt;/p&gt;  &lt;p&gt;Most recent versions (As of January 2013)&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Android 4.1.2 using CyanogenMod 10-20130107 nightly build&lt;/li&gt;    &lt;li&gt;Rooted with Clockworkmod version 6.0.2.7&lt;/li&gt;    &lt;li&gt;Video guide for &lt;a href="http://youtu.be/C9eaCtiS0Bo" target="_blank"&gt;Rooting Epic 4G&lt;/a&gt; (Kudos to &lt;a href="http://www.qbking77.com/" target="_blank"&gt;QBKing77&lt;/a&gt; for his great demos)&lt;/li&gt;    &lt;li&gt;Video guide for &lt;a href="http://youtu.be/_jCqKo7C-nY" target="_blank"&gt;Installing CyanogenMod 10 ROMs&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;a href="http://epiccm.blogspot.com/" target="_blank"&gt;EpicCM blog&lt;/a&gt; (CyanogenMod team working on Epic4G) &lt;/li&gt;    &lt;li&gt;Epic 4G &lt;a href="http://get.cm/?device=epicmtd" target="_blank"&gt;Nightly CM Builds&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;Sprint has &lt;a href="http://support.sprint.com/support/article/Program_your_Samsung_Epic_4G/case-wh164052-20100823-182330" target="_blank"&gt;Steps to activate phone&lt;/a&gt;, which includes instructions for activating a used phone. These may not work in CM 10, but I usually put a temporary boot ROM on the SD card that will &lt;a href="http://epiccm.blogspot.com/2012/01/boot-el30-stock-from-sdcard.html" target="_blank"&gt;boot into the stock FC09 ROM&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Temporary Stock Boot Instructions:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;a href="http://youtu.be/C9eaCtiS0Bo?t=6m32s" target="_blank"&gt;Boot into CWM5 on your Epic 4G&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;Install zip from sdcard &amp;gt; choose zip from sdcard &amp;gt; multiboot &amp;gt; FC09 &amp;gt; boot_FC09.zip&lt;/li&gt;    &lt;li&gt;WAIT.&amp;#160; It will take a while to boot.&amp;#160; You might see a &amp;quot;com.android.phone is not responding&amp;quot;, do not worry, it is harmless.&amp;#160; Wait until Media Scanning is complete before doing anything.&lt;/li&gt;    &lt;li&gt;Follow instructions for activating phone or &lt;a href="http://www.youtube.com/watch?v=Jjh-w1VCrvw" target="_blank"&gt;calibrating tilt sensor&lt;/a&gt;&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;You can also revert the &lt;a href="http://forum.xda-developers.com/showthread.php?t=1052813" target="_blank"&gt;Epic 4G to original locked boot loader and stock ROM&lt;/a&gt; if you have any issues with the custom ROMs or have to take it in for service/support.&lt;/p&gt;  &lt;p&gt;Hope this helps any Epic 4G users out there. If Samsung ever decides to make another Galaxy S phone with a keyboard definitely will consider buying it, but for now I am enjoying the &lt;a href="http://youtu.be/gdmzggcY0UE" target="_blank"&gt;Galaxy Note II with flygrip&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TheG2NetCode/~4/-zMRxf3cfmc" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/TheG2NetCode/~3/-zMRxf3cfmc/samsung-epic-4g-cyanogenmod-notes-and.html</link><author>noreply@blogger.com (Greg Bray)</author><thr:total>0</thr:total><feedburner:origLink>http://codeblog.theg2.net/2013/02/samsung-epic-4g-cyanogenmod-notes-and.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6011603498138679949.post-4112939036798328293</guid><pubDate>Wed, 25 May 2011 07:32:00 +0000</pubDate><atom:updated>2013-05-17T13:36:09.335-06:00</atom:updated><title>Looking for a .NET programmer in Salt Lake City, Utah? You should hire me!</title><description>&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;span style="color: red; font-size: large;"&gt;UPDATE 6/01/2011&lt;/span&gt;: I have accepted a great position at GE healthcare that interestingly has very little to do with .NET and everything to do with making better software.&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;br /&gt;&lt;/strong&gt;
&lt;strong&gt;&lt;span style="color: red; font-size: large;"&gt;UPDATE 5/15/2013&lt;/span&gt;: Although I am still working for GE (Now part of a joint&amp;nbsp;venture&amp;nbsp;with Microsoft) I am also actively looking for new challenges in Software Engineering or Developer Operations.&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;br /&gt;&lt;/strong&gt;
&lt;strong&gt;My 30 second over-hyped elevator pitch:&lt;/strong&gt;&lt;br /&gt;
&lt;a href="http://lh4.ggpht.com/_G06mB5h-kvQ/TdywiWMmiXI/AAAAAAAAHu8/TEY_BnZk81Q/s1600-h/The%20most%20hirable%20man%20in%20the%20world%5B5%5D.png"&gt;&lt;img align="right" alt="The most hirable man in the world" border="0" height="289" src="http://lh4.ggpht.com/_G06mB5h-kvQ/TdywjM_nFWI/AAAAAAAAHvA/DrkboiOo37g/The%20most%20hirable%20man%20in%20the%20world_thumb%5B3%5D.png?imgmax=800" style="background-image: none; border-bottom-width: 0px; border-left-width: 0px; border-right-width: 0px; border-top-width: 0px; display: inline; float: right; margin: 0px 20px 15px; padding-left: 0px; padding-right: 0px; padding-top: 0px;" title="The most hirable man in the world" width="232" /&gt;&lt;/a&gt;Most people don’t have the time to read through a &lt;a href="http://careers.stackoverflow.com/gregbray" target="_blank"&gt;full resume&lt;/a&gt; nowadays, so I’ll keep things short and to the point. &lt;strong&gt;You should hire me!&lt;/strong&gt; Why? Because I am &lt;a href="http://www.joelonsoftware.com/articles/fog0000000073.html" target="_blank"&gt;smart and I get things done&lt;/a&gt;. The last time I was in the job market I turned a 3 week software testing project into a 6 year pursuit helping to convert a small ISV into a cloud driven heavyweight. I don’t always code in .NET, but it is definitely my platform of choice. Life is too short to worry about pointers and memory leaks. If I wanted to do that I’d go back to working in assembly language on an 8086 like God intended. I can automate just about anything using a combination of BASH, PowerShell, AutoIT, VBA, WatiN, MSAA, a bunch of HWNDs, a packet sniffer, a few servos, and a roll of duct tape. I work well as part of the A-Team or sent out solo in the wild like Rambo. In short: I am the most &lt;a href="http://english.stackexchange.com/q/26908/9063" target="_blank"&gt;hirable&lt;/a&gt; man in the world! :-P Keep coding my friends!&lt;br /&gt;
&lt;br /&gt;
I live my life like an open book, &lt;a href="http://www.google.com/profiles/greg.bray" target="_blank"&gt;indexed by Google&lt;/a&gt;. I have a thirst for knowledge and a passion for technology. I pay great attention to detail and strive for nothing less than perfection. A lot of my past projects are internal or backend systems, but below is a sample of what has kept me busy over the last decade or so.     &lt;br /&gt;
&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Personal Coding projects:&lt;/strong&gt;&lt;br /&gt;
&lt;a href="http://blog.phrasememe.com/p/phrasememe-scanner.html" target="_blank"&gt;PhraseMeme Scanner&lt;/a&gt;, &lt;a href="http://blog.phrasememe.com/p/winfone-alpha.html" target="_blank"&gt;WinFone Alpha&lt;/a&gt; (Windows Phone, 2010-2011)&lt;br /&gt;
&lt;a href="http://codeblog.theg2.net/2010/12/windows-phone-barcode-library.html" target="_blank"&gt;Silverlight port&lt;/a&gt; of &lt;a href="http://silverlightzxing.codeplex.com/" target="_blank"&gt;ZXing Barcode Scanning library&lt;/a&gt; (Silverlight, C#, 2010-2011)&lt;br /&gt;
&lt;a href="http://theg2.net/texasholdem/" target="_blank"&gt;Texas Holdem Monte Carlo Simulator&lt;/a&gt; (Silverlight, Windows Mobile, 2009)&lt;br /&gt;
Resolver one: &lt;a href="http://www.resolversystems.com/exchange/users/gbrayut/" target="_blank"&gt;Texas Holdem, Pivot Charts/Auto filter, Web page automation, WPF Charts, Mad Lib generator&lt;/a&gt; (IronPython spreadsheet, 2009)&lt;br /&gt;
&lt;a href="http://www.theg2.net/gnumap/" target="_blank"&gt;GnuMap P2P Mapping project&lt;/a&gt; (Visual Basic, Web Spider, aiSee, 2002)     &lt;br /&gt;
&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Samples of documents I have created:&lt;/strong&gt;&lt;br /&gt;
&lt;a href="http://demo.oqanalyst.com/OQAHS/Files/General_Information/OQ%20Analyst%20-%20System%20Overview%202007OCT08.pdf" target="_blank"&gt;High level overview graph&lt;/a&gt; (Visio 2007)&lt;br /&gt;
&lt;a href="http://demo.oqanalyst.com/OQAHS/Files/General_Information/OQ%20Analyst%20-%20Technical%20Overview%202009AUG18.pdf" target="_blank"&gt;Detailed technical overview chart&lt;/a&gt; (Visio 2009)&lt;br /&gt;
&lt;a href="http://demo.oqanalyst.com/OQA/Files/WSI/OQ_Analyst_Raw_WSI_Overview_And_Examples_2008MAY08.pdf" target="_blank"&gt;In depth technical documentation&lt;/a&gt; (Word 2008)&lt;br /&gt;
&lt;a href="http://demo.oqanalyst.com/OQAHS/Files/General_Information/OQAHS%20Administration%20Methods%20Screenshots%202010MAR16.pdf" target="_blank"&gt;Short section of web based training material&lt;/a&gt; (PowerPoint 2010)&lt;br /&gt;
&lt;a href="http://demo.oqanalyst.com/OQAHS/Files/General_Information/OQAnalyst_All_Feedback_Reports_2006JUNE28.pdf" target="_blank"&gt;Samples of feedback reports w/ synopsis&lt;/a&gt; (Acrobat 2006)&lt;br /&gt;
&lt;a href="http://demo.oqanalyst.com/OQAHS/Files/Upgrade/OQ-AHS%20Software%20Update%203.05%20to%204.09%202010AUG10.pdf" target="_blank"&gt;Memo to customers re: Software Upgrade&lt;/a&gt; (Word 2010)&lt;br /&gt;
&lt;a href="https://web.oqanalyst.com/OQAWSITools/" target="_blank"&gt;Custom Reporting Tools using SOAP web service&lt;/a&gt; (C#, ClickOnce, Access, Excel 2009)&lt;br /&gt;
&lt;a href="http://demo.oqanalyst.com/oqahs/files/" target="_blank"&gt;Raw Documentation Files&lt;/a&gt; (2006 – 2011, I created the majority of the documents on here)     &lt;br /&gt;
&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Screencasts and videos of project I have created:&lt;/strong&gt;&lt;br /&gt;
&lt;a href="http://youtu.be/6T_v4x9JtLQ" target="_blank"&gt;PhraseMeme scanner demo video&lt;/a&gt; (3 mins, Camtasia, PowerPoint 2010)&lt;br /&gt;
&lt;a href="http://youtu.be/K_hOw-KHqoA" target="_blank"&gt;WinFone Alpha demo video&lt;/a&gt; (3 mins, Camtasia, PowerPoint 2010)&lt;br /&gt;
&lt;a href="http://www.theg2.net/texasholdem/ineta/INETA-GregBray-TexasHoldem-2009AUG25.wmv" target="_blank"&gt;Texas Holdem Monte Carlo Simulator&lt;/a&gt; (5 mins, Camtasia, PowerPoint 2009)     &lt;br /&gt;
&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;strong&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Coding Competitions:&lt;/strong&gt;&lt;br /&gt;
PhraseMeme Scanner received &lt;a href="http://blog.phrasememe.com/2011/03/wp7comp-entry-statistics-total-likes.html" target="_blank"&gt;good rankings in Windows Phone 7 Competition&lt;/a&gt; sponsored by Red Gate (2010)&lt;br /&gt;
Texas Holdem app received honorable mention in &lt;a href="http://blog.theg2.net/2009/10/ironpython-texas-holdem-poker.html" target="_blank"&gt;2009 INETA Code Challenge and 2009 Telerik Silverlight contest&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://blog.theg2.net/2009/05/resolver-one-review-4-months-with-net.html" target="_blank"&gt;Monte Carlo spreadsheet&lt;/a&gt; was the winner of $4,000 prize in April 2009 round of &lt;a href="http://www.resolversystems.com/news/?p=109" target="_blank"&gt;Resolver One Challenge&lt;/a&gt;&lt;img src="http://feeds.feedburner.com/~r/TheG2NetCode/~4/3l6taJHNmo0" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/TheG2NetCode/~3/3l6taJHNmo0/looking-for-net-programmer-in-salt-lake.html</link><author>noreply@blogger.com (Greg Bray)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh4.ggpht.com/_G06mB5h-kvQ/TdywjM_nFWI/AAAAAAAAHvA/DrkboiOo37g/s72-c/The%20most%20hirable%20man%20in%20the%20world_thumb%5B3%5D.png?imgmax=800" height="72" width="72" /><feedburner:origLink>http://codeblog.theg2.net/2011/05/looking-for-net-programmer-in-salt-lake.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6011603498138679949.post-411776986868902540</guid><pubDate>Tue, 18 Jan 2011 03:29:00 +0000</pubDate><atom:updated>2011-01-17T20:29:27.732-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Tips n Tricks</category><category domain="http://www.blogger.com/atom/ns#">Testing</category><category domain="http://www.blogger.com/atom/ns#">Silverlight</category><category domain="http://www.blogger.com/atom/ns#">WP7</category><title>InvalidOperationException from IsolatedStorageSettings.Save on Windows Phone 7</title><description>&lt;p&gt;I just had my first failed test from the marketplace certification for &lt;a href="http://www.phrasememe.com" target="_blank"&gt;PhraseMeme Scanner v1.2&lt;/a&gt;. You can view the &lt;a href="https://docs.google.com/viewer?a=v&amp;amp;pid=explorer&amp;amp;chrome=true&amp;amp;srcid=0B85jqt_O7U6SYjdjZWY4OWMtNjQ4Zi00NzM1LWE3OWEtODcxM2FhZDViOTZh&amp;amp;hl=en" target="_blank"&gt;full error report here&lt;/a&gt;, but the important part is:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;Comments: The application terminates unexpectedly when the user turns on/off one of the setting while trying to scroll to&lt;/p&gt;    &lt;p&gt;another page.&lt;/p&gt;    &lt;p&gt;Steps to reproduce:&lt;/p&gt;    &lt;p&gt;1. Launch the application.&lt;/p&gt;    &lt;p&gt;2. Scroll over to the setting menu.&lt;/p&gt;    &lt;p&gt;3. At the same time, press and scroll on any of the settings.&lt;/p&gt;    &lt;p&gt;4. Notice the application terminates unexpectedly when the user turns on/off one of the setting while trying to scroll to&lt;/p&gt;    &lt;p&gt;another page.&lt;/p&gt; &lt;/blockquote&gt; &lt;a style="margin: 20px; float: right" href="http://picasaweb.google.com/lh/photo/53kF2u2XFHydLXaXnw6D6WFAwd2V64U0z78Vvbm6-KE?feat=embedwebsite"&gt;&lt;img src="http://lh6.ggpht.com/_G06mB5h-kvQ/TTUGfpgmR_I/AAAAAAAAHN0/TbsmJVsSOQI/s400/Settings.PNG" width="223" height="400" /&gt;&lt;/a&gt;   &lt;p style="margin-top: 30px"&gt;The settings page uses &lt;a href="http://timheuer.com/blog/archive/2010/09/16/silverlight-toolkit-for-windows-phone-7-released.aspx#toggleswitch" target="_blank"&gt;ToggleSwitches&lt;/a&gt; from the &lt;a href="http://silverlight.codeplex.com/" target="_blank"&gt;Silverlight for Windows Phone Toolkit&lt;/a&gt; with a simple two-way binding to a values stored in an &lt;a href="http://msdn.microsoft.com/en-us/library/system.io.isolatedstorage.isolatedstoragesettings(v=VS.95).aspx" target="_blank"&gt;IsolatedStorageSettings&lt;/a&gt; class, so I was a bit confused where the error was coming from. Using Visual Studio I found that the &lt;a href="http://msdn.microsoft.com/en-us/library/Cc672922(v=VS.96).aspx?appId=Dev10IDEF1&amp;amp;l=EN-US&amp;amp;k=k(SYSTEM.IO.ISOLATEDSTORAGE.ISOLATEDSTORAGESETTINGS.SAVE)&amp;amp;rd=true" target="_blank"&gt;IsolatedStorageSettings.Save&lt;/a&gt; method was throwing an InvalidOperationException whenever the user changed a setting and navigated way from the page at the same time.     &lt;br /&gt;    &lt;br /&gt;The MSDN documentation doesn’t mention that the method can throw this error, but my guess is that either the value is in an indeterminate state or there is a conflict between the save method and the two-way binding. The error could have been there all along, but in this version I had moved all the IO calls to background threads to increase performance where as previously the exception was captured by a try/catch block on the calling method.&lt;/p&gt;  &lt;p&gt;Luckily it was an easy fix: I added a try/catch statement to the save code block and inserted a delay to let whatever processing it was conflicting with finish before it tried to save the settings. Below is the new code that can be used for saving settings stored in an IsolatedStorageSettings class:&lt;/p&gt;  &lt;p style="line-height: normal; margin: 0in 0in 0pt; clear: both; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;font face="Consolas"&gt;&lt;span style="font-family: "&gt;&lt;font color="#808080"&gt;&lt;font style="font-size: 9.5pt"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 9.5pt"&gt;&lt;span style="font-family: "&gt;&lt;font color="#008000"&gt; &lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;span style="font-family: "&gt;&lt;font style="font-size: 9.5pt" color="#808080"&gt;&amp;lt;summary&amp;gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;span style="font-family: "&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;font face="Consolas"&gt;&lt;span style="font-family: "&gt;&lt;font color="#808080"&gt;&lt;font style="font-size: 9.5pt"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="font-family: "&gt;&lt;font style="font-size: 9.5pt" color="#008000"&gt; Save settings to isolated storage. Will run using background thread to prevent blocking UI thread.&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;span style="font-family: "&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;font face="Consolas"&gt;&lt;span style="font-family: "&gt;&lt;font color="#808080"&gt;&lt;font style="font-size: 9.5pt"&gt;///&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 9.5pt"&gt;&lt;span style="font-family: "&gt;&lt;font color="#008000"&gt; &lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;span style="font-family: "&gt;&lt;font style="font-size: 9.5pt" color="#808080"&gt;&amp;lt;/summary&amp;gt;&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;span style="font-family: "&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;font face="Consolas"&gt;&lt;span style="font-family: "&gt;&lt;font color="#0000ff"&gt;&lt;font style="font-size: 9.5pt"&gt;public&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;span style="font-family: "&gt;&lt;font style="font-size: 9.5pt"&gt; &lt;span&gt;&lt;font color="#0000ff"&gt;static&lt;/font&gt;&lt;/span&gt; &lt;span&gt;&lt;font color="#0000ff"&gt;void&lt;/font&gt;&lt;/span&gt; Save()&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/p&gt;  &lt;p style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;span style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;font style="font-size: 9.5pt"&gt;{&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;span style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font style="font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 9.5pt"&gt;&lt;span&gt;&lt;font color="#2b91af"&gt;ThreadPool&lt;/font&gt;&lt;/span&gt;.QueueUserWorkItem(func =&amp;gt; {&lt;/font&gt;&lt;span&gt;&lt;font style="font-size: 9.5pt" color="#008000"&gt;//Save items using background thread.&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;span style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font style="font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font style="font-size: 9.5pt" color="#0000ff"&gt;try&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;span style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font style="font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 9.5pt"&gt;{&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;span style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font style="font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;span&gt;&lt;font style="font-size: 9.5pt" color="#008000"&gt;//NOTE: may throw InvalidOperationException exception if user is in process of changing settings and navigating away from page&lt;/font&gt;&lt;/span&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;span style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font style="font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 9.5pt"&gt;System.Threading.&lt;span&gt;&lt;font color="#2b91af"&gt;Thread&lt;/font&gt;&lt;/span&gt;.Sleep(200);&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;span style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font style="font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 9.5pt"&gt;issSettings.Save(); &lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;span style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font style="font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 9.5pt"&gt;}&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;span style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font style="font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 9.5pt"&gt;&lt;span&gt;&lt;font color="#0000ff"&gt;catch&lt;/font&gt;&lt;/span&gt; (&lt;span&gt;&lt;font color="#2b91af"&gt;Exception&lt;/font&gt;&lt;/span&gt; ex)&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;span style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font style="font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 9.5pt"&gt;{&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;span style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font style="font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 9.5pt"&gt;&lt;span&gt;&lt;font color="#2b91af"&gt;Debug&lt;/font&gt;&lt;/span&gt;.WriteLine(&lt;span&gt;&lt;font color="#a31515"&gt;&amp;quot;Error saving settings: &amp;quot;&lt;/font&gt;&lt;/span&gt; + ex);&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;span style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font style="font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 9.5pt"&gt;}&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;span style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font style="font-size: 9.5pt"&gt;&amp;#160;&amp;#160;&amp;#160; &lt;/font&gt;&lt;/span&gt;&lt;font style="font-size: 9.5pt"&gt;});&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p style="line-height: normal; margin: 0in 0in 0pt; mso-layout-grid-align: none" class="MsoNormal"&gt;&lt;span style="font-family: "&gt;&lt;font face="Consolas"&gt;&lt;font style="font-size: 9.5pt"&gt;}&lt;/font&gt;&lt;/font&gt;&lt;/span&gt;&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Hope that helps someone prevent a failed submission to the marketplace.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TheG2NetCode/~4/Rp_6y6NPNaY" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/TheG2NetCode/~3/Rp_6y6NPNaY/invalidoperationexception-from.html</link><author>noreply@blogger.com (Greg Bray)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh6.ggpht.com/_G06mB5h-kvQ/TTUGfpgmR_I/AAAAAAAAHN0/TbsmJVsSOQI/s72-c/Settings.PNG" height="72" width="72" /><thr:total>0</thr:total><feedburner:origLink>http://codeblog.theg2.net/2011/01/invalidoperationexception-from.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6011603498138679949.post-2311707406735516407</guid><pubDate>Mon, 20 Dec 2010 23:23:00 +0000</pubDate><atom:updated>2010-12-20T16:23:36.504-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">JavaScript</category><category domain="http://www.blogger.com/atom/ns#">Tips n Tricks</category><category domain="http://www.blogger.com/atom/ns#">Tools</category><category domain="http://www.blogger.com/atom/ns#">Regex</category><category domain="http://www.blogger.com/atom/ns#">WP7</category><title>Enable Blogger Mobile Templates Support for WP7 and Opera Mobile</title><description>&lt;p&gt;Blogger recently released a new feature to their &lt;a href="http://bloggerindraft.blogspot.com/2007/06/introducing-blogger-in-draft.html" target="_blank"&gt;Blogger in draft&lt;/a&gt; platform that allows the website to automatically detect mobile browsers and render the page using a small-screen friendly template. This fixes a HUGE issue I have been working on for the last few weeks ever since I released the &lt;a href="http://www.phrasememe.com/scanner" target="_blank"&gt;PhraseMeme Scanner&lt;/a&gt; application, namely publishing content that will be consumed by both large and small screen devices. Previously I was planning on having two version of the website with one being optimized for mobile and one for desktop, but now I can store all the content on Blogger and use the mobile templates to render for small-screen devices.&lt;/p&gt;  &lt;p&gt;The &lt;a href="http://bloggerindraft.blogspot.com/2010/12/new-mobile-templates-for-reading-on-go.html" target="_blank"&gt;Show mobile template&lt;/a&gt; currently works with the default iPhone and Android browsers, but it does not work with the Opera Mobile, Pocket IE, or Windows Phone 7 Internet Explorer browsers. I assume there are other mobile browsers that also don’t work, but there is a simple way to add support for any browser by using JavaScript to redirect users.&amp;#160; Here is the code that I wrote to detect mobile browsers and redirect accordingly:&lt;/p&gt;  &lt;p&gt;&lt;script src="https://gist.github.com/749184.js"&gt; &lt;/script&gt;&lt;/p&gt;  &lt;p&gt;The templates work by appending a m=1 parameter to the blog URL or (m=0 to force full webpage on mobile devices), so all that the above code has to do is look for that parameter and add it if a mobile device is detected. You can add the above script to your blog using either the &lt;a href="http://www.blogspottutorial.com/2008/10/add-alert-script-in-blog.html" target="_blank"&gt;blog template&lt;/a&gt; or the &lt;a href="http://zerodollarchallenge.blogspot.com/2008/01/how-to-add-htmlscripts-to-blogger.html" target="_blank"&gt;HTML/Javascript Gadget&lt;/a&gt;. Adding it to the blog template will cause it to run before the page is fully loaded, but you should save your current template first to make sure you don’t mess anything up;&lt;/p&gt;  &lt;p&gt;I added a &lt;a href="https://spreadsheets.google.com/a/google.com/viewform?formkey=dEZLMGNoTGQ4VERmN1ptTmkxZVpWY3c6MQ" target="_blank"&gt;feature request&lt;/a&gt; for Blogger to support more mobile browsers, but for now the above script should let you start using this amazing feature.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TheG2NetCode/~4/f3_ccJ9pVdE" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/TheG2NetCode/~3/f3_ccJ9pVdE/enable-blogger-mobile-templates-support.html</link><author>noreply@blogger.com (Greg Bray)</author><thr:total>3</thr:total><feedburner:origLink>http://codeblog.theg2.net/2010/12/enable-blogger-mobile-templates-support.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6011603498138679949.post-7248076644540246344</guid><pubDate>Thu, 09 Dec 2010 01:37:00 +0000</pubDate><atom:updated>2011-03-11T13:45:42.001-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">ZXing</category><category domain="http://www.blogger.com/atom/ns#">.NET</category><category domain="http://www.blogger.com/atom/ns#">Library</category><category domain="http://www.blogger.com/atom/ns#">OSS</category><category domain="http://www.blogger.com/atom/ns#">Silverlight</category><category domain="http://www.blogger.com/atom/ns#">WP7</category><title>Windows Phone Barcode Library (Silverlight C# ZXing Port)</title><description>&lt;a href="https://picasaweb.google.com/lh/photo/cUd45Nx8qddGuCUlfCClcmFAwd2V64U0z78Vvbm6-KE?feat=embedwebsite" target="_blank"&gt;&lt;img style="margin: 0px 0px 0px 20px; display: inline; float: right" align="right" src="https://lh3.googleusercontent.com/_G06mB5h-kvQ/TQfWLkwZW7I/AAAAAAAAHGI/lj52MSYhK9k/s640/02_Barcode_Type_1.PNG" width="206" height="343" /&gt;&lt;/a&gt;   &lt;p&gt;I have been working on a &lt;a href="http://www.phrasememe.com/scanner" target="_blank"&gt;Barcode Scanning application for Windows Phone 7&lt;/a&gt; for about 3 months now, but none of my efforts would have been possible without the prior work done by Google on the open source &lt;a href="http://code.google.com/p/zxing/" target="_blank"&gt;ZXing (“Zebra Crossing”)&lt;/a&gt; barcode scanning library. This library is released under the &lt;a href="http://code.google.com/p/zxing/wiki/LicenseQuestions" target="_blank"&gt;Apache License v2.0&lt;/a&gt; and has spurred development of many different barcode scanners on many different platforms. The idea for PhraseMeme Scanner came when I saw there weren’t any good scanners available for Windows Phone 7 and then stumbled across the partial C# port of ZXing. Through a bit of testing I was able to modify the library to support Silverlight and Window Phone 7, and decided I would help push the library into a well maintained and supported state in the Silverlight world.&lt;/p&gt;  &lt;p&gt;While the primary purpose for updating the library is to build the &lt;a href="http://twitter.com/#!/PhraseMeme/status/16935992573296641" target="_blank"&gt;&amp;quot;Best barcode scanning app available&amp;quot;&lt;/a&gt; I also want to give back to the community and help others create great windows phone or Silverlight apps. ZXing has their own Google Code project, but that site is mainly devoted to Android or Java development, so I decided to store the code on Codeplex to get it some .Net love. This also means that I can use Mecurial instead of SVN/CVS, which so far has been a great experience and should be very helpful if anyone else decides to contribute patches or new features to the library.&lt;/p&gt;  &lt;p&gt;So without further ado, please check out the &lt;a href="http://silverlightzxing.codeplex.com" target="_blank"&gt;&lt;font size="4"&gt;&lt;strong&gt;Windows Phone 7 Silverlight ZXing Barcode Scanning Library&lt;/strong&gt;&lt;/font&gt;&lt;/a&gt; based on the csharp ZXing port created by Suraj Supekar at &lt;a href="http://code.google.com/p/zxing/source/detail?spec=svn1692&amp;amp;r=1202" target="_blank"&gt;revision 1202 in the SVN repository&lt;/a&gt;. Let me know what you think, and happy coding!&lt;/p&gt;  &lt;p&gt;&lt;font size="4"&gt;&lt;strong&gt;Update 3/11/2011: &lt;/strong&gt;&lt;/font&gt;It looks like the project is getting a lot of interest from developers with over &lt;strong&gt;6,000&lt;/strong&gt; page views and &lt;strong&gt;750&lt;/strong&gt; total downloads in the last few months. This is probably due to the various &lt;a href="http://twitter.com/#!/winphonegeek/status/30624497686028288" target="_blank"&gt;tweets&lt;/a&gt; on &lt;a href="http://twitter.com/#!/gcaughey/status/30241160819638273" target="_blank"&gt;twitter&lt;/a&gt; and a blog post from Rudi Grobler about &lt;a href="http://www.rudigrobler.net/blog/reading-barcodes-from-your-wp7-device" target="_blank"&gt;reading barcodes on WP7&lt;/a&gt; using the Silverlight ZXing port. That blog post was mentioned on &lt;a href="http://twitter.com/#!/PhraseMeme/status/32173998540328960" target="_blank"&gt;This Week in Channel 9&lt;/a&gt;, which totally made my day even if it was only talked about for &lt;a href="http://j.mp/h9bS00" target="_blank"&gt;40 seconds&lt;/a&gt; and never even mentioned my name. Still… pretty wicked cool &lt;/p&gt;  &lt;p&gt;&lt;img style="border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none" class="wlEmoticon wlEmoticon-smilewithtongueout" alt="Smile with tongue out" src="http://lh6.ggpht.com/_G06mB5h-kvQ/TUc-i1KXJxI/AAAAAAAAHRM/PnkblA31-70/wlEmoticon-smilewithtongueout%5B2%5D.png?imgmax=800" /&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TheG2NetCode/~4/tNXdxSHAsGc" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/TheG2NetCode/~3/tNXdxSHAsGc/windows-phone-barcode-library.html</link><author>noreply@blogger.com (Greg Bray)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://lh3.googleusercontent.com/_G06mB5h-kvQ/TQfWLkwZW7I/AAAAAAAAHGI/lj52MSYhK9k/s72-c/02_Barcode_Type_1.PNG" height="72" width="72" /><thr:total>7</thr:total><feedburner:origLink>http://codeblog.theg2.net/2010/12/windows-phone-barcode-library.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6011603498138679949.post-8612828614365699202</guid><pubDate>Tue, 05 Oct 2010 04:58:00 +0000</pubDate><atom:updated>2011-11-29T18:44:25.519-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Tips n Tricks</category><category domain="http://www.blogger.com/atom/ns#">.NET</category><category domain="http://www.blogger.com/atom/ns#">Hardware</category><category domain="http://www.blogger.com/atom/ns#">Servers</category><category domain="http://www.blogger.com/atom/ns#">Cloud Computing</category><title>VPS/VM vs Dedicated vs Cloud Servers: Hosting options and cost comparisons</title><description>I usually talk about Code on this blog, but eventually that code is going to have to run somewhere so I thought I would outline some of the different server options that are available. While there are free or low cost options for hosting simple or small websites, if you are using ASP.NET, PHP, or Java to create a dynamic website or if you are looking for a file or application server then you are going to have to pay for the resources that you use (bandwidth, hardware, software, etc). The price/performance ratio can vary greatly depending on what type of server you purchase. There are a lot of different configurations, but here are some of my recommendations.&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;



First, what not to do:&lt;/h2&gt;
While in certain cases it may be appropriate, my recommendation is to steer clear of two specific hosting options: &lt;strong&gt;Shared web hosting&lt;/strong&gt; and &lt;strong&gt;Do-It-Yourself hosting&lt;/strong&gt;. Shared hosting refers to the $5 a month plans offered by Godaddy, Yahoo, and thousands of “resellers” that use a control panel like &lt;a href="http://www.parallels.com/products/plesk/demo/" target="_blank"&gt;Plesk&lt;/a&gt; or &lt;a href="http://www.cpanel.net/products/cpanelwhm/try-demo.html" target="_blank"&gt;cPanel&lt;/a&gt; to divide up a single server into hundreds of small websites. These servers are often over-sold and under-powered, and you will only get FTP and control panel access, so you will have to rely on your hosting provider to make any advanced configuration changes or perform troubleshooting steps for you. If you cannot afford any of the other options then Shared Hosting might be a good way to start, but keep in mind that you get what you pay for and will&amp;nbsp; probably out-grow it very quickly.&lt;br /&gt;
&lt;br /&gt;
As for &lt;strong&gt;Do-It-Yourself hosting,&lt;/strong&gt; this is simply a case of economies of scale: You wouldn’t start a wheat farm just to make a sandwich, so why build and maintain your own servers? Unless you are a corporation with a full IT department, it is not in your best interest to setup and maintain your own web or application servers outside of your personal testing/development environment. Servers are more or less a commodity nowadays, so while you could setup a computer in a closet of your office and use it to host your company website, you then have to worry about what happens when the power goes out or when your Internet connection goes down. Setting up and maintaining a reliable network with redundant paths and uninterrupted power takes a considerable amount of time and money. I highly suggest that you outsource this effort to a 3rd party and focus your energy on improving your website or application instead. And in terms of running your own Email and Calendaring server, you really, REALLY should look at paying &lt;a href="http://www.google.com/apps/intl/en/business/index.html" target="_blank"&gt;Google&lt;/a&gt;, &lt;a href="http://www.microsoft.com/online/business-productivity.aspx" target="_blank"&gt;Microsoft&lt;/a&gt;, or someone else to provide these services for you if at all possible.&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;



Virtual Private Server / Virtual Machine:&lt;/h2&gt;
It use to be that when looking for a hosting provider you were either stuck with shared hosting or a dedicated server. Now there are many other options, most of which are based on server virtualization. While it may sound similar to Shared Hosting, &lt;strong&gt;VPS or VM hosting&lt;/strong&gt; options can provide guaranteed resources and an isolated execution environment in which you have full control of the server. The hosting provider will purchase high-end server hardware and then use a &lt;a href="http://en.wikipedia.org/wiki/Hypervisor" target="_blank"&gt;hypervisor&lt;/a&gt; to divide that server up into multiple virtual machines for different customers (usually 2-24 depending on the size of the VMs). Each VM gets a certain percentage of the CPU, Memory, and Disk Space and will function as its own server. From my experience VPS or VM hosting provides the best bang for your buck at around &lt;strong&gt;$20-$120 a month&lt;/strong&gt; (see Choosing a Hosting Provider below).&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;



Dedicated Servers:&lt;/h2&gt;
Some applications require significant horsepower, in which case a &lt;strong&gt;dedicated server&lt;/strong&gt; is usually a requirement. You can purchase standardized “cookie-cutter” servers from most hosting providers, or you can also get a custom quote if you need to have a specific type of RAID setup or maximize RAM size or CPU speeds. Until recently I have primarily worked with dedicated servers that usually run anywhere from &lt;strong&gt;$100 to $1000 a month&lt;/strong&gt;, so they are only viable in business environments that can justify the cost of the server. You also may have the option to rent, lease or purchase the server, but if you are purchasing you must factor in the time and costs for replacing failed hardware components in the future. Also if you work with sensitive information such as credit cards or medical records then you may require a dedicated server to meet Payment Card Industry (PCI), Health Insurance Portability and Accountability Act (HIPAA) or various other federal regulations.&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;



Cloud IaaS and PaaS Servers:&lt;/h2&gt;
Cloud hosting is the new hot term, but a lot of the time it means the same thing as &lt;strong&gt;VPS or VM Hosting&lt;/strong&gt; except you pay by the hour instead of by the month. There are typically 3 types of &lt;a href="http://www.jansipke.nl/top-cloud-computing-providers" target="_blank"&gt;“Cloud Computing”: IaaS, PaaS, and SaaS&lt;/a&gt;. For the most part &lt;strong&gt;Infrastructure as a Service (IaaS)&lt;/strong&gt; is exactly the same as VPS or VM hosting just with a fancy API and pay-by-the-hour terms. &lt;strong&gt;Software as a Service (SaaS)&lt;/strong&gt; doesn’t really have servers in the sense that you usually are riding on top of another application (Ex: Google Apps or Salesforce). &lt;strong&gt;Platform as a Service (PaaS)&lt;/strong&gt; still uses Virtual Machines, but the platform is designed to help you scale your application horizontally across multiple nodes. &lt;a href="http://aws.amazon.com/" target="_blank"&gt;Amazon Web Services (AWS)&lt;/a&gt; has some PaaS products, but their EC2 product fits more into the IaaS category (you have to scale-out your code to work on multiple servers on your own). &lt;a href="http://www.microsoft.com/windowsazure/windowsazure/" target="_blank"&gt;Windows Azure&lt;/a&gt;, &lt;a href="http://www.rackspacecloud.com/cloud_hosting_products/sites" target="_blank"&gt;Rackspace Cloud Sites&lt;/a&gt; and &lt;a href="http://code.google.com/appengine/" target="_blank"&gt;Google App Engine&lt;/a&gt; are examples of PaaS, but they each have different programing models so you have to build your application around their platform. PaaS is designed to scale to meet your traffic needs and use multiple server nodes to provide better reliability, but this also means you will play a higher cost if you are running a 24x7x365 application. For instance, running &lt;a href="http://www.microsoft.com/windowsazure/pricing/" target="_blank"&gt;two small web roles&lt;/a&gt; in Windows Azure to create a high availability website would cost &lt;strong&gt;$0.12*2*24*30 = $172.80 a month&lt;/strong&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;h2&gt;



Choosing a Hosting Provider:&lt;/h2&gt;
So now that you have an idea of the different types of hosting, all you have to do is find a hosting provider that offers a solution that meets your needs. I have worked with ASP.NET websites of various sizes for the last 5-10 years and can highly recommend the following companies based on my experience with them:&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="http://services.superb.net/affiliate.php?affiliate=3969&amp;amp;url=superb.net" target="_blank"&gt;Superb.net&lt;/a&gt;: Offers all types of hosting ranging from shared to dedicated to virtual machines and custom quotes. Their VPS product is very affordable starting at $35 per month for a Win 2003 server or $20 per month for a Linux server. They also have great rates on dedicated servers starting at around $70-$80 a month. I had a server with them for about 10 years and they have always had great support and great prices. &lt;/li&gt;
&lt;li&gt;&lt;a href="https://manage.accuwebhosting.com/aff.php?aff=358" target="_blank"&gt;AccuWebHosting.com&lt;/a&gt;: Recently I moved my Windows server over to a VPS hosted at AccuWebHosting. They are not as large as Superb.net, but they offer some of the the best rates on VPS servers starting at $23 per month for Windows or $16.50 per month for Linux. While not as powerful as a dedicated server the VPS servers work great for light web or application servers.&lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.rackspace.com/" target="_blank"&gt;Rackspace.com&lt;/a&gt;: Offers fully managed dedicated servers and colocation services with “Fanatical Support”. They are a premium provider and cost a bit more than their competitors (starting around $500-$600 a month for a mid-range server), but if your application is mission critical you can feel comfortable turning over the keys to them and they will make sure your servers remain online and operational. Also Rackspace is the only vendor I have ever been able to get to sign a HIPAA compliant Business Associate Agreement (BAA). &lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.rackspacecloud.com/" target="_blank"&gt;Rackspacecloud.com&lt;/a&gt;: Originally called Mosso it was rebranded in July 2009 and offers Cloud CDN, Website, and Server solutions. They have managed servers starting at &lt;a href="http://www.rackspacecloud.com/cloud_hosting_products/servers/pricing" target="_blank"&gt;less than $100 a month&lt;/a&gt;, so if you want “Fanatical Support” without the high costs this might be a good place to start. &lt;/li&gt;
&lt;li&gt;&lt;a href="http://aws.amazon.com/ec2/pricing/" target="_blank"&gt;Amazon EC2&lt;/a&gt;: EC2 is the most mature of the online cloud providers and offers the most pricing options including &lt;a href="http://serverfault.com/questions/164476/confused-by-amazon-ec2-spot-price-and-on-demand-price-help-needed/164558#164558" target="_blank"&gt;Spot and Reserved instances&lt;/a&gt;. If you envision scaling out to hundreds of servers it is well worth your time to check out EC2. Their &lt;a href="http://aws.amazon.com/s3/" target="_blank"&gt;Simple Storage Service (S3)&lt;/a&gt; is also one of the best storage providers as it offers two price points depending on the level of durability that you require. &lt;/li&gt;
&lt;li&gt;&lt;a href="http://www.microsoft.com/windowsazure/pricing/" target="_blank"&gt;Windows Azure&lt;/a&gt;: Designed for high reliability and easier development, Azure is worth looking into if you are starting a new Microsoft .NET project that will require multiple servers. They are the new kid on the block, having been officially released in February 2010, but their use of Roles instead of servers means an application can be easily scaled up or down as needed. Also SQL Azure is a great way to create a hosted MS SQL database, as you pay $10 per GB per month, which combined with $0.15/GB/Month for blob storage means you should be able to store all your data and images/files for relatively cheap and support a large number of simultaneous users. Check out an &lt;a href="http://blog.richard.parker.name/2010/06/30/an-introduction-to-windows-azure-for-busy-people/" target="_blank"&gt;introduction to Windows Azure&lt;/a&gt; for more information and watch the &lt;a href="http://channel9.msdn.com/Shows/Cloud+Cover/Cloud-Cover-Episode-25-Deploying-and-Upgrading" target="_blank"&gt;Cloud Cover show&lt;/a&gt; on Channel 9 for great coverage. &lt;/li&gt;
&lt;/ul&gt;
I hope this helps as you look at designing or scaling out your application or website. If you have questions I highly suggest asking them on one of the &lt;a href="http://stackexchange.com/sites" target="_blank"&gt;StackExchange&lt;/a&gt; websites such as &lt;a href="http://stackoverflow.com/" target="_blank"&gt;ServerFault.com&lt;/a&gt; or &lt;a href="http://webmasters.stackexchange.com/" target="_blank"&gt;Webmasters.StackExchange.com&lt;/a&gt;. There are usually lots of great people there willing to help answer questions.&lt;img src="http://feeds.feedburner.com/~r/TheG2NetCode/~4/PXWti8MW5FY" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/TheG2NetCode/~3/PXWti8MW5FY/vpsvm-vs-dedicated-vs-cloud-servers.html</link><author>noreply@blogger.com (Greg Bray)</author><thr:total>3</thr:total><feedburner:origLink>http://codeblog.theg2.net/2010/10/vpsvm-vs-dedicated-vs-cloud-servers.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6011603498138679949.post-1001061262623386864</guid><pubDate>Sun, 19 Sep 2010 23:51:00 +0000</pubDate><atom:updated>2010-10-06T16:19:49.904-06:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Over Complicated</category><category domain="http://www.blogger.com/atom/ns#">Tips n Tricks</category><category domain="http://www.blogger.com/atom/ns#">.NET</category><category domain="http://www.blogger.com/atom/ns#">XAML</category><category domain="http://www.blogger.com/atom/ns#">Silverlight</category><category domain="http://www.blogger.com/atom/ns#">WP7</category><category domain="http://www.blogger.com/atom/ns#">Data Binding</category><title>Localization and Globalization in WP7 Applications Using Resource Files</title><description>I’ve been watching the progress of &lt;a href="http://blog.theg2.net/2010/08/windows-phone-7-pocket-xbox.html" target="_blank"&gt;Windows Phone 7&lt;/a&gt; for a while now and recently started developing &lt;a href="http://blog.phrasememe.com/" target="_blank"&gt;a few applications&lt;/a&gt; that I hope to release to the marketplace when it opens later this year. One of the apps I have been working on uses .NET Resource files to allow label and button text to be translated into other languages. While the idea is simple the implementation was a bit more complicated than what I was expecting, so I thought I would post some details here to help guide others.&lt;br /&gt;
&lt;br /&gt;
First off, if you are not familiar with .NET Resource files, I suggest watching this video on &lt;a href="http://www.msdev.com/Directory/Description.aspx?eventId=1883" target="_blank"&gt;Globalization and Localization&lt;/a&gt; from the &lt;a href="http://www.msdev.com/Directory/SeriesDescription.aspx?CourseId=158" target="_blank"&gt;Windows Phone 7 in 7 training series&lt;/a&gt;, which gives a great overview of what each of the terms mean. In my case I was most interested in localization using separate resource files for each language, which was not covered in the video but is covered in the &lt;a href="http://msdn.microsoft.com/en-us/library/ff637520(v=vs.92).aspx" target="_blank"&gt;MSDN Windows Phone documentation&lt;/a&gt; linked to at the end of the video. This documentation was very helpful for setting up the resource files and creating a LocalizedStrings class, but after that they only provided one method of setting up the data binding for XAML objects. They also did not elaborate on some of the other options you can use when setting up localization resource files.&lt;br /&gt;
&lt;br /&gt;
After a few tries and a bit of Google-fu I was able to get things setup how I wanted by adding these additional steps:&lt;br /&gt;
&lt;ol&gt;
&lt;li&gt;I created all the Resource files and the LocalizedStrings class in a Localization folder to keep things organized. It use to be that the .RESX files had to be in a special Resource folder in Visual Studio, but with 2010 they can be stored anywhere you want. If you have a large application you would probably want to have multiple folders with their own set of resource files (ex: one for each UI page or section of your application). In this case you would still have a single LocalizedStrings class, but inside that class there would be public properties for multiple resource files (ex: MainPageResources, SettingsPageResources, etc…) instead of just one Localizedresources property.&amp;nbsp; &lt;/li&gt;
&lt;li&gt;The above articles specifically reference the en-US and es-ES cultures, but .NET also supports using just en or es for culture-invariant language specification, which is usually better if all you need is localization without currency or date/time format conversions. You can in fact create a general fr file that includes French translations and use that same file to support both France (fr-FR) and Canada (fr-CA) cultural variants. See MSDN for more information about the &lt;a href="http://msdn.microsoft.com/en-us/library/cc838238(VS.95).aspx" target="_blank"&gt;Hierarchical Organization of Resource Files&lt;/a&gt; and see this list for all of the &lt;a href="http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo(VS.95).aspx" target="_blank"&gt;specific languages and cultures supported by Silverlight&lt;/a&gt;.      &lt;/li&gt;
&lt;li&gt;The MSDN article shows you how to setup the files and create the LocalizedStrings class, but they then assume that you know how to use that class for data binding. Visual Studio 2010 and Silverlight handle data binding differently than Winforms, and it gets even more confusing since XAML also has it’s own definition of &lt;a href="http://msdn.microsoft.com/en-us/library/ms750613.aspx" target="_blank"&gt;Resources&lt;/a&gt; that are different then the .NET resources we just created. Silverlight also uses the term Resource to refer to files that use the the Build Action of "Content”, as these files get wrapped up into the .XAP file similar to how files with Build Action of "Resource” get embedded into the .Dll assembly (ex: &lt;a href="http://www.silverlightexamples.net/post/Load-Bitmap-Image-From-Resource-in-a-Single-Line-of-Code.aspx" target="_blank"&gt;loading an image from content or resource files&lt;/a&gt;). I found that instead of using the Text="{Binding Path=resourceFile.resourceName, Source={StaticResource Localizedresources }}" XAML syntax it was easier to use the following steps:&lt;/li&gt;
&lt;ol&gt;
&lt;li&gt;Open your primary XAML page (usually MainPage.xaml) in the Visual Studio designer&lt;/li&gt;
&lt;li&gt;Open the properties for the PhoneApplicationPage and set the DataContext to be Application.Resources –&amp;gt; LocalizedStrings. NOTE: if you already are using a DataContext object, then you should integrate the LocalizedStrings class into that object so that it has localization support.&lt;/li&gt;
&lt;li&gt;Once the Page’s DataContext has been set you can change the data binding for any control on the page by simply selecting the property (ex: text, checked, etc), selecting “Apply Data Binding…”, and setting the Path to Localizedresources.BtnText or whatever the name of the desired resource value is.&lt;/li&gt;
&lt;/ol&gt;
&lt;li&gt;If you want to change the text in the Application Bar you have to jump through a few hoop because it is not actually a Silverlight control and does not support data binding. Instead you have to &lt;a href="http://msdn.microsoft.com/en-us/library/ff637520(v=vs.92).aspx#sectionToggle2" target="_blank"&gt;create or update the Application Bar at runtime.&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;
I hope this helps!&lt;img src="http://feeds.feedburner.com/~r/TheG2NetCode/~4/X8Dd1aPTiD8" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/TheG2NetCode/~3/X8Dd1aPTiD8/localization-and-globalization-in-wp7.html</link><author>noreply@blogger.com (Greg Bray)</author><thr:total>0</thr:total><feedburner:origLink>http://codeblog.theg2.net/2010/09/localization-and-globalization-in-wp7.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6011603498138679949.post-2858422376823323120</guid><pubDate>Sat, 11 Sep 2010 00:26:00 +0000</pubDate><atom:updated>2010-09-10T18:26:39.484-06:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Over Complicated</category><category domain="http://www.blogger.com/atom/ns#">Tools</category><category domain="http://www.blogger.com/atom/ns#">VBScript</category><category domain="http://www.blogger.com/atom/ns#">Excel</category><category domain="http://www.blogger.com/atom/ns#">Regex</category><title>Excel 2010 Regular Expressions: Manually installing Morefunc 5 Add-in</title><description>&lt;p&gt;I came across a need to use regular expressions in a spreadsheet today. Usually in this case I would look at using a more powerful tool such as &lt;a href="http://www.resolversystems.com/products/resolver-one/" target="_blank"&gt;Resolver One&lt;/a&gt;, which I have added into my toolbox and used for &lt;a href="http://blog.theg2.net/search?q=resolver+one" target="_blank"&gt;many side projects&lt;/a&gt;, but in this case I was stuck using Excel for legacy reasons. Sadly even the latest version of Excel 2010 does not have built in support for Regular Expressions so you either have to drop into VBA code and write your own &lt;a href="http://lispy.wordpress.com/2008/10/17/using-regex-functions-in-excel/" target="_blank"&gt;Regex functions&lt;/a&gt; or install an add-on that has pre-built functions. This &lt;a href="http://mathfest.blogspot.com/2010/03/regular-expressions-in-excel.html" target="_blank"&gt;blog post&lt;/a&gt; brought me to a nice free add-on for Excel called &lt;a href="http://xcell05.free.fr/" target="_blank"&gt;Morefunc&lt;/a&gt; which has a bunch of Regex functions, but it doesn’t work right out of the box with Excel 2010. After installing it I had to follow &lt;a href="http://www.lytebyte.com/2009/01/08/how-to-add-and-remove-excel-add-in-or-plugins/" target="_blank"&gt;these instructions&lt;/a&gt; to manually add the Morefunc.xll, Morefunc11.xla, and Morefunc12.xlam files from the “C:\Program Files\Morefunc” folder. Once I did that and allowed macros on the spreadsheet then the new functions showed up under the Morefunc category and under the Functions section of the Formula ribbon group. Since I didn’t see these instructions posted anywhere else I figured I would post them here so that others could find them.&lt;/p&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TheG2NetCode/~4/Af6dLvq0grQ" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/TheG2NetCode/~3/Af6dLvq0grQ/excel-2010-regular-expressions-manually.html</link><author>noreply@blogger.com (Greg Bray)</author><thr:total>4</thr:total><feedburner:origLink>http://codeblog.theg2.net/2010/09/excel-2010-regular-expressions-manually.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6011603498138679949.post-949321857460593122</guid><pubDate>Mon, 14 Jun 2010 18:13:00 +0000</pubDate><atom:updated>2010-06-14T15:30:17.142-06:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">PowerShell</category><category domain="http://www.blogger.com/atom/ns#">MSSQL</category><category domain="http://www.blogger.com/atom/ns#">AWS</category><title>Powershell Backup All Databases Locally and to Amazon S3</title><description>&lt;p&gt;Previously I had posted a Powershell script that would use 7Zip to &lt;a href="http://codeblog.theg2.net/2010/02/powershell-7-zip-amazon-s3-upload.html" target="_blank"&gt;compress and encrypt a folder&lt;/a&gt; and then send it to Amazon S3. This script could have many uses, but in my case it was designed to fulfill the need for off site storage of compressed database backups. While it did all the heavy lifting of getting the data encrypted, compressed and uploaded to S3 I left the creation of the database backup folder as an exercise for the user to complete.&lt;/p&gt;  &lt;p&gt;I now have a working system that I would like to share in case anyone was unable to create the backup folder using Powershell. There were a few hiccups that I found, such as not being able to use the &lt;a href="http://stackoverflow.com/questions/2383605/powershell-transcript-is-empty-when-running-script-from-sql-agent-job-in-2005-sql" target="_blank"&gt;Start-Transcript method in a SQL Agent Job&lt;/a&gt; and having my &lt;a href="http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=36201&amp;amp;whichpage=1" target="_blank"&gt;MSDB data file triple in size&lt;/a&gt; after 3 months of backups, but after working out those issues the script provides a very cost effective method of creating both local and offsite database backups with 1 week or 1 month retention. Currently I have it running on a server with about 100 databases ranging in size from 7MB to 700MB with daily full backups and hourly differential backups being sent to Amazon S3 and stored with 1 month retention for about $5 a month. The total raw backup size is 2.2GB per full backup set and 100-400MB for each differential backup set, but the script gets about 10:1 compression so the daily storage on S3 is about 500MB total for all of the full and differential backups.&lt;/p&gt;  &lt;p&gt;You will need to modify the settings in both the psBackupAllDBtoAmazonS3.ps1 and ps7ZiptoAmazonS3.ps1 files to get this to work on your server, but once you do you can sit back and let the scripts do it’s magic. You can set it to run as a scheduled task, but we chose to run it as an SQL Agent Job so that our server monitoring software would notify us if there were any issues with the script.&lt;/p&gt;

&lt;textarea class="brush:ps" rows="118" cols="80"&gt;
#Description: Powershell 2.0 script to backup all databases in MS SQL Server to the local disk and then zip and encrypt the folder using 7zip and then send it to Amazon S3 for offsite storage.
#Author: Greg Bray (6/14/2010)
#Website: http://codeblog.theg2.net/2010/06/powershell-backup-all-databases-locally.html
#License: free for personal or commercial use under the Creative Commons Attribution 3.0 United States License.
#Prerequisite: You must first install the latest version of 7Zip from http://www.7-zip.org/ (licensed under the GNU LGPL)
#Prerequisite: You must also install the Amazon Web Services SDK for .NET from http://aws.amazon.com/sdkfornet/ (licensed under the Apache License, Version 2.0)
#Prerequisite: You must also download the ps7ZiptoAmazonS3.ps1 from http://codeblog.theg2.net/2010/02/powershell-7-zip-amazon-s3-upload.html
#Prerequisite: You must set the settings listed below as well as the settings listed in the ps7ZiptoAmazonS3.ps1 file
#Recommended: I recommend using CloudBerry S3 Explorer for managing Amazon S3 files. http://cloudberrylab.com/default.aspx?page=cloudberry-explorer-amazon-s3
#Recommended: I recommend using http://PowerGui.org Script editor if you want to change or debug this script.

&lt;#Example calling from Run, a batch file, SQL Agent Job, or the task Scheduler: NOTE: may need to run "Set-ExecutionPolicy RemoteSigned" in powershell to allow unsigned local scripts to execute
powershell.exe -Command "&amp; 'c:\Backup\psBackupAllDBtoAmazonS3.ps1'"
#&gt;

#Script will backup all active databases on the server except those listed on an exclusion list. 
#Performs Differential backup except when $bFullBackup is true (currently set to do full backup when run between 00:00 and 01:00)
#Uses a 1 week local retention and either a 1 week or 1 month offsite retention on Amazon S3 depending on the definition of $S3FilePath
#Offsite files will be compressed and encrypted using 7zip. Local files will not be compressed or encrypted.
#There also will be a transcript log created that can be used to monitor the script. NOTE: If run using SQL Agent Job Start-Transcript will not work.
$strLogfile = "c:\Backup\Backup Log.rtf"
if (($host.Name -notmatch '^PowerGUI') -and ($host.name -ne "Windows PowerShell ISE Host")) {#PowerGUI and ISE Hosts do not support transcriptions yet :-(
    #Start-Transcript $strLogfile -Append | Out-Null #Append output to log file. Disabled as SQL Agent Jobs don't work with powershell transcripts
    #NOTE: Transcripts don't work with SQL Agent Jobs either... See http://stackoverflow.com/questions/2383605/powershell-transcript-is-empty-when-running-script-from-sql-agent-job-in-2005-sql
}

#Settings
$strBackupPathBase = "c:\Backup" #Base path on server where to store backups. NOTE: Do not include trailing slash.
$arrDBsToExclude = @("tempdb", "master") #DBs not included in the backup set. NOTE: Master database does not support differential backups, but will be included in full backups (see $strBackupQuery definition below)
$dtStart = [DateTime]::Now #capture start date to track total time
$bFullBackup = ($dtStart.Hour -eq 0) #Perform full backup instead of differential when run between 00:00 and 01:00
$strDateTimeStamp = $dtStart.ToString("yyyy-MM-dd_HHmm").ToUpper() #Timestamp appended to all backup files. NOTE: this is not the actual backup time, but when the script starts running
$strBackupPath = "{0}\{2}-{1:ddd}\{1:HH}" -f $strBackupPathBase, $dtStart, $dtStart.DayOfWeek.value__ #Full path where files will be stored locally (1 week retention). If folder exists it will be deleted
#See $S3FilePath and DB Connection string definitions below. Also update encryption settings in ps7ZiptoAmazonS3.ps1
Write-Host ("`r`n`r`n{0} - Starting SQL Server Differential backup with these parameters:`r`n`tBackupPath='{1}'`r`n`tTimestamp={2}`r`n`tFullBackup={3}`r`n`tExclude Databases: ${arrDBsToExclude}" -f [DateTime]::Now, $strBackupPath,$strDateTimeStamp,$bFullBackup)

#Delete backup directory if it already exists. This creates a 1 week local retention for the backup files
if([System.IO.Directory]::Exists($strBackupPath)){
    Remove-Item $strBackupPath -Force -Recurse
}
New-Item $strBackupPath -type directory | Out-Null #Create directory again

#Setup database connection 
$conn = new-object System.Data.SqlClient.SqlConnection
$conn.ConnectionString = 'Data Source=localhost;Initial Catalog=master;User ID=sa;Password=SAPASSWORD' #NOTE: use ' instead of " to prevent issue with $ character
if($conn.State -ne [System.Data.ConnectionState]::Open){ $conn.Open();} #Open connection if not already open

#Get a list of all databases
$cmd = new-object System.Data.SqlClient.SqlCommand
$cmd.Connection=$conn
$cmd.CommandType = [System.Data.CommandType]::Text
$cmd.CommandText= "SELECT name FROM sys.databases"
$sqlReader = $cmd.ExecuteReader()
$lstDatabases = New-Object System.Collections.ArrayList
while ($sqlReader.Read() -eq $true){
    [void]$lstDatabases.Add($sqlReader.GetString(0)) #Add database name to list
}
$sqlReader.Close()

#Backup all databases to disk
$strBKType = "DIFF"
$intBackups = 0
$strBackupQuery = "BACKUP DATABASE [{0}] TO DISK = '{1}' WITH DIFFERENTIAL, INIT" #0: Database name, 1: Backup file path
if($bFullBackup){# Perform full backup instead of differential
    $strBackupQuery = "BACKUP DATABASE [{0}] TO DISK = '{1}' WITH INIT" #0: Database name, 1: Backup file path
    $arrDBsToExclude = @() + ($arrDBsToExclude | where {$_ -notmatch "master"}) #make sure master database is included in the full backup
    $strBKType = "FULL"
}
foreach($strDatabase in $lstDatabases){
    if($arrDBsToExclude -notcontains $strDatabase){
        #write-Host ("`r`n{0} - Backing up database: {1}" -f [DateTime]::Now, $strDatabase)
        $strFilename = "{0}\{1}_{2}_{3}.bak" -f $strBackupPath, $strDatabase, $strBKType, $strDateTimeStamp
    
        $cmd = new-object System.Data.SqlClient.SqlCommand
        $cmd.Connection=$conn
        $cmd.CommandType = [System.Data.CommandType]::Text
        $cmd.CommandText=  $strBackupQuery -f $strDatabase, $strFilename
    
        $intBackups += 1
        $intReturn = $Null
        $intReturn = $cmd.ExecuteNonQuery()
        if ($intReturn -eq $Null) {
                write-Host ("{0} - Database {1} backup failed ({2} of {3}). Retry after 10 seconds." -f [DateTime]::Now, $strDatabase,$intBackups,$lstDatabases.Count)
            Start-Sleep -s 10
            $intReturn = $cmd.ExecuteNonQuery()
            if ($intReturn -eq $Null) {
                    write-Host ("{0} - Database {1} backup failed ({2} of {3}). Script aborted." -f [DateTime]::Now, $strDatabase,$intBackups,$lstDatabases.Count)
                exit 2 #Quit script if there is an error
            }
        }
        #write-Host ("{0} - Database {1} backed finished successfully ({2} of {3})" -f [DateTime]::Now, $strDatabase,$intBackups,$lstDatabases.Count)
    }
}

#Perform basic monthly db maintinece here. Will execute on first day of the month when the full backup is created
if($bFullBackup -and ($dtStart.Day -eq 0)){
    #Clean up MSDB backup history logs to prevent excessive growth of MSDB. See http://technet.microsoft.com/en-us/library/ms188328.aspx
    write-Host ("{0} - Start server maintinence: sp_delete_backuphistory on MSDB" -f [DateTime]::Now)
    $cmd = new-object System.Data.SqlClient.SqlCommand
    $cmd.Connection=$conn
    $cmd.CommandType = [System.Data.CommandType]::Text
    $cmd.CommandText= 'use msdb; Declare @date datetime; Set @date = dateadd (mm, -1, getdate()); Exec sp_delete_backuphistory @date' 
    $Null = $cmd.ExecuteNonQuery()
}

if($conn.State -eq [System.Data.ConnectionState]::Open){ $conn.Close();} #Close database connection

#Call powershell script to encrypt data and send it to Amazon S3. NOTE: there are other settings configured in the script file.
#$S3FilePath = "DB2/{2}-{0:ddd}/Hour_{0:HH}_{1}_Backup.7z" -f $dtStart,$strBKType,$dtStart.DayOfWeek.value__ #S3 path using DB2 bucket and 1 week retention
$S3FilePath = "DB2/{0:dd}/Hour_{0:HH}_{1}_Backup.7z" -f $dtStart,$strBKType #S3 path using DB2 bucket and 1 month retention
&amp; 'C:\Backup\ps7ZiptoAmazonS3.ps1' "$strBackupPath" "$S3FilePath"

$dtEnd = [DateTime]::Now
$tsTotal = $dtEnd.Subtract($dtStart) #Get total processing time
write-Host ("`r`n`r`n{0} - Finished SQL Server Backup. Total processing time: {1}`r`n`tBackup Path:{5}`r`n`tS3 Storage Path:{7}`r`n`tFull Backup:{6}`r`n`tTotal databases backed up: {2} of {3}`r`n`t{4} Exclusions: - ${arrDBsToExclude} " -f $dtEnd,$tsTotal,$intBackups,$lstDatabases.Count,$arrDBsToExclude.Count, $strBackupPath, $bFullBackup, $S3FilePath)
if (($host.Name -notmatch '^PowerGUI') -and ($host.name -ne "Windows PowerShell ISE Host")){
    #Stop-Transcript #Disabled for use with SQL Job.
}
exit $LASTEXITCODE #Make sure to pass exitcode from ps7ZiptoAmazonS3 to host for error tracking
&lt;/textarea&gt;&lt;img src="http://feeds.feedburner.com/~r/TheG2NetCode/~4/mIJaZ3lgdyM" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/TheG2NetCode/~3/mIJaZ3lgdyM/powershell-backup-all-databases-locally.html</link><author>noreply@blogger.com (Greg Bray)</author><thr:total>3</thr:total><feedburner:origLink>http://codeblog.theg2.net/2010/06/powershell-backup-all-databases-locally.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6011603498138679949.post-7834676921622884859</guid><pubDate>Fri, 16 Apr 2010 20:39:00 +0000</pubDate><atom:updated>2010-04-16T14:39:59.270-06:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">WPF</category><category domain="http://www.blogger.com/atom/ns#">Video</category><category domain="http://www.blogger.com/atom/ns#">.NET</category><category domain="http://www.blogger.com/atom/ns#">Fun</category><category domain="http://www.blogger.com/atom/ns#">Parallel Programming</category><category domain="http://www.blogger.com/atom/ns#">DLR</category><title>Lap Around .NET 4 with Scott Hanselman</title><description>&lt;p&gt;Things were slow at the office today, so I used the free time to catch up on some of the recorded sessions from DevDays 2010. &lt;a href="http://www.hanselman.com/" target="_blank"&gt;Scott Hanselman’s&lt;/a&gt; overview of the &lt;a href="http://channel9.msdn.com/posts/matthijs/Lap-Around-NET-4-with-Scott-Hanselman/" target="_blank"&gt;new features in .NET 4&lt;/a&gt; is one of the best presentation I have seen about .NET 4 so far. How many presentations include 14,000 generations of monkeys trying to write Shakespeare? Here is the synopsis:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;In this session, Scott Hanselman gives a deep and broad tour of the .NET 4 release, with a focus on making your development experience easier. See lots of demos (and very few slides) showcasing the key new features in the .NET Framework 4 including MEF, improvements in ASP.NET, threading, multi-core and parallel extensions, additions to the base classes, changes and additions to the CLR and DLR, what's new for the languages (Visual Basic and C#), and of course, what's new in Windows Presentation Foundation and System.Web. Come and see how all these new features and capabilities improve your overall .NET experience! &lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TheG2NetCode/~4/OvVpIt8Taes" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/TheG2NetCode/~3/OvVpIt8Taes/lap-around-net-4-with-scott-hanselman.html</link><author>noreply@blogger.com (Greg Bray)</author><thr:total>0</thr:total><feedburner:origLink>http://codeblog.theg2.net/2010/04/lap-around-net-4-with-scott-hanselman.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6011603498138679949.post-4545040804838319151</guid><pubDate>Sun, 14 Mar 2010 07:35:00 +0000</pubDate><atom:updated>2010-03-14T00:35:06.079-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">userscript</category><category domain="http://www.blogger.com/atom/ns#">JavaScript</category><category domain="http://www.blogger.com/atom/ns#">Bookmarklet</category><category domain="http://www.blogger.com/atom/ns#">Video</category><title>TED Fullscreen Video Multiple Monitor Userscript: Yay!</title><description>&lt;p&gt;I like to think that I can hack out &lt;a href="http://codeblog.theg2.net/search/label/JavaScript" target="_blank"&gt;JavaScript&lt;/a&gt; as good as any web developer, but occasionally I still fall into rookie mistakes. For instance, I totally forgot to test my last userscript for fixing &lt;a href="http://codeblog.theg2.net/2010/03/slashdot-zoom-fix-greasemonkey-and.html" target="_blank"&gt;Slashdot articles while zooming&lt;/a&gt; in anything but my default browser (Google Chrome). In theory it should have worked with Greasemonkey, but when I tried testing it today using Firefox it failed miserably. Luckily with a few &lt;a href="http://userscripts.org/scripts/show/70637" target="_blank"&gt;code changes&lt;/a&gt; I was able to update the script and get it to work with both Firefox and Google Chrome as well as fix a huge bug when visiting Slashdot’s main page as a non-registered user (another thing I probably should have tested!).&lt;/p&gt;  &lt;p&gt;Considering that it was my first attempt at a user script I am not too upset and will chalk it up to experience. Tonight my plans for the evening fell apart, so I decided to try and fix a big pet peeve of mine: no multiple monitor support for video players on certain websites. Maybe I am the only one that thinks this is a problem, but I hate it when websites have a Flash or Silverlight video player embedded onto their page and don’t have an option to enlarge the video or open it in a pop-out window. Most people do fine using the fullscreen mode built into the player, but both Silverlight and Flash &lt;a href="http://failblog.org/" target="_blank"&gt;fail&lt;/a&gt; at fullscreen with multiple monitors since they will exit fullscreen as soon as you try and click on something outside the video (for security purposes apparently). This means you can either stop multi-tasking and only watch the video or you have to settle for a small video player that is absolutely tiny on anything larger than 1024 resolution width. For instance: &lt;a href="http://bloghh.wordpress.com/2010/03/13/if-you-have-a-business-you-must-sell/" target="_blank"&gt;here is a video&lt;/a&gt; that a friend brought to my attention as viewed on a 1600x900 LCD TV. &lt;/p&gt;  &lt;p&gt;&lt;/p&gt; &lt;center&gt;&lt;a href="http://lh6.ggpht.com/_G06mB5h-kvQ/S5yRpgyn-5I/AAAAAAAAGiI/yOtC1Sjt7Ng/s1600-h/Sample%5B26%5D.png" target="_blank"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Sample" border="0" alt="Sample" src="http://lh5.ggpht.com/_G06mB5h-kvQ/S5yRqaPbl8I/AAAAAAAAGiQ/w_O0MdmoztY/Sample_thumb%5B22%5D.png?imgmax=800" width="646" height="304" /&gt;&lt;/a&gt;&lt;/center&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;That is a lot of white space going to waste, and while the fullscreen mode works I often watch videos on the LCD TV while browsing the web on a projector connected to the same computer and end up switching in and out of fullscreen mode multiple times. I’ve had this same problem before with Channel9 and fixed it using a &lt;a href="http://codeblog.theg2.net/2009/11/channel-9-full-screen-video-player-my.html" target="_blank"&gt;bookmarklet&lt;/a&gt;, but that actually requires clicking a link in my favorites every time I loaded a video, which was less than ideal. Now that Chrome supports userscripts I am working on converting some of the bookmarklets that I have into userscripts, and since I already have a working solution for Channel9 I thought that I would try creating one for &lt;a href="http://TED.Com" target="_blank"&gt;TED.com&lt;/a&gt; next.&lt;/p&gt;  &lt;p&gt;So if you ever watch TED videos on a machine with multiple monitors then today is your lucky day.&amp;#160; This userscript will &lt;a href="http://userscripts.org/scripts/show/71411" target="_blank"&gt;enable multiple monitor fullscreen video&lt;/a&gt; for any page that uses the TED.Com flash player. Videos that are embedded from YouTube currently are not supported, but YouTube already lets you increase the width of the player, open it in a pop-out window, or even use the browser’s zoom feature to resize the video so that shouldn’t be a problem. And this time I did do some basic testing in both Firefox and Chrome so hopefully it will work as advertised.&lt;/p&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TheG2NetCode/~4/ECgEprCcX34" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/TheG2NetCode/~3/ECgEprCcX34/ted-fullscreen-video-multiple-monitor.html</link><author>noreply@blogger.com (Greg Bray)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh5.ggpht.com/_G06mB5h-kvQ/S5yRqaPbl8I/AAAAAAAAGiQ/w_O0MdmoztY/s72-c/Sample_thumb%5B22%5D.png?imgmax=800" height="72" width="72" /><thr:total>4</thr:total><feedburner:origLink>http://codeblog.theg2.net/2010/03/ted-fullscreen-video-multiple-monitor.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6011603498138679949.post-3269897090282426206</guid><pubDate>Fri, 05 Mar 2010 23:40:00 +0000</pubDate><atom:updated>2010-03-05T16:50:15.766-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">userscript</category><category domain="http://www.blogger.com/atom/ns#">JavaScript</category><category domain="http://www.blogger.com/atom/ns#">Bookmarklet</category><category domain="http://www.blogger.com/atom/ns#">CSS</category><category domain="http://www.blogger.com/atom/ns#">HTML</category><title>Slashdot Zoom Fix: a Greasemonkey and Chrome compatible userscript</title><description>&lt;p&gt;One of my top ten visited websites is probably &lt;a href="http://www.slashdot.org"&gt;Http://www.slashdot.org&lt;/a&gt; who’s headline is “News for nerds, stuff that matters”. The site usually posts over 20 stories a day covering technology, math, physics, and computer related topics, which help me keep informed and entertained. One problem that I often have is that the text size is very hard to read when using a high resolution monitor or when using the projector that I have setup on a media center computer at home. Usually this is easy to solve, since one of the &lt;a href="http://blog.theg2.net/2009/04/who-needs-100-mouse-you-do.html" target="_blank"&gt;11 buttons on my mouse&lt;/a&gt; is mapped to the CTRL button and can be combined with the scroll wheel to zoom in and out on web pages quickly. However in this case there are boxes on the right hand side of the screen that also enlarge when the page is zoomed, causing the text width to be smaller and more difficult to read. Here is an article on Slashdot normal and zoomed:&lt;/p&gt;  &lt;div align="center"&gt; &lt;table border="1" cellspacing="0" cellpadding="2" width="600" align="center"&gt;&lt;tbody&gt;       &lt;tr&gt;         &lt;td valign="top" width="300"&gt;&lt;center&gt;&lt;a href="http://lh5.ggpht.com/_G06mB5h-kvQ/S5GWTDuD-4I/AAAAAAAAGek/jeKl8Aenqf0/s1600-h/Slashdot%20Normal%5B2%5D.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Slashdot Normal" border="0" alt="Slashdot Normal" src="http://lh5.ggpht.com/_G06mB5h-kvQ/S5GWT400FUI/AAAAAAAAGes/coBMMor8K44/Slashdot%20Normal_thumb.png?imgmax=800" width="244" height="184" /&gt;&lt;/a&gt;             &lt;br /&gt;Normal&lt;/center&gt;&lt;/td&gt;          &lt;td valign="top" width="300"&gt;&lt;center&gt;&lt;a href="http://lh5.ggpht.com/_G06mB5h-kvQ/S5GWUqC5z7I/AAAAAAAAGe0/O3P1rkJWjPs/s1600-h/Slashdot%20Zoomed%5B2%5D.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Slashdot Zoomed" border="0" alt="Slashdot Zoomed" src="http://lh3.ggpht.com/_G06mB5h-kvQ/S5GWVWg8mRI/AAAAAAAAGe8/SP7P0xFVu3U/Slashdot%20Zoomed_thumb.png?imgmax=800" width="244" height="184" /&gt;&lt;/a&gt;            &lt;br /&gt;Zoomed &lt;/center&gt;&lt;/td&gt;       &lt;/tr&gt;     &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt;  &lt;p&gt;&lt;/p&gt;  &lt;p&gt;The site is designed using CSS and for some reason the advertisement and “Interviews” box will get bigger when the page is zoomed, shrinking the width of the textbox significantly. If you are a registered user Slashdot will not display the ad but will still have a side panel on the right that grows larger when you try and zoom in. I initially created a bookmarklet that could be used to remove the side panel by clicking on a link in my favorites to inject some javascript into the webpage to alter the CSS classes, but that still required that I manually click the button every time that I visit he website. &lt;/p&gt;  &lt;p&gt;I planned on making a Google Chrome Extension, but recently Chrome announce that they now will automatically convert &lt;a href="http://googlesystem.blogspot.com/2009/11/google-chrome-converts-user-scripts.html" target="_blank"&gt;Greasemonkey scripts into Chrome Extensions&lt;/a&gt;. This means you can write a cross-browser compatible script that can run in Firefox, Chrome or any other browser that supports &lt;a href="http://en.wikipedia.org/wiki/Greasemonkey" target="_blank"&gt;Greasemonkey&lt;/a&gt; scripts. It only took a few minutes to convert the bookmarklet into a userscript, and I posted it on &lt;a href="http://userscripts.org/scripts/show/70637" target="_blank"&gt;userscripts.org&lt;/a&gt; so that anyone can use it. The script will automatically remove the sidebar so that zooming works much better. You can even change the script to automatically zoom a specified amount, however I left this off by default since the right amount highly depends on the width of your screen. Here are the results:&lt;/p&gt;  &lt;div align="center"&gt;   &lt;table border="1" cellspacing="0" cellpadding="2" width="602" align="center"&gt;&lt;tbody&gt;       &lt;tr&gt;         &lt;td valign="top" width="300"&gt;&lt;center&gt;&lt;a href="http://lh3.ggpht.com/_G06mB5h-kvQ/S5GWV3riLlI/AAAAAAAAGfE/2AmCt-x0ANI/s1600-h/Slashdot%20Fix%20Zoom%20User%20Script%5B2%5D.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Slashdot Fix Zoom User Script" border="0" alt="Slashdot Fix Zoom User Script" src="http://lh6.ggpht.com/_G06mB5h-kvQ/S5GWWmEe4dI/AAAAAAAAGfM/p9MFdcpOcXY/Slashdot%20Fix%20Zoom%20User%20Script_thumb.png?imgmax=800" width="244" height="184" /&gt;&lt;/a&gt;&amp;#160;&amp;#160; &lt;br /&gt;Normal&lt;/center&gt;&lt;/td&gt;          &lt;td valign="top" width="300"&gt;&lt;center&gt;&lt;a href="http://lh3.ggpht.com/_G06mB5h-kvQ/S5GWXMedIuI/AAAAAAAAGfU/rX5HtFUQnsQ/s1600-h/Slashdot%20Fix%20Zoom%20User%20Script%20%28zoomed%29%5B2%5D.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="Slashdot Fix Zoom User Script (zoomed)" border="0" alt="Slashdot Fix Zoom User Script (zoomed)" src="http://lh6.ggpht.com/_G06mB5h-kvQ/S5GWX8y1qaI/AAAAAAAAGfc/PlaFWwHMlac/Slashdot%20Fix%20Zoom%20User%20Script%20%28zoomed%29_thumb.png?imgmax=800" width="244" height="184" /&gt;&lt;/a&gt;             &lt;br /&gt;Zoomed&lt;/center&gt;&lt;/td&gt;       &lt;/tr&gt;     &lt;/tbody&gt;&lt;/table&gt; &lt;/div&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt;  &lt;p&gt;Hopefully someone else will find this useful. I have a few other bookmarklets that I use and will probably convert into userscripts soon, as well as a few new ones that I want to work on when I get some free time.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TheG2NetCode/~4/NihRveHRFGg" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/TheG2NetCode/~3/NihRveHRFGg/slashdot-zoom-fix-greasemonkey-and.html</link><author>noreply@blogger.com (Greg Bray)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh5.ggpht.com/_G06mB5h-kvQ/S5GWT400FUI/AAAAAAAAGes/coBMMor8K44/s72-c/Slashdot%20Normal_thumb.png?imgmax=800" height="72" width="72" /><thr:total>1</thr:total><feedburner:origLink>http://codeblog.theg2.net/2010/03/slashdot-zoom-fix-greasemonkey-and.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6011603498138679949.post-209502873748720276</guid><pubDate>Fri, 19 Feb 2010 23:08:00 +0000</pubDate><atom:updated>2010-06-14T12:17:54.901-06:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Tools</category><category domain="http://www.blogger.com/atom/ns#">.NET</category><category domain="http://www.blogger.com/atom/ns#">PowerShell</category><category domain="http://www.blogger.com/atom/ns#">Cloud Computing</category><title>Powershell, 7-Zip, Amazon S3 Upload Script with AES-256 Encryption</title><description>&lt;p&gt;I recently was tasked with finding a way to store some backup files from our server in a secure and reliable off-site location. After talking with our hosting provider, who wanted around $600 a month for off-site tape rotation, we decided to look at using &lt;a href="http://aws.amazon.com/s3/" target="_blank"&gt;Amazon Simple Storage Service&lt;/a&gt; (Amazon S3) to store the files in the cloud instead. We needed a way to automate the upload process and make sure that the data was encrypted, so I spent a few days working on a Powershell script (using the &lt;a href="http://powergui.org" target="_blank"&gt;excellent PowerGui Script Editor&lt;/a&gt;) that uses &lt;a href="http://www.7-zip.org/" target="_blank"&gt;7-zip&lt;/a&gt; to create a .7z archive with AES-256 encryption and then send it up to Amazon S3 using the &lt;a href="http://aws.amazon.com/sdkfornet/" target="_blank"&gt;Amazon Web Services SDK for .NET&lt;/a&gt;. Here is the script:&lt;/p&gt;  &lt;p&gt;&lt;textarea class="brush:ps" rows="118" cols="80"&gt;
#Description: Powershell 2.0 script to zip and encrypt a folder using 7zip and then send it to Amazon S3
#Author: Greg Bray (2/19/2010)
#Website: http://codeblog.theg2.net/2010/02/powershell-7-zip-amazon-s3-upload.html
#License: free for personal or commercial use under the Creative Commons Attribution 3.0 United States License.
#Prerequisite: You must first install the latest version of 7Zip from http://www.7-zip.org/ (licensed under the GNU LGPL)
#Prerequisite: You must also install the Amazon Web Services SDK for .NET from http://aws.amazon.com/sdkfornet/ (licensed under the Apache License, Version 2.0)
#Recommended: I recommend using CloudBerry S3 Explorer for managing Amazon S3 files. http://cloudberrylab.com/default.aspx?page=cloudberry-explorer-amazon-s3
#Recommended: I recommend using http://PowerGui.org Script editor if you want to change or debug this script.

#Usage: ps7ZiptoAmazonS3 'BackupFolderPath' 'S3ObjectKey' 'TranscriptLogFile'
#  BackupFolderPath = Folder to backup (do not include a trailing slash)
#  S3ObjectKey = Object key where to store file on Amazon S3. Note: If object already exists on S3 it will be overwritten.
#  TranscriptLogFile = Optional log file where the transcript will be appended.
#NOTE: you also will need to set the Zip and Encrypt settings, Amazon S3 settings, and 7Zip/AWSSDK file paths below

&lt;#Example calling from another powershell script (with log file): 
&amp; 'c:\Backups\ps7ZiptoAmazonS3.ps1' 'c:\Backups\DataFolder' 'S3Backups/DataFolder.7z' 'c:\Backups\BackupLog.txt'
#&gt;
&lt;#Example calling from Run or task Scheduler: NOTE: may need to run "Set-ExecutionPolicy RemoteSigned" in powershell to allow unsigned local scripts to execute
powershell.exe -Command "&amp; 'c:\Backups\ps7ZiptoAmazonS3.ps1' 'c:\Backups\DataFolder' 'S3Backups/DataFolder.7z' 'c:\Backups\BackupLog.txt'"
#&gt;

#Check arguments and set variables
if ($args.count -ge 2) {
    $FolderPath = $args[0] #Local folder to encrypt and send to S3 (No trailing slash)
    $S3ObjectKey = $args[1] #Destination on S3 where file will be stored. Note: If object exists it will be overwritten.
    if ($args.count -ge 3) { #start logging transcript
        Start-Transcript $args[2] -Append | Out-Null
    }
} else { #Default preset arguments used if no values are provided
    $FolderPath = "c:\Backups\DataFolder"
    $S3ObjectKey = "S3Backups/DataFolder.7z"
}
 
write-host "`r`n`r`n" #Start log file with 2 blank lines 
$dtStart = [System.DateTime]::Now #Save start time to calculate total time below
write-host ($dtStart.ToString() + " - Script started")

#Zip and Encrypt settings
$EncryptionKey = "secret_password" #Data is encrypted using Strong AES-256 encryption. Recommended password size is 10-16 characters.
$TemporaryPath = "c:\Temp" #No trailing slash. Used to store zip file localy before uploading. File will be deleted after upload but not if there is an exception (see below).

#Amazon S3 account settings (See http://aws-portal.amazon.com/gp/aws/developer/account/index.html?action=access-key):
$S3AccessKeyID = "ABCDEFGHIJKLMNOPQRST" #Your Amazon S3 Access Ky ID
$S3SecretKeyID = "0123456789abcdefghijklmnopqrstuvwzyz" #Your Amazon S3 Secret Access Key
$S3BucketName = "S3BackupBucket" #S3 Bucket name where the file will be stored
Write-Host ($dtStart.ToString() + " - FolderPath:'$FolderPath' S3BucketName:'$S3BucketName' S3ObjectKey:'$S3ObjectKey'")


#Load AWS Assembly and Initialize 7Zip path (only runs once when debugging script)
if($7ZipPath -eq $null){
    $7ZipPath = "C:\Program Files\7-Zip\7z.exe" #Path to 7Zip
    $AWSDOTNETSDKPath = "C:\Program Files (x86)\AWS SDK for .NET\bin\AWSSDK.dll" #Path to Amazon SDK for x64 system. Remove " (x86)" when running on an x86 machine
    if (-not [System.IO.File]::Exists($AWSDOTNETSDKPath)) { #Try path for x86 system
         $AWSDOTNETSDKPath = $AWSDOTNETSDKPath.Replace(" (x86)","")
         if (-not [System.IO.File]::Exists($AWSDOTNETSDKPath)) { #File not found, throw exception
            write-error "ERROR: Cannot find Amazon Web Services SDK. Please download .NET SDK from http://aws.amazon.com/sdkfornet/ and update AWSDOTNETSDKPath in script."
            exit 2
         }
    }
    #Load AWS Assembly
    [Reflection.Assembly]::LoadFile($AWSDOTNETSDKPath) | Out-Null
}

#Function for computing Amazon S3 MD5 digest (128 bit base64 encoded) using System.Security.Cryptography.MD5
function Hash-MD5 ($file) {
    $cryMD5 = [System.Security.Cryptography.MD5]::Create()
    $fStream = New-Object System.IO.StreamReader ($file)
    $bytHash = $cryMD5.ComputeHash($fStream.BaseStream)
    $fStream.Close()
    return [Convert]::ToBase64String($bytHash)
}

#Zip and Encrypt files
Write-Host ([System.DateTime]::Now.ToString() + " - Zip and Encrypt Files")
$FolderName = $FolderPath.Substring($FolderPath.LastIndexOf("\")+1) #grab the name of the backup folder
$TimeStamp = [datetime]::Now.ToString("yyyy-MM-dd_HHmm") #Create unique timestamp string
$strFile = [String]::Format("{0}\{1}_{2}.7z", $TemporaryPath,$FolderName,$TimeStamp) #Create filename for the zip
#7z options: add, type 7z, Archive filename, Files to add (with wildcard. Change \* to \prefix* or \*.txt to limit files), compression level 9, password, encrypt filenames, Send output to host so it can be logged.
#See http://dotnetperls.com/7-zip-examples or the 7zip help file for more info on command line switches. 
#NOTE: -mx7 and -mx9 get around 10 to 1 compression for text files and take round 5 minutes for 1GB of data. Use -mx3 or -mx5 to increase speed but decrease compression level.
&amp; $7ZipPath "a" "-t7z" "$strFile" "$FolderPath\*" "-mx9" "-r" "-p$EncryptionKey" "-mhe" | out-host #Call 7z.exe to create archive file
if($LASTEXITCODE -ne 0){ #Detect errors from 7Zip. Note: 7z will crash sometimes if file already exists
        Write-Error "ERROR: 7Zip terminated with exit code $LASTEXITCODE. Script halted."
        exit $LASTEXITCODE
}

#Create Amazon PutObjectRequest. Details at http://docs.amazonwebservices.com/sdkfornet/latest/apidocs/html/T_Amazon_S3_Model_PutObjectRequest.htm
Write-Host ([System.DateTime]::Now.ToString()) " - Creating S3 PutObjectRequest"
$AmazonS3 = [Amazon.AWSClientFactory]::CreateAmazonS3Client($S3AccessKeyID, $S3SecretKeyID)
$S3PutRequest = New-Object Amazon.S3.Model.PutObjectRequest 
$S3PutRequest.BucketName = $S3BucketName
$S3PutRequest.Key = $S3ObjectKey
$S3PutRequest.FilePath = $strFile
Write-Host ([System.DateTime]::Now.ToString()) " - Compute File MD5 Digest"
$strMD5 = Hash-MD5($strFile) #NOTE: may take 5-30 seconds to compute digest for 1GB file.
$S3PutRequest.MD5Digest = $strMD5 #Use MD5 digest to ensure data is not corrupted during transport. 

$dFileSize = (Get-Item $strFile).Length / 1MB #Get archive size in MB
Write-Host ([System.DateTime]::Now.ToString()) ([String]::Format(" - Uploading File:'{0}' Size:{1:#,###.#} MB", $strFile, $dFileSize)) 
$S3Response = $AmazonS3.PutObject($S3PutRequest) #NOTE: upload defaults to 20 minute timeout.
#If upload fails it will throw an exception and $S3Response will be $null
if($S3Response -eq $null){
    Write-Error "ERROR: Amazon S3 put requrest failed. Script halted."
    exit 1
}

Write-Host ([System.DateTime]::Now.ToString()) " - Delete Local 7z File:'$strFile'"
Remove-Item $strFile -Force

$dtEnd = [datetime]::Now
$tsTotal = $dtEnd.Subtract($dtStart)
Write-Host ($dtEnd.ToString()) " - Script finished. Total time: " $tsTotal
write-host "`r`n`r`n" #End log file with 2 blank lines 

if ($args.count -ge 3) { #stop transcript
    Stop-Transcript
}
&lt;/textarea&gt;&lt;/p&gt;  &lt;p&gt;It seems to work pretty well so far, taking about 5-10 minutes to zip and encrypt 1GB of SQL Backups down to 100MB and then upload it to Amazon S3. From there we can use tools like &lt;a href="http://cloudberrylab.com/default.aspx?page=cloudberry-explorer-amazon-s3" target="_blank"&gt;CloudBerry S3 Explorer&lt;/a&gt; to browse or download files when needed. The monthly costs to keep data on Amazon S3 is $0.150 per GB, with $0.10 per GB transfer in and $0.150 per GB transfer out. With a 1 week backup retention and minimal data-out transfers we expect to pay around around $10 to $20 a month and should be able to access it much quicker than if we were using off-site tape storage. Cloud computing FTW!&lt;/p&gt;

&lt;p&gt;&lt;b&gt;UPDATE 6/14/2010&lt;/b&gt;: I just posted the script used to &lt;a target="_blank" href="http://codeblog.theg2.net/2010/06/powershell-backup-all-databases-locally.html"&gt;create the Database backup&lt;/a&gt; folder.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TheG2NetCode/~4/VDfzwEX8O7U" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/TheG2NetCode/~3/VDfzwEX8O7U/powershell-7-zip-amazon-s3-upload.html</link><author>noreply@blogger.com (Greg Bray)</author><thr:total>15</thr:total><feedburner:origLink>http://codeblog.theg2.net/2010/02/powershell-7-zip-amazon-s3-upload.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6011603498138679949.post-8844505391198683781</guid><pubDate>Fri, 12 Feb 2010 23:58:00 +0000</pubDate><atom:updated>2010-02-14T01:06:21.439-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Tips n Tricks</category><category domain="http://www.blogger.com/atom/ns#">Parallel Programming</category><category domain="http://www.blogger.com/atom/ns#">IronPython</category><title>Parallel ForEach file processing in IronPython: Get some TPL love in IPY!</title><description>&lt;p&gt;I recently have started playing around with the Task Parallel Library (TPL) that will be shipping in .NET 4, which lets you easily spread a workload across multiple cores using a simple Parallel.ForEach statement. I have a few IronPython scripts that I want to convert to start using multiple threads, so I thought I would try using the &lt;a href="http://codeblog.theg2.net/2010/02/tpl-and-parallelforeach-in-net-35-using.html" target="_blank"&gt;.NET 3.5 version of the TPL&lt;/a&gt; from inside of IronPython. It turns out that the TPL works just fine, but writing thread safe code in IronPython can be tricky. First off, the System.Threading.Interlocked class does not work on IronPython integers because &lt;a href="http://lists.ironpython.com/pipermail/users-ironpython.com/2008-November/008960.html" target="_blank"&gt;python integers are immutable&lt;/a&gt;. That really sucks, because it means that the only way to change a global integer value in a thread safe manner is to use &lt;a href="http://old.nabble.com/Converting-C--to-Python-...-the-lock()-keyword--td27114498.html" target="_blank"&gt;locks or the System.Threading.Monitor class&lt;/a&gt;. One interesting workaround is to use a python list instead of an integer. Appending a value to a list is an atomic operation, so instead of calling Interlocked.Add you can just append all the values to an empty list an use sum to return the aggregate value or len() to get the number of items in the list (emulating incrementing a variable). It is a bit of a hack, but sometimes easier that using locks. Also, you have to remember that the print statement is not thread safe, so instead you should use something like System.Text.StringBuilder to buffer your print statements and then print them once you are back to a single thread code section.&lt;/p&gt;  &lt;p&gt;Below is a small sample script that I wrote to test processing a large number of text files using IronPython. It will search through all files in a given directory that match a given pattern (ie: *.txt) and return the total number of files and lines. It will also search for a given tolken inside each file and return the total number of matches. This is a task that is very easy to run on multiple cores and is a perfect fit for the Parallel.ForEach method. By default it will search your temporary files folder, which on my workstation had 69 .txt files with a total of 469,286 lines. The single threaded version took about 2.3 seconds to run and the multi-threaded version took between 0.8 and 1.0 seconds. The workload was spread across 8 cores, which caused a 2x improvement in speed, even thought this example is still primarily bound by the drive IO speed. Still it shows how using the TPL can greatly increase performance for common tasks.&lt;/p&gt;  

&lt;textarea class="brush: py;" rows="130" cols="80"&gt;
"""Uses the Task Parallel Libray (TPL) to processes files using multiple threads.
Please download and install the Reactive Extensions (Rx) for .Net 3.5 from http://msdn.microsoft.com/en-us/devlabs/ee794896.aspx before running this script
Usage: import the file into an existing script or run the following from the IronPython console:
execfile("c:\PathToFile\Filename.py")
"""
import clr
from System import Environment
from System.IO import File,Directory
from System.Diagnostics import Stopwatch
from System.Text import StringBuilder
from System.Threading import Monitor
clr.AddReference('System.Windows.Forms')


strAssembly = "C:\Program Files (x86)\Microsoft Reactive Extensions\Redist\DesktopV2\System.Threading.dll";
if not File.Exists(strAssembly): # Try both 32bit and 64bit file path
    strAssembly = "C:\Program Files\Microsoft Reactive Extensions\Redist\DesktopV2\System.Threading.dll";
    if not File.Exists(strAssembly): # Library does not exist, prompt with error message
        print "TPL assembly not found. Please download and install the Reactive Extensions (Rx) for .Net 3.5 from http://msdn.microsoft.com/en-us/devlabs/ee794896.aspx"
        raise Exception("Task Parallel Libray not found. Please download and install the Reactive Extensions (Rx) for .Net 3.5");
        #Rx and TPL for .NET 3.5 can be downloaded from  http://msdn.microsoft.com/en-us/devlabs/ee794896.aspx

#Load TPL
clr.AddReferenceToFileAndPath(strAssembly)
from System.Threading.Tasks import *

#Method to process files. See test call at bottom of file
def TPLProcessFiles(strTolken, strPath=None, strFilter="*.txt"):
    """Finds all occurences of strTolken in strPath for files that match strFilter.
        strTolken = string tolken used for searching. NOTE: search is case-insensitive and includes partial match (cat will match Category).
        strPath = Path to the directory used for searching. Default is system's temp directory
        strFilter = file match filter for search. Default is *.txt"""
    print "Start TPLProcessFiles('%s', '%s', '%s')" % (strTolken, strPath, strFilter)
    
    if strPath == None:
        strPath = Environment.GetEnvironmentVariable("TEMP")
        print "Using temporary files path: %s" % strPath
    elif not Directory.Exists(strPath):
        raise Exception("Invalid path: " + strPath)
    
    #Setup
    swTime = Stopwatch()
    swTime.Start()
    LogWriter.Reset()
    Results.Reset()
    strFiles = Directory.GetFiles(strPath, strFilter)

    #Single thread test code. Useful for when you get an AggregateException_ctor_DefaultMessage exception in the Parallel.ForEach version or for benchmarking
    #for aFile in strFiles:
    #    SearchFile(aFile, strTolken)
    
    #TPL version with multiple threads
    pfeResult = Parallel.ForEach(strFiles, lambda aFile: SearchFile(aFile, strTolken))
    
    print LogWriter.ToString() #Have to use LogWriter class below because print is not a threadsafe function
    strResults = Results.ToString() #Have to store results in a thread safe class
    swTime.Stop()
    print "Finished. Total Files: %d  LogCallCount: %d   Total Time: %0.3fs  Total Cores: %d" % (len(strFiles), LogWriter.GetCallCount(), float(swTime.ElapsedMilliseconds)/1000, Environment.ProcessorCount)
    print "Results - %s" % strResults

#File search method    
def SearchFile(strFilename, strTolken):
    """Method used for searching a file. This will be called from the Parallel.ForEach loop.
        Returns a tuple of (Filename, Total line count, Total tolken count).
        NOTE: Code must be thread safe, so you cannot use the print statement or increment global variables."""
    #LogWriter.WriteLine("Start file: %s searching for %s" % (strFilename, strTolken))
    f = open(strFilename, "r") #open file as readonly
    t = f.read() #get text
    f.close()
    Results.Add(1, t.count("\n"),t.count(strTolken)) #Add to global results

#Class used to store results    
class Results:
    Files = 0 #static members
    Lines = 0
    Tolkens = 0   
    
    @staticmethod
    def Reset(): #NOTE: this is not thread safe, but we will only call this method from a single thread
        Results.Files = 0
        Results.Lines = 0
        Results.Tolkens = 0

    @staticmethod
    def Add(intFiles, intLines, intTolkens):
        Monitor.Enter(Results) #Use the System.Threading.Monitor class to ensure addition is thread safe
        Results.Files += intFiles
        Results.Lines += intLines
        Results.Tolkens += intTolkens
        Monitor.Exit(Results) #Finish thread safe code

    @staticmethod
    def GetValues():
        return (Results.Files, Results.Lines, Results.Tolkens)
        
    @staticmethod
    def ToString():
        return "Total files: %d  Total lines: %d  Total tolkens: %d" % Results.GetValues()
        
#Log writer class to buffer print statements    
class LogWriter:
    sbLog = StringBuilder() #StringBuilder is thread safe when used as a static member
    CallCount = [] #Integer operations are not threadsafe, but appending to a list is
    
    @staticmethod
    def WriteLine(strMessage): #NOTE: must be thread safe. String 
        LogWriter.sbLog.Append(strMessage+"\r\n")
        LogWriter.CallCount.append(1)
    
    @staticmethod
    def ToString():
        return LogWriter.sbLog.ToString()
    
    @staticmethod
    def Reset():
        LogWriter.sbLog.Length = 0
        LogWriter.intCallCount = []    

    @staticmethod
    def GetCallCount():
        return sum(LogWriter.CallCount)

        
if __name__ == "__main__":
    TPLProcessFiles("Error") #Run test if this file is loaded from the IronPython Console
&lt;/textarea&gt;&lt;img src="http://feeds.feedburner.com/~r/TheG2NetCode/~4/g2A5pipxbdI" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/TheG2NetCode/~3/g2A5pipxbdI/parallel-foreach-file-processing-in.html</link><author>noreply@blogger.com (Greg Bray)</author><thr:total>1</thr:total><feedburner:origLink>http://codeblog.theg2.net/2010/02/parallel-foreach-file-processing-in.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6011603498138679949.post-764152777116694147</guid><pubDate>Sat, 06 Feb 2010 23:39:00 +0000</pubDate><atom:updated>2010-02-06T16:42:05.787-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">.NET</category><category domain="http://www.blogger.com/atom/ns#">Fun</category><category domain="http://www.blogger.com/atom/ns#">Parallel Programming</category><category domain="http://www.blogger.com/atom/ns#">Poker</category><title>TPL and Parallel.ForEach in .Net 3.5 using Reactive Extensions for .NET (Rx)</title><description>&lt;p&gt;The next version of the .Net framework and Visual Studio both have &lt;a href="http://codeblog.theg2.net/2010/01/vs2010-parallel-computing-features-tour.html" target="_blank"&gt;some pretty cool features&lt;/a&gt; to help programmers work with multiple cores, which is great but doesn’t help the majority of us that are stuck with .Net 3.5 for the foreseeable future. Luckily &lt;a href="http://channel9.msdn.com/shows/Going+Deep/Erik-Meijer-and-Team-Cloud-Data-Programmability-Connecting-the-Distributed-Dots/" target="_blank"&gt;Erik Meijer and the Cloud Programability Team&lt;/a&gt; have back ported the &lt;a href="http://en.wikipedia.org/wiki/Parallel_Extensions" target="_blank"&gt;Parallel Extensions Framework (PFX)&lt;/a&gt; to .Net 3.5 and Silverlight 3 as part of the &lt;a href="http://msdn.microsoft.com/en-us/devlabs/ee794896.aspx" target="_blank"&gt;Reactive Extensions for .NET (Rx)&lt;/a&gt;. Rx adds the IObservable&amp;lt;T&amp;gt; and IObserver&amp;lt;T&amp;gt; interfaces, which are the mathematical duality of the IEnumerable&amp;lt;T&amp;gt; and IEnumerator&amp;lt;T&amp;gt; and provide tools for doing &lt;a href="http://www.leading-edge-dev.de/?p=501" target="_blank"&gt;Reactive Programming.&lt;/a&gt; There are &lt;a href="http://rxwiki.wikidot.com/101samples" target="_blank"&gt;many different ways to use Rx&lt;/a&gt;, but internally they all use the Task Parallel Library (TPL) as the “special sauce” to automate processing tasks across multiple threads.&lt;/p&gt;  &lt;p&gt;Parallel.ForEach is a part of the TPL that can be used to unroll an outer loop and have it run across multiple threads. Take the following example. This is standard single threaded code that loops through a collection of 2 card Texas Holdem starting hands and evaluates all possible 7 card hands that include those two cards:&lt;/p&gt; 

&lt;textarea class="brush: py;" rows="11" cols="80"&gt;
//Enumerate all possible 2 card starting hands with an Ace and a King
foreach (var aPKAK in HoldemHand.PocketHands.Query(&amp;quot;AK&amp;quot;))
{
    //Enumerate and score all possible 7 card hands that include the starting hand
    foreach (var aHand in HoldemHand.Hand.Hands(aPKAK, 0, 7))
    {
        ulHand = HoldemHand.Hand.Evaluate(aHand);
        lCount++;
    }
}
&lt;/textarea&gt;  

&lt;p&gt;There are over 2 million hands in the inner loop, which gets run once for each of the possible starting hands in the outer loop. There are 12 offsuit starting hands and 4 suited starting hands with an Ace and a King, which means that the outer loop would run 16 times, however those 16 executions are separate and could easily be run across multiple threads. That is where Parallel.ForEach comes in. Here is the same code, which will automatically be scheduled across multiple threads:&lt;/p&gt; 

&lt;textarea class="brush: py;" rows="12" cols="80"&gt;//Use Parallel.ForEach and a Lambda Expression to get the same results
Parallel.ForEach(HoldemHand.PocketHands.Query(&amp;quot;AK&amp;quot;), aPKAK =&amp;gt;
{
    long plcount = 0; //Local loop count
    foreach (var aHand in HoldemHand.Hand.Hands(aPKAK, 0, 7))
    {
        ulHand = HoldemHand.Hand.Evaluate(aHand);
        plcount++;
    }
    //Use threadsafe method to increment global count
    System.Threading.Interlocked.Add(ref lCount, plcount);
});
&lt;/textarea&gt;

&lt;p&gt;The bulk of the code is the same, with the only changes being that the inner block gets converted into a Lambda Expression (could have also used a delegate) and instead of incrementing lCount in the inner loop we increment a local loop variable and then atomically add it to the global value. We could have used System.Threading.Interlocked.Increment to atomically increment lCount inside the inner loop, but this adds a lot of unneeded locks that slow down all the threads. Keeping a local copy of the values and only locking once at the end provides much better performance.&lt;/p&gt;  &lt;p&gt;And with those few small changes we are able to start using multiple threads, which on my local machine with 4 cores and 8 threads ended up decreasing the processing time from 1.55 seconds to 0.67 seconds and more than doubling the number of hands processed per second from 16,420,998 to 37,816,595.&lt;/p&gt;  &lt;p&gt;If you want to start using the TPL you can download it &lt;a href="http://msdn.microsoft.com/en-us/devlabs/ee794896.aspx" target="_blank"&gt;here&lt;/a&gt; and add a reference to the System.Threading.dll located in the “C:\Program Files (x86)\Microsoft Reactive Extensions\Redist\DesktopV2” folder. And while you are at it you might as well play around with Rx too!&lt;/p&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TheG2NetCode/~4/CduhmccQhHw" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/TheG2NetCode/~3/CduhmccQhHw/tpl-and-parallelforeach-in-net-35-using.html</link><author>noreply@blogger.com (Greg Bray)</author><thr:total>1</thr:total><feedburner:origLink>http://codeblog.theg2.net/2010/02/tpl-and-parallelforeach-in-net-35-using.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6011603498138679949.post-6031259373714016183</guid><pubDate>Wed, 20 Jan 2010 19:40:00 +0000</pubDate><atom:updated>2010-01-20T12:40:01.574-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Video</category><category domain="http://www.blogger.com/atom/ns#">.NET</category><category domain="http://www.blogger.com/atom/ns#">Windows</category><category domain="http://www.blogger.com/atom/ns#">Parallel</category><title>VS2010 Parallel Computing Features Tour: Wow!</title><description>&lt;p&gt;Microsoft Visual Studio 2010 and .NET Framework 4.0 are in beta 2 right now and should be available in a few months, but after watching videos about the features of &lt;a href="http://channel9.msdn.com/shows/Going+Deep/Inside-C-40-dynamic-type-optional-parameters-more-COM-friendly/" target="_blank"&gt;C# 4.0&lt;/a&gt; and the features of Visual Studio 2010 I don’t know how much longer I can wait! I just finished watching a video about the &lt;a href="http://channel9.msdn.com/posts/DanielMoth/VS2010-Parallel-Computing-Features-Tour/" target="_blank"&gt;parallel computing features in VS2010&lt;/a&gt; and I seriously am drooling over the multi-core programming tools available in the next release! C# 4.0 was introduced by &lt;a href="http://channel9.msdn.com/pdc2008/TL16/" target="_blank"&gt;Anders Hejlsberg at PDC 2008&lt;/a&gt;, but it is great to see it finally coming to fruition. And with .NET 4 splitting the download into &lt;a href="http://channel9.msdn.com/posts/Jaime+Rodriguez/NET-4-Client-Profile/" target="_blank"&gt;Client and Full profiles&lt;/a&gt; it now can be downloaded and installed on most machines at about half the size (30-40MB vs 70-160MB for .NET 3.5).&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TheG2NetCode/~4/ks5uTenWOPc" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/TheG2NetCode/~3/ks5uTenWOPc/vs2010-parallel-computing-features-tour.html</link><author>noreply@blogger.com (Greg Bray)</author><thr:total>0</thr:total><feedburner:origLink>http://codeblog.theg2.net/2010/01/vs2010-parallel-computing-features-tour.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6011603498138679949.post-6314031986436168457</guid><pubDate>Thu, 03 Dec 2009 23:56:00 +0000</pubDate><atom:updated>2009-12-03T16:56:58.147-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">.NET</category><category domain="http://www.blogger.com/atom/ns#">Watin</category><category domain="http://www.blogger.com/atom/ns#">Testing</category><title>Watin 2.0 and Gallio 3.1 in x64 environment: fixing System.Reflection.ReflectionTypeLoadException and System.Runtime.InteropServices.COMException "The interface is unknown" issues</title><description>&lt;p&gt;We use &lt;a href="http://www.gallio.org/" target="_blank"&gt;Gallio/MbUnit&lt;/a&gt; and &lt;a href="http://watin.sourceforge.net/"&gt;Watin&lt;/a&gt; at my work for unit testing of an ASP.NET website, as it provides &lt;a href="http://www.theroamingcoder.com/node/22" target="_blank"&gt;excellent reports&lt;/a&gt; including the raw Watin events (click, type, select) and &lt;a href="http://blog.benhall.me.uk/2007/12/watin-integration-into-mbunitgallio.html" target="_blank"&gt;screenshots for failed cases&lt;/a&gt;. Today I spent a few hours trying to get the project working on my new Windows 7 x64 development machine, and things did not start out very well. When I first tried to load the project in the Gallio Icarus runner none of the unit tests showed up and it indicated that an exception was thrown while exploring tests. I tried using both the x64 and x86 versions of Gallio/MbUnit, and even tried using the &lt;a href="http://testdriven.net/" target="_blank"&gt;TestDriven.NET&lt;/a&gt; loader from within Visual Studio, but couldn’t get anything to work. Here is the full error message for Google’s sake:&lt;/p&gt;  &lt;blockquote&gt;   &lt;pre&gt;[error] An exception was thrown while exploring tests.
Location: D:\SVN_Development\OQA Unit Testing\OQA Testing Framework\OQA Testing Framework\bin\Debug\OQA Testing Framework.EXE
Reference: OQA Testing Framework, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
Details: System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information. 
   at System.Reflection.Module._GetTypesInternal(StackCrawlMark&amp;amp; stackMark) 
   at System.Reflection.Assembly.GetTypes() 
   at Gallio.Common.Reflection.Impl.NativeAssemblyWrapper.GetTypes() in c:\RelEng\Projects\MbUnit v3.1\Work\src\Gallio\Gallio\Common\Reflection\Impl\NativeAssemblyWrapper.cs:line 72 
   at Gallio.Framework.Pattern.TestAssemblyPatternAttribute.PopulateChildrenImmediately(IPatternScope assemblyScope, IAssemblyInfo assembly) in c:\RelEng\Projects\MbUnit v3.1\Work\src\Gallio\Gallio\Framework\Pattern\TestAssemblyPatternAttribute.cs:line 147 
   at Gallio.Framework.Pattern.TestAssemblyPatternAttribute.Consume(IPatternScope containingScope, ICodeElementInfo codeElement, Boolean skipChildren) in c:\RelEng\Projects\MbUnit v3.1\Work\src\Gallio\Gallio\Framework\Pattern\TestAssemblyPatternAttribute.cs:line 75 
   at Gallio.Framework.Pattern.DefaultPatternEvaluator.Consume(IPatternScope containingScope, ICodeElementInfo codeElement, Boolean skipChildren, IPattern defaultPrimaryPattern) in c:\RelEng\Projects\MbUnit v3.1\Work\src\Gallio\Gallio\Framework\Pattern\DefaultPatternEvaluator.cs:line 153&lt;/pre&gt;
&lt;/blockquote&gt;

&lt;p&gt;The error message indicates that it is due to an issue with missing assemblies, and suggested that you make sure the CopyLocal option is set to true for all 3rd party references, but that didn’t help either. Finally I created a test project and started ripping the original project to peaces to find out why it was failing. Turns out it worked fine if I remove a reference to an interface stored in the Watin.Core.Dll assembly, so I setup a workaround and was finally able to load the tests. Only problem was that it would fail whenever the test tried to load Watin. At this point I figured it had to be an issue with the Watin dll, and it turns out that it was simply trying to load an x64 version of the library that doesn’t actually exist (the library is x86 only). &lt;a href="http://stackoverflow.com/questions/916769/watin-error-cannot-load" target="_blank"&gt;This link&lt;/a&gt; suggested setting Visual Studio to use x86 as the build platform type instead of “Any CPU”, and once I did that the original project started working. Yay!&lt;/p&gt;

&lt;p&gt;It didn’t take long though for something else to fail, as it threw an exception as soon as one of the tests tried to access the Document object. This time the exception was System.Runtime.InteropServices.COMException with Message=&amp;quot;The interface is unknown. (Exception from HRESULT: 0x800706B5)&amp;quot; coming from mshtml.HTMLDocumentClass.IHTMLDocument2_get_url(). Another quick search lead to another &lt;a href="http://stackoverflow.com/questions/1014815/how-do-you-get-watin-to-work-on-windows-server-2008-with-ie8" target="_blank"&gt;StackOverflow answer&lt;/a&gt; suggesting to run Visual Studio as an Administrator. That seem to do the trick!&lt;/p&gt;

&lt;p&gt;So if you are using an x64 machine to do unit testing with Gallio, MbUnit, and Watin, make sure to set the platform to x86 and make sure to run Visual Studio and Icarus as an Administrator! I should probably get back to working on those unit tests now :-P&lt;/p&gt;

&lt;p&gt;Enjoy!&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TheG2NetCode/~4/32jXDA1qnEI" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/TheG2NetCode/~3/32jXDA1qnEI/watin-20-and-gallio-31-in-x64.html</link><author>noreply@blogger.com (Greg Bray)</author><thr:total>3</thr:total><feedburner:origLink>http://codeblog.theg2.net/2009/12/watin-20-and-gallio-31-in-x64.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6011603498138679949.post-5633059212620007688</guid><pubDate>Tue, 10 Nov 2009 20:52:00 +0000</pubDate><atom:updated>2010-07-23T16:17:20.805-06:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">JavaScript</category><category domain="http://www.blogger.com/atom/ns#">Tips n Tricks</category><category domain="http://www.blogger.com/atom/ns#">Bookmarklet</category><category domain="http://www.blogger.com/atom/ns#">Video</category><category domain="http://www.blogger.com/atom/ns#">CSS</category><category domain="http://www.blogger.com/atom/ns#">HTML</category><title>Channel 9 Full Screen Video Player: My first Bookmarklet</title><description>&lt;p&gt;I really enjoy watching videos from &lt;a href="http://channel9.msdn.com" target="_Blank"&gt;Channel 9&lt;/a&gt;, Microsoft’s community site that targets users and developers. It is a great way to keep updated on the latest technologies and learn more about future products before they come out. The only thing that I don’t like is that the website is not very user friendly for people that have multiple monitors. This surprises me, as most developers that I know use at least two monitors, sometimes three or four. Even after their recent layout change, which increased the size of the video player significantly, the embedded video player is still too small to be able to read code from screencasts. There is of course a full screen button, but this doesn’t really work when multitasking on multiple monitors as it will close as soon as you click on another browser or window on another screen. Both Silverlight and Flash have this issue, which they consider to be a security feature, but it renders the full screen mode worthless useless you stop using your second monitor while watching the video. &lt;/p&gt;  &lt;p&gt;Currently there are only two workarounds to the Silverlight/Flash full screen issue, both of which &lt;a href="http://www.youtube.com/watch?v=Mh85R-S-dh8" target="_Blank"&gt;YouTube&lt;/a&gt; has already implemented using buttons at the top of the video player. The first is enlarging the video so that it takes up more of the page, and the second is opening it in a new page that can be resized to as large or small as you want. Alternatively you can use a different video player such as the embedded Windows Media Player, but while the WMV links on Channel 9 display full screen in the browser they sometimes have buffering or quality issues and cannot take advantage of the &lt;a href="http://www.iis.net/media/experiencesmoothstreaming" target="_Blank"&gt;Smooth Streaming&lt;/a&gt; that the Silverlight player can offer. All I really wanted was a way to enlarge the video to fit the full width of the browser window, so I figured why not just write a script to do it?&lt;/p&gt;  &lt;p&gt;&lt;a href="http://en.wikipedia.org/wiki/Bookmarklet" target="_Blank"&gt;Bookmarklets&lt;/a&gt; are essentially small snippets of javascript code that live in a browser’s favorites and do simple things like &lt;a href="http://www.mitchelaneous.com/2009/02/26/wikipedia-bookmarklet-for-your-desktop-research/" target="_Blank"&gt;opening a Wikipedia box for searching&lt;/a&gt;, &lt;a href="http://www.makeuseof.com/tag/google-reader-tools-tips/" target="_Blank"&gt;Subscribe/Share/Note&lt;/a&gt; the current webpage in Google Reader, using &lt;a href="http://googlesystem.blogspot.com/2009/10/google-sidewiki-bookmarklet.html" target="_Blank"&gt;Google SideWiki&lt;/a&gt;, or &lt;a href="http://www.amazon.com/wishlist/get-button" target="_Blank"&gt;adding any item to an Amazon Wishlist&lt;/a&gt;. Due to cross-site scripting restrictions implemented in most browsers they are relatively safe, so they shouldn’t be able to drain your bank account or spam all your friends on Facebook. Plus unlike &lt;a href="http://en.wikipedia.org/wiki/Greasemonkey" target="_Blank"&gt;Greasemonkey&lt;/a&gt; scripts they will only run when you click on the link in your favorites, so they won’t slow down or change your normal browsing habits. This seems like a perfect fit for resizing the Silverlight video player on Channel 9. &lt;/p&gt;  &lt;p&gt;So after dissecting the way that the Google bookmarklets worked I started coding my own. If you want to try it out you can simply drag this link to your favorites (or right click and select "Add to Favorites"): &lt;a href="javascript:b=document.body;if(b&amp;amp;&amp;amp;!document.xmlVersion){void(z=document.createElement('script'));void(z.src='http://www.theg2.net/bookmarklets/C9SLFullScreen.js');void(b.appendChild(z));}else{alert('Bookmarklet-Failed');}"&gt;C9FullScreen&lt;/a&gt; and then click on the new link that it created after browsing to your &lt;a href="http://channel9.msdn.com/shows/PingShow/Ping-37-SQL-Server-WIndows-7-Bing-Google-Bill-Gates-Birthday/" target="_Blank"&gt;favorite Channel 9 video&lt;/a&gt;. To see how it works, here is the code that gets embedded into the C9FullScreen link:&lt;/p&gt;  &lt;textarea class="brush: js;" rows="1" cols="75"&gt;javascript:b=document.body;if(b&amp;amp;&amp;amp;!document.xmlVersion){void(z=document.createElement('script'));void(z.src='http://www.theg2.net/bookmarklets/C9SLFullScreen.js');void(b.appendChild(z));}else{alert('Bookmarklet-Failed');}&lt;/textarea&gt;   &lt;p&gt;And here is the script that gets injected into the page to resize the video:&lt;/p&gt;

&lt;textarea class="brush: js;" rows="80" cols="75"&gt;
//C9FullScreen: Increases the size of the Silverlight player to the full width of the window
//Works with Internet Explorer, Safari, Firefox, and Chrome
//Author: Greg Bray
//Information: http://codeblog.theg2.net/2009/11/channel-9-full-screen-video-player-my.html
//Blog: http://blog.theg2.net
//License: Released to Public Domain
//Version 1.1 released 5/22/2010 to use new zap file and fix issue with http://channel9.msdn.com/learn/courses/SharePoint2010Developer/SharePoint2010DeveloperRoadmap/SharePoint2010IntegrationwithPowerShell/

//alert('Start JS Code');

//Reverse a string. Used to get PID from URL
//Code From: http://www.bytemycode.com/snippets/snippet/400/
String.prototype.reverse = function(){
    splitext = this.split("");
    revertext = splitext.reverse();
    reversed = revertext.join("");
    return reversed;
}

//Method to enlarge the Channel 9 Silverlight Player.
function C9SLFullScreen(){
    var b=document.body;
    var d=document.getElementById('ctl00_MainPlaceHolder_Starter_MediaPlayer');
    if(d){
        //Good test video is http://channel9.msdn.com/posts/Charles/Introducing-Click-to-Run-in-Office-2010/
        //alert("Player DIV found. Now check if Silverlight Player is already loaded.");
        o = d.getElementsByTagName('object');
        if(o.length==1){ //Video is already playing
            //alert('Player already loaded. Clear player and grab URL/PID');
   if(navigator.userAgent.toLowerCase().indexOf('chrome/') &gt; -1){
    alert('Player has already loaded. Resizing the video in Chrome will cause the player to load a partial version of the clip from the cache. Please refresh the page and try going C9FullScreen before starting the video.');
   } else {
    myregexURL = /m=(.+),autostart=/ //Regex to get video URL from object
    myregex = /\/ch9((?:\/\d)+)\// //Regex to get pid from video url
    mURL=myregexURL.exec(d.getElementsByTagName('object')[0].getElementsByTagName('param')[1].value)[1]; 
    mpID= myregex.exec(mURL); //Match regex
    pID = mpID[1].replace(/\//g,"");
    pID = pID.reverse();
    //alert("pID:"+pID+"\r\n"+mURL);
    d.removeChild(o[0]);//Remove active Silverlight object. Use o[0] to reference the player object
   }
        } else { //Video player not loaded. Grab movie url and pid.
            myregex = /\/ch9((?:\/\d)+)\//
            mURL=d.getElementsByTagName('a')[0].href; 
            mpID= myregex.exec(mURL); //Match regex
            if(mpID){
                pID = mpID[1].replace(/\//g,"");
                pID = pID.reverse();
            } else { //Learn/Courses videos do not include the id in the url, so grab it from the rdf tag. UPDATE 7/23/2010: Now standard C9 shows don't include it in the URL either!
                myregex2 = /\/(\d+)\/Trackback.aspx/
                dSummary = document.getElementById("contents");
                if(dSummary){
                    strHtml = dSummary.innerHTML;
                    pID = myregex2.exec(strHtml)[1];
                } else {
                    alert("Error: Cannot find trackback element containing video ID.");
                    return;
                }
            }
            //alert("pID:"+pID+"\r\n"+mURL);
        }

        //Hide bar at top
        document.getElementById("cb_main").style.display = "none";
        document.body.style.padding = "0 0 0 0";
  //Get window size (Leave a little extra as some browsers will act strange with the scroll bar.
        var h = window.innerHeight || document.documentElement.clientHeight || document.getElementsByTagName('body')[0].clientHeight;
        var w = window.innerWidth || document.documentElement.clientWidth || document.getElementsByTagName('body')[0].clientWidth;
        z=document.createElement('div');
        //Set Style (see http://www.comptechdoc.org/independent/web/cgi/javamanual/javastyle.html)
        //z.style.position = "absolute";
        //z.style.left = "20px";
        //z.style.top = "200px";
        intW = (w-35);
        intH = (h-20);
        z.style.width = intW+"px";
        z.style.height = intH+"px";
        z.style.marginLeft = "5px";
        z.style.marginTop = "5px";
        z.style.marginBottom = "10px";
        z.style.backgroundColor = "LightGrey";
        z.style.border = "medium solid black";
        //z.innerHTML = s;//'&lt;center&gt;'+s+'&lt;/center&gt;'; 
        bStart ="true"; //true=Starts onload, false=waits for click. Download will start immediatly, so true is recommended. NOTE: the AutoHide feature does not work (must be set to true otherwise it is always hidden).
        z.innerHTML = '&lt;object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="'+intW+'" height="'+intH+'"&gt;&lt;param name="source" value="http://channel9.msdn.com/App_Themes/default/VideoPlayer10_01_18.xap" /&gt;&lt;param name="initParams" value="m='+mURL+',autostart='+bStart+',autohide=true,showembed=true,postid='+pID+'" /&gt;&lt;param name="background" value="#00FFFFFF" /&gt;&lt;a href="http://go.microsoft.com/fwlink/?LinkID=124807" style="text-decoration: none;"&gt;&lt;img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/&gt;&lt;/a&gt;&lt;/object&gt;'       
        b.insertBefore(z, b.firstChild);
    }else{
        alert('ctl00_MainPlaceHolder_Starter_MediaPlayer not found. Make sure Channel 9 video page is loaded. Note: this does not work on the main homepage');
    }
}

C9SLFullScreen();
//alert('End JS Code');
&lt;/textarea&gt;
&lt;p&gt;And here is the result: A full screen video... Enjoy!&lt;/p&gt;
&lt;center&gt;&lt;a href="http://picasaweb.google.com/lh/photo/R1qcv4iIJf64PuISEBYNRw?authkey=Gv1sRgCKC0mp6P4ZPaGg&amp;feat=embedwebsite"&gt;&lt;img src="http://lh4.ggpht.com/_G06mB5h-kvQ/Svnf8EKSuLI/AAAAAAAABJ0/yWMQ5txFo_c/s800/PingC9FullScreen.jpg" /&gt;&lt;/a&gt;&lt;/center&gt;&lt;img src="http://feeds.feedburner.com/~r/TheG2NetCode/~4/liwBBQVOsww" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/TheG2NetCode/~3/liwBBQVOsww/channel-9-full-screen-video-player-my.html</link><author>noreply@blogger.com (Greg Bray)</author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://lh4.ggpht.com/_G06mB5h-kvQ/Svnf8EKSuLI/AAAAAAAABJ0/yWMQ5txFo_c/s72-c/PingC9FullScreen.jpg" height="72" width="72" /><thr:total>2</thr:total><feedburner:origLink>http://codeblog.theg2.net/2009/11/channel-9-full-screen-video-player-my.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6011603498138679949.post-2638797829242021985</guid><pubDate>Mon, 09 Nov 2009 04:51:00 +0000</pubDate><atom:updated>2009-11-08T21:51:44.321-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Tips n Tricks</category><category domain="http://www.blogger.com/atom/ns#">Video</category><category domain="http://www.blogger.com/atom/ns#">Tools</category><category domain="http://www.blogger.com/atom/ns#">.NET</category><category domain="http://www.blogger.com/atom/ns#">Testing</category><category domain="http://www.blogger.com/atom/ns#">Analysis</category><title>Short .Net Reflector Training Video from Pluralsight</title><description>&lt;p&gt;Today’s &lt;a href="http://www.simple-talk.com/" target="_blank"&gt;Simple-Talk newsletter&lt;/a&gt; had a video from &lt;a title="http://www.pluralsight.com" href="http://www.pluralsight.com" target="_blank"&gt;http://www.pluralsight.com&lt;/a&gt; that talked about the basic features of &lt;a href="http://www.red-gate.com/products/reflector/" target="_blank"&gt;Red Gate’s .NET Reflector.&lt;/a&gt; If you are not familiar with the .NET Reflector, I highly recommend you give it a try, as it is by far one of the best .NET tools available. &lt;a href="http://www.pluralsight.com/main/partnerPrograms/redgate.aspx?utm_source=redgate&amp;amp;utm_medium=newsletter&amp;amp;utm_campaign=reflector1" target="_blank"&gt;This short 14 minute video&lt;/a&gt; walks you through most of the features of the program and shows you why it can be so useful. I’ve used .NET Reflector for system testing or when a library’s documentation is incomplete or out of date. The video doesn’t cover the Analyze feature for finding all class references and dependencies, and it doesn’t talk about all the &lt;a href="http://www.codeplex.com/reflectoraddins" target="_blank"&gt;cool plug-ins&lt;/a&gt; you can add, but it does provide a great introduction to a very powerful tool!&amp;#160; &lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TheG2NetCode/~4/WYhqR5fztQY" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/TheG2NetCode/~3/WYhqR5fztQY/short-net-reflector-training-video-from.html</link><author>noreply@blogger.com (Greg Bray)</author><thr:total>0</thr:total><feedburner:origLink>http://codeblog.theg2.net/2009/11/short-net-reflector-training-video-from.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6011603498138679949.post-724712821167903293</guid><pubDate>Sun, 01 Nov 2009 23:15:00 +0000</pubDate><atom:updated>2009-11-01T16:20:44.514-07:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">.NET</category><category domain="http://www.blogger.com/atom/ns#">Fun</category><category domain="http://www.blogger.com/atom/ns#">Analysis</category><category domain="http://www.blogger.com/atom/ns#">IronPython</category><category domain="http://www.blogger.com/atom/ns#">Poker</category><title>Texas Holdem Hand Equity Calculation in IronPython</title><description>&lt;p&gt;This year I have been working in my free time to create &lt;a href="http://blog.theg2.net/2009/10/ironpython-texas-holdem-poker.html" target="_blank"&gt;easy to use Texas Holdem poker spreadsheets&lt;/a&gt; based on IronPython using &lt;a href="http://www.resolversystems.com/" target="_blank"&gt;Resolver One&lt;/a&gt;. These spreadsheets can be used to calculate Win/Tie/Loss odds, but some people like to use hand equity instead since it represents a player’s overall stake in the pot. Equity of 1.0 or 100% means that they will win the entire pot, where as equity of 0.5 (50%) or 0.25 (25%) means that they will split the pot with other players. You can again use Monte Carlo analysis to run a number of trials before all of the board cards are dealt to estimate a player’s current equity in the hand. This means that if during 4 trials I would win 2 of them and split the pot with one other player on the other 2, then my equity would be (1.0+1.0+0.5+0.5)/4 =&amp;#160; 3/4 or 75%.&lt;/p&gt;  &lt;p&gt;Calculating Win/Tie/Loss statistics on an independent player vs player basis is very simple, as the player’s pocket cards are evaluated against each opponent one at a time to show which opponent hands are stronger or weaker than your own. This does not take into account how the pocket cards of other opponents might change the odds, since in reality you usually play verse a table of opponents not just one opponent at a time. Changing the spreadsheet to work against the whole table would require changing the Monte Carlo simulation from a “row by row” analysis to a “table by table” analysis, where by you setup a table of opponents using a random hand for each player given the information that you have about their hand (AK, KK or QQ, Group1, etc..) and then generate a random 5 card hand based on the currently dealt cards. &lt;/p&gt;  &lt;p&gt;There are a lot of issues that you have to watch out for in this type of &lt;a href="http://www.codingthewheel.com/archives/multiway-ranged-isometric-equity-calculation-in-poker-1" target="_blank"&gt;Multiway Isometric Ranged Equity Calculation&lt;/a&gt;, but the basics are simple so long as you have a method of comparing multiple player’s hands for a given board. The &lt;a href="http://www.codingthewheel.com/archives/poker-hand-evaluator-roundup#pokersource_keithrule" target="_blank"&gt;C# poker library&lt;/a&gt; that I use is mainly focused on heads-up hands, but it only took me about an hour to whip up a method that would take a board setup and a list of player pocket hands and return the scored value and equity for each hand as well as the highest ranked hand and a list of the winners. Here’s the code:&lt;/p&gt; 
&lt;textarea class="brush: py;" rows="59" cols="75"&gt;
#This function can be used to calculate equity for multiple hands and a given board
def HandEquity(ulBoard, lstulHands, bPrintResults=False):
    &amp;quot;&amp;quot;&amp;quot;Used to calculate hand equity for a given 5 card poker hand and a list of players hands. If a hand wins then it's equity is 1, a loss is 0, and a tie is 1/n where n is the number of hands that tie.
        ulBoard: A 5 card hand for the board represented as a 52 bit mask in an unsigned long. Use HoldemHand.Hand.ParseHand method to parse &amp;quot;Ac Kd Th 3c 2d&amp;quot; type strings into bitmasks.
        lstulHands: a list of 2 card pocket hand masks as unsigned longs. Invalid hands that duplicate board cards are accepted but will get None for their score and equity. Use Use HoldemHand.Hand.ParseHand(&amp;quot;Ac Kc&amp;quot;) or HoldemHand.PocketHands.Query(&amp;quot;AK&amp;quot;).ToArray() to get hand masks.
        bPrintResults: True will print the results to the console. Use False for fastest results. NOTE: change 'pass #print' or '#print' lines to 'print' to enable more detailed debug messages 
    Returns a tuple of (lstintScores, lstfEquity, intHighScore, lstHighScorers):
        lstintScores = integer representing the scored value for each hand. If hand is invalid given the board cards, value will be None.
        lstfEquity = float representing the hand's equity. If hand is invalid given the board cards, value will be None. Sum of all valid hands will equal 1.
        intHighScore = integer representing the highest scored value (ie what the winner(s) had). Use HoldemHand.Hand.DescriptionFromHandValueInternal(intHighScore) to get a string description
        lstHighScorers = list of the index to each of the winners. use len(lstHighScorers) to find out how many winners there were.
    Example:
        testBoard = ((288&amp;lt;&amp;lt; (13 * 3)) + (7&amp;lt;&amp;lt; (13 * 2))) #0b100100000000000000011100000000000000000000000000 is Ts 7s 4h 3h 2h
        testHands = [3, 3 &amp;lt;&amp;lt; 13, 3 &amp;lt;&amp;lt; (13*2), int('1100',2)] #3 is 0b11 for 3c 2c, &amp;quot;3 &amp;lt;&amp;lt; 13&amp;quot; is 3d 2d, &amp;quot;3 &amp;lt;&amp;lt; (13*2)&amp;quot; is 3h 2h, and int('1100',2) is 4c 5c
        (lstintScores, lstfEquity, intHighScore, lstHighScorers) = HandEquity(testBoard, testHands)&amp;quot;&amp;quot;&amp;quot;
    intTotalHands = len(lstulHands)     
    if intTotalHands &amp;lt; 1:
        raise Exception(&amp;quot;Error: lstulHands must have at least one hand.&amp;quot;)
    if HoldemHand.Hand.BitCount(ulBoard) != 5:
        raise Exception(&amp;quot;Error: ulBoard must be a 5 card hand.&amp;quot;)
    if(bPrintResults):
        print &amp;quot;Start HandEquity with %d hands and board cards: %s&amp;quot; % (intTotalHands, HoldemHand.Hand.MaskToString(ulBoard))
    lstintScores = [None]*intTotalHands #List that holds scores for all the handss
    lstfEquity = [None]*intTotalHands #List that holds equity values for all the hands
    intHighScore = -1 #The highest score currently found
    lstHighScorers = [] #list of the index for hands that currently have the highscore
    intScore = None #temp variable to hold the current score
    
    #NOTE: Hand equity will not be available until after this loop finishes!
    for intIndex,aHand in enumerate(lstulHands):
        if HoldemHand.Hand.BitCount(aHand) != 2:
            raise Exception(&amp;quot;Error: Pocket hands must contain 2 cards. lstulHands index %03d HandMask=0x%0.13X contains %d cards.&amp;quot; % (intIndex, aHand, HoldemHand.Hand.BitCount(aHand)))
        if(aHand &amp;amp; ulBoard == 0): #Make sure there are no duplicate cards on the board and hand first
            lstintScores[intIndex] = intScore = HoldemHand.Hand.Evaluate(aHand | ulBoard) #evaluate the hand and board cards to get the score
            if intScore &amp;gt; intHighScore:
                intHighScore = intScore #Set new high score
                lstfEquity[intIndex] = float(1)
                for aScoreIndex in lstHighScorers: #Reset old high scores equity to zero
                    lstfEquity[aScoreIndex] = 0
                lstHighScorers = [intIndex] #Reset high score list
            elif intScore == intHighScore: #There is a tied pot, so calculate partial equity
                lstHighScorers.append(intIndex) #Add this index to the current high score
                for aScoreIndex in lstHighScorers: #Reset old high scores equity to partial equity
                    lstfEquity[aScoreIndex] = 1 / float(len(lstHighScorers))
            else:
                lstfEquity[intIndex] = 0 #losing hand gets no equity
            #print &amp;quot;%03d: Hand %s score is %s (%d)&amp;quot; % (intIndex, HoldemHand.Hand.MaskToString(aHand), HoldemHand.Hand.DescriptionFromHandValueInternal(intScore),intScore)
        else:
            pass #print &amp;quot;%03d: Hand %s has duplicate cards. Score and Equity are None.&amp;quot; % (intIndex, HoldemHand.Hand.MaskToString(aHand))
    
    #Hand equity is now finished.
    if(bPrintResults): #Print results for each hand
        print &amp;quot;Best hand is '%s' with %d winner(s) getting %0.2f equity in the hand.&amp;quot; % (HoldemHand.Hand.DescriptionFromHandValueInternal(intHighScore), len(lstHighScorers), 1 / float(len(lstHighScorers)))
        for intIndex,aHand in enumerate(lstulHands):
            if(lstintScores[intIndex] == None):
                print &amp;quot;%03d: Hand %s HandScore=None      Equity=None.&amp;quot; % (intIndex, HoldemHand.Hand.MaskToString(aHand))                  
            else:
                print &amp;quot;%03d: Hand %s HandScore=%09d Equity=%0.2f.&amp;quot; % (intIndex, HoldemHand.Hand.MaskToString(aHand), lstintScores[intIndex], lstfEquity[intIndex])  
    return (lstintScores, lstfEquity, intHighScore, lstHighScorers) #Return Results
&lt;/textarea&gt;  &lt;p&gt;Here is a sample print-out when bPrintResults is True:&lt;/p&gt;  &lt;p&gt;testBoard = ((288&amp;lt;&amp;lt; (13 * 3)) + (7&amp;lt;&amp;lt; (13 * 2))) #0b100100000000000000011100000000000000000000000000 is Ts 7s 4h 3h 2h   &lt;br /&gt;testHands = [3, 3 &amp;lt;&amp;lt; 13, 3 &amp;lt;&amp;lt; (13*2), int('1100',2)] #Hands: 3c 2c, 3d 2d, 3h 2h, and 4c 5c    &lt;br /&gt;(lstintScores, lstfEquity, intHighScore, lstHighScorers) = HandEquity(testBoard, testHands, True)&lt;/p&gt;  &lt;p&gt;Start HandEquity with 4 hands and board cards: Ts 7s 4h 3h 2h   &lt;br /&gt;Best hand is 'Two pair, Three's and Two's with a Ten for a kicker' with 2 winner(s) getting 0.50 equity in the hand.    &lt;br /&gt;000: Hand 3c 2c HandScore=033622016 Equity=0.50    &lt;br /&gt;001: Hand 3d 2d HandScore=033622016 Equity=0.50    &lt;br /&gt;002: Hand 3h 2h HandScore=None&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160;&amp;#160; Equity=None    &lt;br /&gt;003: Hand 5c 4c HandScore=016942384 Equity=0.00&lt;/p&gt;  &lt;p&gt;This is just a first step towards a full table Monte Carlo Simulator, but it gives you all of the details that are needed to find the winner(s) for a hand and calculate hand equity. The code used to generate a random board would be the same as in the other poker spreadsheets, but the player hand selection logic would need to use some sort of Round Robin algorithm to make sure that each player gets equal access to all of their possible pocket cards. Then you would use the HandEquity method to calculate the player’s equity for each hand and aggregate the results. My next goal is to change the spreadsheet code to use multiple threads, so I probably won’t tackle multi-way analysis anytime soon. &lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TheG2NetCode/~4/9q_mINOIjpg" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/TheG2NetCode/~3/9q_mINOIjpg/texas-holdem-hand-equity-calculation-in.html</link><author>noreply@blogger.com (Greg Bray)</author><thr:total>0</thr:total><feedburner:origLink>http://codeblog.theg2.net/2009/11/texas-holdem-hand-equity-calculation-in.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6011603498138679949.post-8568786967779591637</guid><pubDate>Fri, 02 Oct 2009 04:15:00 +0000</pubDate><atom:updated>2009-10-01T22:15:10.572-06:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Over Complicated</category><category domain="http://www.blogger.com/atom/ns#">Hardware</category><category domain="http://www.blogger.com/atom/ns#">Windows</category><title>Windows 7 Issues with JMicron JMB36X Controller in AHCI mode</title><description>&lt;p&gt;I had a lot of issues when &lt;a href="http://codeblog.theg2.net/2009/05/installing-windows-7-on-asus-p6t-with.html" target="_blank"&gt;setting up a RAID controller when installing Windows 7&lt;/a&gt; a few months ago, and today I had more problems trying to get an IDE drive to work in the same machine. The ASUS P6T motherboard has two hard drive controllers: one Intel ICH10R SATA controller for the 6 red SATA ports, and one JMicron controller for the two orange SATA ports and the single IDE connection. When I installed an old IDE hard drive to the JMicron controller, it was recognized in Windows but I was never able to format the drive. It kept saying that the window needed to be refreshed or that I needed to reboot the machine.&lt;/p&gt;  &lt;p&gt;After trying a few times with no progress, I decided to check and see if there was any &lt;a href="http://support.asus.com/download/download.aspx?model=P6T&amp;amp;SLanguage=en-US" target="_blank"&gt;updated drivers on the ASUS website&lt;/a&gt;. Turns out there was a recent BIOS update for the JMB322 firmware, so I download it to a jump drive, rebooted the computer and used the EZ Flash 2 utility built into the BIOS to run the update (I love this feature!) After changing the ICH10R settings back to RAID and setting the volume to be the primary hard drive and default boot device I was able to load back into Windows, but now there was another issue: There were two JMicron JMB36X devices listed in the device manager and only one of them was working.&lt;/p&gt;  &lt;p&gt;I tried removing both of them, thinking that one was a duplicate, but they both were detected again and one of them always listed “This device cannot start. (Code 10)” as the error message. The BIOS settings had the JMicron controller setup as AHCI mode, but no matter what I tried I could not get it to work. I even tried the latest drivers right from the &lt;a href="ftp://driver.jmicron.com.tw/jmb36x/XP_Vista_Win7/" target="_blank"&gt;JMicron website&lt;/a&gt;, but still nothing.&lt;/p&gt;  &lt;p&gt;Finally I tried changing the JMicron Controller settings from AHCI to IDE, and it started working again. This time I could detect the drive and the formatting worked just fine. Seems like the P6T motherboard still has a few bugs to work out specifically with the SATA and IDE controllers when using Windows 7 64bit edition. If I had to do it again I would probably ditch the hardware RAID array and instead buy an SSD drive for much better performance and a lot less headaches trying to set things up. &lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TheG2NetCode/~4/9gT9LrvQoWc" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/TheG2NetCode/~3/9gT9LrvQoWc/windows-7-issues-with-jmicron-jmb36x.html</link><author>noreply@blogger.com (Greg Bray)</author><thr:total>5</thr:total><feedburner:origLink>http://codeblog.theg2.net/2009/10/windows-7-issues-with-jmicron-jmb36x.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6011603498138679949.post-1551871316033146968</guid><pubDate>Tue, 15 Sep 2009 17:21:00 +0000</pubDate><atom:updated>2009-09-15T11:21:30.131-06:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Tips n Tricks</category><category domain="http://www.blogger.com/atom/ns#">Video</category><category domain="http://www.blogger.com/atom/ns#">.NET</category><category domain="http://www.blogger.com/atom/ns#">PowerShell</category><title>Powershell V2 training videos on Channel 9</title><description>&lt;p&gt;If you are a Windows system administrator and are not familiar with &lt;a href="http://en.wikipedia.org/wiki/Windows_PowerShell" target="_blank"&gt;Powershell&lt;/a&gt; yet, you &lt;a href="http://karlprosser.com/coder/2009/01/06/this-is-your-admin-life-you-have-to-script-powershell/" target="_blank"&gt;should be&lt;/a&gt;! Even programmers should find a .NET based command shell useful in many situations where they want to test an assembly or use it in a simple script. I just found out that Channel 9 has a &lt;a href="http://channel9.msdn.com/tags/PSV2/" target="_blank"&gt;PSV2 tag for all of their Powershell V2 videos&lt;/a&gt;, which cover different aspects of Powershell in a short video format. These videos don't appear to have a lot of views or comments, but they are definitely good learning material and could use a bit more exposure. Check out this one on &lt;a href="http://channel9.msdn.com/posts/philpenn/PowerShell-How-To-Variables-Types-and-Operators/" target="_blank"&gt;Variables, Types, and Operators&lt;/a&gt;:&lt;/p&gt;  &lt;p&gt;&amp;#160;&lt;/p&gt; &lt;center&gt;&lt;object classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95" width="640" height="480" codebase="http://www.microsoft.com/Windows/MediaPlayer/"&gt; &lt;param name="Filename" value="http://ecn.channel9.msdn.com/o9/ch9/9/2/8/6/8/4/PowerShellAficionadoPart1_ch9.wmv"&gt; &lt;param name="AutoStart" value="false"&gt; &lt;param name="ShowControls" value="true"&gt; &lt;param name="BufferingTime" value="2"&gt; &lt;param name="ShowStatusBar" value="true"&gt; &lt;param name="AutoSize" value="true"&gt; &lt;embed src="http://ecn.channel9.msdn.com/o9/ch9/9/2/8/6/8/4/PowerShellAficionadoPart1_ch9.wmv" type="application/x-mplayer2" autostart="0" enabled="1" showstatusbar="1" showdisplay="1" showcontrols="1" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" CODEBASE="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,0,0,0" width="640" height="480"&gt;&lt;/embed&gt; &lt;/object&gt;&lt;/center&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;Also if you are using Powershell, I highly recommend using the now free &lt;a href="http://shelltools.wik.is/PowerShell_Analyzer" target="_blank"&gt;Powershell Analyzer&lt;/a&gt; for creating and editing your scripts. I think that it still runs V1 of Powershell, but it is the best IDE that I have worked with so far. The &lt;a href="http://www.powershellplus.com/" target="_blank"&gt;Powershell Plus&lt;/a&gt; that replaced it just doesn't fit my needs quite as well.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TheG2NetCode/~4/UlIVYkasxww" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/TheG2NetCode/~3/UlIVYkasxww/powershell-v2-training-videos-on.html</link><author>noreply@blogger.com (Greg Bray)</author><thr:total>0</thr:total><feedburner:origLink>http://codeblog.theg2.net/2009/09/powershell-v2-training-videos-on.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6011603498138679949.post-4931779463218946185</guid><pubDate>Sun, 13 Sep 2009 19:08:00 +0000</pubDate><atom:updated>2009-09-13T13:13:49.570-06:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">WPF</category><category domain="http://www.blogger.com/atom/ns#">Video</category><category domain="http://www.blogger.com/atom/ns#">.NET</category><category domain="http://www.blogger.com/atom/ns#">XAML</category><category domain="http://www.blogger.com/atom/ns#">Silverlight</category><title>Learn WPF on a Sunday Morning!</title><description>I have been working on a few projects that involve WPF and Silverlight these last few weeks, and I have to say that the learning curve is a bit steeper than I expected. I have worked with Windows Forms and ASP.NET Web Forms for a while and know most of the tricks regarding layout and data binding, but WPF brings a lot of new technology and features into the mix. I had tried to jump straight into Silverlight design using Expressions Blend, but I got lost and overwhelmed in the process. This weekend I took a step back and started with learning WPF, which is the way that applications are designed in Silverlight. There are a lot of great resources, but all I needed to get moving were a few videos from the &lt;a href="http://www.windowsclient.net/"&gt;www.WindowsClient.net&lt;/a&gt; website. Their &lt;a href="http://windowsclient.net/learn/videos_wpf.aspx" target="_blank"&gt;series on WPF&lt;/a&gt; showed the basics for layout and design options in a simple WPF application. Here are some good videos to get you started:&lt;br /&gt;
&lt;br /&gt;
1. &lt;a href="http://windowsclient.net/learn/video.aspx?v=76359" target="_blank"&gt;Creating a simple WPF application&lt;/a&gt; (&lt;em&gt;10:19)&lt;/em&gt;&lt;br /&gt;
2. &lt;a href="http://windowsclient.net/learn/video.aspx?v=76347" target="_blank"&gt;Using XAML in WFP&lt;/a&gt; (&lt;em&gt;10:34&lt;/em&gt;)&lt;br /&gt;
3. &lt;a href="http://windowsclient.net/learn/video.aspx?v=76354" target="_blank"&gt;Overview of the different layout panels in WPF&lt;/a&gt; (&lt;em&gt;14:05&lt;/em&gt;)&lt;br /&gt;
4. &lt;a href="http://windowsclient.net/learn/video.aspx?v=83530" target="_blank"&gt;Simple WPF Data Grid Editing using ListView and GridView&lt;/a&gt; (&lt;em&gt;31:03&lt;/em&gt;)&lt;br /&gt;
5. &lt;a href="http://windowsclient.net/learn/video.aspx?v=124419" target="_blank"&gt;WPF Effects&lt;/a&gt; (&lt;em&gt;11:41&lt;/em&gt;)&lt;br /&gt;
6.&amp;nbsp;&lt;a href="http://windowsclient.net/learn/video.aspx?v=13252" target="_blank"&gt;Host a WPF Control in a Win32 Application&lt;/a&gt;&amp;nbsp;(&lt;em&gt;19:59&lt;/em&gt;)&lt;br /&gt;
&lt;br /&gt;
There is plenty more to learn about WPF (Animations, Styles, Video, etc), but this is a great way to get a start using WPF.&lt;br /&gt;
&lt;br /&gt;
Enjoy!&lt;br /&gt;&lt;img src="http://feeds.feedburner.com/~r/TheG2NetCode/~4/S1JRgfeTqgk" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/TheG2NetCode/~3/S1JRgfeTqgk/learn-wpf-on-sunday-morning.html</link><author>noreply@blogger.com (Greg Bray)</author><thr:total>0</thr:total><feedburner:origLink>http://codeblog.theg2.net/2009/09/learn-wpf-on-sunday-morning.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6011603498138679949.post-3004715754935366215</guid><pubDate>Wed, 02 Sep 2009 22:25:00 +0000</pubDate><atom:updated>2009-09-02T16:25:12.914-06:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Tips n Tricks</category><category domain="http://www.blogger.com/atom/ns#">XML</category><category domain="http://www.blogger.com/atom/ns#">MSSQL</category><title>Simple Talk article about TSQL Select For XML clause</title><description>&lt;p&gt;I had to do some work today creating a C# web service that would query a MS SQL database and return an XmlDocument with the results. After writing the query I tried loading the data into a DataTable and then using the WriteXML method to turn it into XML, but the layout wasn't exactly what I wanted and the use of a TableAdapter, StringWriter, XMLTextWriter, and XMLDocument seemed a bit excessive. I then remembered that MS SQL 2000, 2005, and 2008 support the &lt;a href="http://msdn.microsoft.com/en-us/library/ms190922.aspx" target="_blank"&gt;For XML clause&lt;/a&gt; on Select statements. I had read an article from Simple Talk a few months ago about the different options and by adding &amp;quot;FOR XML RAW ('LogEntry'), ROOT ('LogEntries')&amp;quot; to the end of the query I was able to get the SQL server to format the data for me and then use the &lt;a href="http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.executexmlreader.aspx" target="_blank"&gt;ExecuteXmlReader() method&lt;/a&gt; to create an XmlReader and load the data into an XmlDocument. The article is a great read for anyone that needs to work with XML data from an MS SQL server.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.simple-talk.com/sql/learn-sql-server/using-the-for-xml-clause-to-return-query-results-as-xml/"&gt;http://www.simple-talk.com/sql/learn-sql-server/using-the-for-xml-clause-to-return-query-results-as-xml/&lt;/a&gt;&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TheG2NetCode/~4/h66PZyEL9Ag" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/TheG2NetCode/~3/h66PZyEL9Ag/simple-talk-article-about-tsql-select.html</link><author>noreply@blogger.com (Greg Bray)</author><thr:total>0</thr:total><feedburner:origLink>http://codeblog.theg2.net/2009/09/simple-talk-article-about-tsql-select.html</feedburner:origLink></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-6011603498138679949.post-6106012140418148920</guid><pubDate>Tue, 28 Jul 2009 06:32:00 +0000</pubDate><atom:updated>2009-07-28T00:32:50.892-06:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">JavaScript</category><category domain="http://www.blogger.com/atom/ns#">.NET</category><category domain="http://www.blogger.com/atom/ns#">Silverlight</category><category domain="http://www.blogger.com/atom/ns#">IronPython</category><category domain="http://www.blogger.com/atom/ns#">DLR</category><category domain="http://www.blogger.com/atom/ns#">HTML</category><title>.NET Dynamic Languages Deep Dive: Bring your scuba gear!</title><description>&lt;p&gt;So I’ve been playing around with &lt;a href="http://codeblog.theg2.net/search/label/IronPython" target="_blank"&gt;IronPython&lt;/a&gt; for a little while now and have been having a lot of fun learning to combine dynamic and static programming techniques. I haven’t tried to do anything too fancy yet, but using an &lt;a href="http://www.resolversystems.com" target="_blank"&gt;IronPython powered spreadsheet&lt;/a&gt; to create a &lt;a href="http://www.theg2.net/rsltexasholdem/" target="_blank"&gt;Texas Holdem Monte Carlo Simulator&lt;/a&gt; did show that you can get reasonably good performance just hacking away at a problem, even when there are a few extra levels of indirection, binding, and code generation added into the mix.&lt;/p&gt;  &lt;p&gt;Lately I’ve been keeping my Google Reader RSS feed full of cartoons, news, and blog posts, and I just barely got around to digesting Bruno Terkaly’s break down of &lt;a href="http://blogs.msdn.com/brunoterkaly/archive/2009/07/23/c-4-0-dynamic-language-runtime.aspx" target="_blank"&gt;C# 4.0 and the Dynamic Language Runtime&lt;/a&gt;. He uses his blog to do presentations, so there usually are a lot of diagrams and a few key paragraphs of text, but if you have been keeping up with the developments then the pictures really help to pull things into perspective.&lt;/p&gt;  &lt;p&gt;This post in particular was expanding on Jim Hugunin’s talk about the use of &lt;a href="http://channel9.msdn.com/pdc2008/TL10/" target="_blank"&gt;Dynamic Languages in Microsoft .NET&lt;/a&gt; from PDC 2008 almost a year ago. I had seen Anders Hejlsberg’s presentation about &lt;a href="http://channel9.msdn.com/pdc2008/TL16/" target="_blank"&gt;The Future of C#&lt;/a&gt;, but I hadn’t had a chance to watch the video about the DLR until today. If anyone is wondering why there is so much hype about the DLR, the new Dynamic type in C#/VB.NET, or the emergence of IronPython and IronRuby, I suggest taking a look at both of these videos, as they show what in my mind is the future of programming. These technologies have been picking up steam over the last year or two, but when .NET 4.0 and VS 2010 ship in the near future, I expect to see a lot more applications taking advantage of this new powerful platform.&lt;/p&gt;  &lt;p&gt;The DLR in particular is quite fascinating, in that it bridges the gap between Dynamic and Static languages, as well as creating a method for connecting .NET code to COM, Javascript, Python, Ruby, and whatever else you want to tie into it with a custom binder. Also, with the DLR being supported in Silverlight, there are a lot of new opportunities for running managed dynamic code directly from a browser. &lt;a href="http://visitmix.com/labs/gestalt/" target="_blank"&gt;Gestalt&lt;/a&gt; for instance is a newly released project hosted at the Microsoft mix online community labs, which has the goal of letting web developers replace or supplement their JavaScript code with &lt;a href="http://channel9.msdn.com/shows/The+Knowledge+Chamber/Gestalt-Nishant-Kothary-and-Joshua-Allen/" target="_blank"&gt;Ruby, Python &amp;amp; XAML&lt;/a&gt; directly embedded into HTML pages using the standard &amp;lt;Script&amp;gt; tags that get parsed by Javascript and Silverlight. Very interesting stuff! &lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/TheG2NetCode/~4/Bz2c51e6TC4" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/TheG2NetCode/~3/Bz2c51e6TC4/net-dynamic-languages-deep-dive-bring.html</link><author>noreply@blogger.com (Greg Bray)</author><thr:total>0</thr:total><feedburner:origLink>http://codeblog.theg2.net/2009/07/net-dynamic-languages-deep-dive-bring.html</feedburner:origLink></item></channel></rss>
