Thursday, December 3, 2009

Watin 2.0 and Gallio 3.1 in x64 environment: fixing System.Reflection.ReflectionTypeLoadException and System.Runtime.InteropServices.COMException "The interface is unknown" issues

We use Gallio/MbUnit and Watin at my work for unit testing of an ASP.NET website, as it provides excellent reports including the raw Watin events (click, type, select) and screenshots for failed cases. 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 TestDriven.NET loader from within Visual Studio, but couldn’t get anything to work. Here is the full error message for Google’s sake:

[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& 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

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). This link 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!

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="The interface is unknown. (Exception from HRESULT: 0x800706B5)" coming from mshtml.HTMLDocumentClass.IHTMLDocument2_get_url(). Another quick search lead to another StackOverflow answer suggesting to run Visual Studio as an Administrator. That seem to do the trick!

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

Enjoy!

Tuesday, November 10, 2009

Channel 9 Full Screen Video Player: My first Bookmarklet

I really enjoy watching videos from Channel 9, 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.

Currently there are only two workarounds to the Silverlight/Flash full screen issue, both of which YouTube 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 Smooth Streaming 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?

Bookmarklets are essentially small snippets of javascript code that live in a browser’s favorites and do simple things like opening a Wikipedia box for searching, Subscribe/Share/Note the current webpage in Google Reader, using Google SideWiki, or adding any item to an Amazon Wishlist. 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 Greasemonkey 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.

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"): C9FullScreen and then click on the new link that it created after browsing to your favorite Channel 9 video. To see how it works, here is the code that gets embedded into the C9FullScreen link:

And here is the script that gets injected into the page to resize the video:

And here is the result: A full screen video... Enjoy!

Sunday, November 8, 2009

Short .Net Reflector Training Video from Pluralsight

Today’s Simple-Talk newsletter had a video from http://www.pluralsight.com that talked about the basic features of Red Gate’s .NET Reflector. 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. This short 14 minute video 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 cool plug-ins you can add, but it does provide a great introduction to a very powerful tool! 

Sunday, November 1, 2009

Texas Holdem Hand Equity Calculation in IronPython

This year I have been working in my free time to create easy to use Texas Holdem poker spreadsheets based on IronPython using Resolver One. 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 =  3/4 or 75%.

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.

There are a lot of issues that you have to watch out for in this type of Multiway Isometric Ranged Equity Calculation, but the basics are simple so long as you have a method of comparing multiple player’s hands for a given board. The C# poker library 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:

Here is a sample print-out when bPrintResults is True:

testBoard = ((288<< (13 * 3)) + (7<< (13 * 2))) #0b100100000000000000011100000000000000000000000000 is Ts 7s 4h 3h 2h
testHands = [3, 3 << 13, 3 << (13*2), int('1100',2)] #Hands: 3c 2c, 3d 2d, 3h 2h, and 4c 5c
(lstintScores, lstfEquity, intHighScore, lstHighScorers) = HandEquity(testBoard, testHands, True)

Start HandEquity with 4 hands and board cards: Ts 7s 4h 3h 2h
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.
000: Hand 3c 2c HandScore=033622016 Equity=0.50
001: Hand 3d 2d HandScore=033622016 Equity=0.50
002: Hand 3h 2h HandScore=None        Equity=None
003: Hand 5c 4c HandScore=016942384 Equity=0.00

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.

Thursday, October 1, 2009

Windows 7 Issues with JMicron JMB36X Controller in AHCI mode

I had a lot of issues when setting up a RAID controller when installing Windows 7 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.

After trying a few times with no progress, I decided to check and see if there was any updated drivers on the ASUS website. 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.

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 JMicron website, but still nothing.

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.

Tuesday, September 15, 2009

Powershell V2 training videos on Channel 9

If you are a Windows system administrator and are not familiar with Powershell yet, you should be! 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 PSV2 tag for all of their Powershell V2 videos, 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 Variables, Types, and Operators:

 

Also if you are using Powershell, I highly recommend using the now free Powershell Analyzer 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 Powershell Plus that replaced it just doesn't fit my needs quite as well.

Sunday, September 13, 2009

Learn WPF on a Sunday Morning!

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 www.WindowsClient.net website. Their series on WPF showed the basics for layout and design options in a simple WPF application. Here are some good videos to get you started:

1. Creating a simple WPF application (10:19)
2. Using XAML in WFP (10:34)
3. Overview of the different layout panels in WPF (14:05)
4. Simple WPF Data Grid Editing using ListView and GridView (31:03)
5. WPF Effects (11:41)
6. Host a WPF Control in a Win32 Application (19:59)

There is plenty more to learn about WPF (Animations, Styles, Video, etc), but this is a great way to get a start using WPF.

Enjoy!

Wednesday, September 2, 2009

Simple Talk article about TSQL Select For XML clause

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 For XML clause on Select statements. I had read an article from Simple Talk a few months ago about the different options and by adding "FOR XML RAW ('LogEntry'), ROOT ('LogEntries')" to the end of the query I was able to get the SQL server to format the data for me and then use the ExecuteXmlReader() method 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.

http://www.simple-talk.com/sql/learn-sql-server/using-the-for-xml-clause-to-return-query-results-as-xml/

Tuesday, July 28, 2009

.NET Dynamic Languages Deep Dive: Bring your scuba gear!

So I’ve been playing around with IronPython 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 IronPython powered spreadsheet to create a Texas Holdem Monte Carlo Simulator 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.

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 C# 4.0 and the Dynamic Language Runtime. 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.

This post in particular was expanding on Jim Hugunin’s talk about the use of Dynamic Languages in Microsoft .NET from PDC 2008 almost a year ago. I had seen Anders Hejlsberg’s presentation about The Future of C#, 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.

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. Gestalt 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 Ruby, Python & XAML directly embedded into HTML pages using the standard <Script> tags that get parsed by Javascript and Silverlight. Very interesting stuff!

Thursday, July 9, 2009

IronPython SpeechSynthesizer Mad Lib!

I just submitted a Mad lib Spreadsheet to the Resolver One Exchange that shows how to use the System.Speech.Synthesis.SpeechSynthesizer class to make a talking Mad Lib. In case anyone else is looking to do Speech Synthesis from IronPython, I will post the code here as well. Enjoy!

Thursday, July 2, 2009

Box Selection in Visual Studio: You learn something new every day!

I was browsing on the Coding4Fun site and came across this cool video about Box Selection in Visual Studio 2010:

<a href="http://video.msn.com/?mkt=en-US&amp;playlist=videoByUuids:uuids:3e57917d-1b92-4188-b898-25a1d64a408e&amp;showPlaylist=true&amp;from=shared" target="_new" title="Box Selection and Multi-Line Editing Demo">Video: Box Selection and Multi-Line Editing Demo</a>

Looks like deleting a box selection has been around for a little while in both Visual Studio and Office (simply hold the alt key while you select the text), I just never knew about it. Heck, only recently learned about using the clipboard ring a few months ago. VS 2010 adds the ability to also do inserts and replaces when doing a box selection, which really would come in handy while coding.

Tuesday, June 30, 2009

Export Vonage Call Log using IronPython and WatiN

Here is another IronPython script that shows how to use the WatiN testing framework, which is great for testing web pages in Internet Explorer, and it is starting to support Google Chrome and Firefox too. We use WatiN at work for testing the full stack on an ASP.Net website, and it works very well even for AJAX sites. This example will login to Vonage and export all of a user's call data to a CSV format.

Enjoy!

Monday, June 8, 2009

IronPython Date Selector: Pick a date... any date...

Another quick IronPython snipet that shows how to use the Windows.Form.MonthCalendar control to create a simple date selector.

image002

Works well for selecting singe dates, and could be modified to support selecting a date range if desired. I prefer having a Start Date and End Date, and selecting each separately. Full code can be downloaded here.

Enjoy!

IronPython Excel COM Automation: Pivot this!

I have been playing around with IronPython recently while creating spreadsheets in Resolver One. So far I have been having a lot of fun, but I haven't really been doing anything that would be useful in a work setting. The main reason for this is because most of the spreadsheet work that I do revolves around pivot tables and Auto Filter, which are immensely helpful for visually analyzing data. I thought I might try and use Excel's COM Automation to add Pivot Charts and Auto Filter to any system with IronPython, and here is the code that I have come up with so far:
UPDATE 7/13/2009: After releasing the initial code, I found that there was a problem with the HideToolbars function causing the Excel toolbars to be disabled permanently. Also, the code would not work if the user's Region was set to something other than "en-US" due to this known bug. I updated the code to disable the HideToolbars function and use Reflection and the InvokeMember method to force the Culture to be "en-US". If you want to view the old "en-US" only code, you can download it here.

The code should be pretty straight forward. The Reload() method is helpful for reloading the whole module when testing from a console. The Run() method shows the steps to load a new spreadsheet. The ExcelManager static class is the core of the logic and provides an entry point for interacting with the spreadsheet.
There is not a lot of debuging code, so if something goes wrong it is just going to throw an exception, but this should be enough to help get things started. I did fix some funky problems with importing DateTime, where they kept getting converted into integers. Should work fine now, but anything other than Datetime, numerical types or strings will probably not get imported correctly.
If anyone else needs to do Excel Interop with IronPython, feel free to use the code, which can be downloaded here.
Enjoy!

Monday, June 1, 2009

Simple-Talk article about SQL FOR XML usage

I read a great article from Simple-Talk today about how to use the FOR XML option in Microsoft SQL server. I usually would passively post these to a shared RSS reader feed or star them for future reference, but I found the article through the Red Gate Newsletter and I don't really want to add the entire feed just to share one article. I do however suggest signing up for the newsletter if you are interested in MSSQL, .NET, or Exchange as they often have a lot of good articles about coding in or managing these systems.

Simple-Talk is a service from Red Gate, which creates tools for Exchange, SQL Server and .NET including the .NET Reflector, which is an invaluable tool for anyone using the .NET framework. I use it all the time to help with testing and debugging or when using .NET libraries that have poor user documentation. It even includes add-ins for changing code in .NET assemblies or adding an embedded IronPython console for playing around with objects and methods. Very handy indeed!

Wednesday, May 20, 2009

IronPython programming can be harder than it looks!

After playing around with IronPython for a few months, I definitely like how easy it is to manipulate objects. Everything is truly open, and if you want to attach one object to another or pass a function around as a variable then "it just works". I have mainly been using IronPython for fun, but right now I would be a bit scared to use such a fluid language for a structured large scale production application: The lack of static typing and compile time checks would make we wary of using IronPython for "real code" instead of just scripting. I stumbled on a video of Giles Thomas on Channel 9 (posted in March 2008 but mystically appeared in my RSS reader this afternoon) and it sounds like Resolver Systems had similar concerns but combined IronPython with Test Driven Development to build a solid foundation for Resolver One. That way they get plenty of up front testing and don't need to second guess the dynamic nature of programming in python. Seems to have worked well so far, as Resolver One is a rock solid product from my experience.
Usually when somebody says that "it just works", the phrase comes with an asterisk and a long line of small text at the bottom of the page. In my experience with IronPython this is still the case, as there are a few things that are much harder to do than they should be. Michael Foord, another Resolver Systems developer, co-wrote the book on IronPython, and today wrote an article about a case when IronPython code ends up being a bit tricky. If you ever need to get the docstrings from an arbitrary IronPython object, or just want to see a detailed explanation of some of the inner workings of python, the Techie Blog is a great read!

Friday, May 8, 2009

Installing Windows 7 on ASUS-P6T with IHC10R RAID Array

I recently purchased a new computer, and I decided to go with the following components:

Motherboard: ASUS P6T LGA 1366 Intel X58 ATX

CPU: INTEL Core i7 920 2.66G quad core with Hyper Threading (4 cores, 8 threads)

RAM: 3x2GB DDR3 1600

Hard Drive: 2x250GB Seagate Barracuda 7200.10 ST3250310AS setup as RAID 1 Mirror

Video Card: MSI N9400GT-MD512H 9400GT RTL with passive cooling design

Case: APEVIA X-ALIEN MX-ALIEN-BK Black Steel ATX Full Tower

The build went fine, but I got stuck trying to install Windows 7 64Bit RC, as I could not get it to load the drivers for either the JMicron JMB363 or Intel ICH10R SATA controllers. The SATA Port 0 and 1 are controlled by the JMicron JMB363 controller, which can be setup as a special Speed or Backup mode using Intel Drive Xpert technology. I couldn't find any information about what these actually were (I assume Raid 0 and Raid 1, but not sure), so I decided to try and setup the drives on the ICH10R controller as a standard RAID 1 array instead. After updating the bios using the built in ASUS EZ Flash 2 feature (very cool!), I setup the ICH10R controller in RAID mode in the BIOS, disabled the quick boot and the Floppy drive (was causing Windows 7 setup to be incredibly slow trying to loading drivers from a floppy drive that didn't exist), and pressed CTRL+i to setup the drives in mirror mode.

Windows 7 setup still couldn't detect any of the drives. The motherboard came with a driver disk, but I couldn't get any of the SATA drivers for Intel or JMicron on it to work. Even after breaking the raid and installing one drive on each controller, and changing from RAID to AHCI, it still couldn't find them. I tried downloading 3 different versions of the ICH10R driver, even the ones that said they were Windows 7 compatible. I final found a driver that worked for the JMicron controller on the motherboard driver disk tucked away in an install directory in an AMD64 directory. This wasn't what I wanted, but at least I was able to get Windows installed. It took a long time and I thought that it stalled on the "Completing Installation" section, but after an hour or so it changed to a message saying that the installation will continue after rebooting (which I force to reboot after 10 minutes of waiting). Looks like they still haven't fixed any of the useless notifications during windows 7 installation.

After Windows loaded up, I downloaded and installed the latest drivers and ran Windows update, which updated the drivers again. A few reboots, and everything looks great, although it still is running off of the JMicron controller and is not in RAID 1 like I wanted. I switched the drives over to the ICH10R controller, but then it wouldn't load into windows. I was about to cry, but then I noticed that there were two drives listed in the boot sequence, and one of them was still a blank drive. I switched the order of the drives so that the one with Windows was on the lowest SATA port, and then after rebooting it loaded into Windows again (crisis adverted!). Now the drives were on the correct controller, which was still setup in RAID mode in the bios. Unfortunately you can't create a RAID array in the boot loader from an existing disk without loosing all of the data, but by downloading and installing the Intel Matrix Storage Console I was able to convert an existing disk to a RAID 1 array. The process failed the first time, but I rebooted, tried again, and after 2 hours (SATA 3.0GB/sec my ass....) I had everything working just how I wanted.

A bit of a pain, but at least I got it to work. It might be that there is a special driver for the ICH10R SATA RAID mode that is hidden somewhere, but I couldn't find anything that worked. Best bet if you are installing Windows 7 64-bit on ASUS-P6T is to connect a drive to Port 0 or 1 and load the JMicron drivers from the install/AMD64 directory. You can then move over to the Intel controller after updating all the drivers in Windows and build whatever type of RAID array you want using the Intel Matrix Storage Console.

Update 10/1/2009: More issues with JMicron controller and IDE drive.

Friday, March 13, 2009

PowerShell Script for Processing TimeManagment CSV Data

If you are a code geek I highly suggest looking at the An App A Day site to see some cool open source projects that were designed and created in less 24 hours. I have been using the TimeManagment program to create my time cards for a few years now, although because of it's lack of analysis tools I haven't been able to do much else with the data. If you are interested in tracking and analyzing time spent on your computer, RescueTime is much more stable and has many, many more features, but TimeManagment is a great way to create an audit log and do customized tracking.

Even something as simple as creating a time card can be a bit of a pain, since all of the data is stored in a single CSV file. You end up having to open the file in Excel and scan through thousands of lines like these to find what you were doing at any given time:

I finally got fed up with it and created a PowerShell script to do the job for me (including removing 1 hour each day for lunch). Now I can click a button and out pops a nice little report listing my hours for any given date range:

You can see that it is not perfect (It still things that I plan on coming in and working a few hours this weekend. Fat Chance!), but if you are interested here is a link to the PowerShell script file. Should come in handy for anyone else using the TimeManagment program or just interested in processing CSV data files using PowerShell.

Enjoy!

Tuesday, February 17, 2009

Programs for reading and writing code in different languages

Just a quick post to keep things going. I end up having to read more code than I write, mainly because even when I write code I am usually pulling bits and pieces from old projects. When writing code I always use a full IDE, since I have become dependent on features such as code completion, breakpoints/debugging, and visual designers. For reading code these features are not as important, but code syntax highlighting and region/section collapsing are still very useful. For writing code I use all of the standard IDEs: Visual Studio 2005/2008 for .NET, SQL Management Studio for MS SQL, PowerShell Analyzer or PowerShell Plus for PowerShell, and IronPython Studio for IronPython. For reading code, rather than loading a bulky IDE I have started to use a free program called Notepad++, which supports multiple tabs, region collapsing, and syntax highlighting for a myriad of languages. It works a lot better than reading code in notepad and loads much faster than Visual Studio. Here is a screenshot:

Thursday, February 5, 2009

JavaScript and CSS based popup for changing Google Analytics User Segment cookie

I use Google Analytics on all of the sites that I work on for tracking page views and traffic sources. It has great reporting features, but I always have problems with traffic from my office computer or home laptop skewing the results. Most of the computers that I use have dynamic IP addresses, so a static IP filter does not work. Instead you have to setup a cookie based filter. The problem is then how do you setup the cookie and monitor if your traffic is currently being tracked or not? I created a small JavaScript and CSS based popup for setting and clearing the cookie that I can then add somewhere to the site. The first section is the JavaScript code. Place this block somewhere in your HTML or template:

The second section is the DIV/CSS popup that contains a few links that you can click on. Again just place this anywhere in your HTML or template (it uses fixed positioning and will always appear in the middle of the screen):

The final section is a link that can be placed somewhere on your page. Clicking the link will display the popup:

I use a period for the link text and hide it somewhere on the page. This way I can click the hidden link from any computer to disable tracking for that browser. This is an example of what the end result looks like:

For some reason Google Chrome does not let your clear the __utmv cookie using JavaScript. It works in IE and it works in Chrome on a localhost page, but it doesn't work on the live blog. A bit strange, but you can always clear the cookie manually in the browser. Oh, and don't forget to setup the filter in Google Analytics to exclude the traffic (see link above)

The next time I work on this I will probably change it so that the tracking status is displayed on the actual link itself using red "__ TRACKING DISABLED __" text if your page views were not being tracked or a normal period to anyone who's traffic was being tracked.

Wednesday, February 4, 2009

First Post! (aka CodeBlog Mission Statement)

I end up coding in a lot of different languages and keep on forgetting how to do simple things (is it "for x in y", "foreach", etc...). I need some place to store code that I can access from anywhere so that I don't have to keep going to Google each time I forget something. I don't want to post code snippets to my personal blog, so this is the new holding spot for all my coding tricks and treats. And thanks to SyntaxHighlighter 2.0 created by Alex Gorbatchev all those code snippets will be in full color and easy to view. For example, take this prize python gem: This returns: Don't expect any long winded posts about Systems vs. Apps Hungarian Notation (ok... well maybe a few :-) as this is designed to be home to just sweet, sweet code. Enjoy!

Blog.TheG2.Net - Your guide to life in the Internet age.