CTICoder

A random spillage of programming (and other) thoughts

Archive for the ‘Uncategorized’ Category

New Year. New Wallpaper

Posted by Shaun McDonnell on January 4, 2010

GetToWork

Posted in Uncategorized | Leave a Comment »

My wife always said I can’t see 4 feet in front of me…

Posted by Michael Bray on October 20, 2009

At home, I am NOTORIOUS for looking right at things and not seeing them.  This type of conversation has been heard many times thru the years: “Honey, could you pass the sugar?”  “Hmm?  Where is it?”  “Right in front of you, doofus.”

Well this isn’t just at home – it’s here at work too.  And I just found something that (I presume) has been there all the time and I just never saw it.  And I love it.

In SQL Server Management Studio, when you execute a query and display the execution plan, that plan is often (for me anyway) way larger than the screen.  Sure you can right-click and there are various zoom options like ‘Zoom to fit’.  But if you do that, then you are left needing jewelers glasses to see it, and worse, with having to navigate around the plan, which can be a pain.  Or *was* a pain. 

If you look closely (you might have to squint) you’ll see a + below the scroll bar:

image

If you click that +, you get a Panning window that lets you move anywhere in the query plan you want, pain free.  And no need to zoom!

Posted in Uncategorized | Leave a Comment »

Enabling Automatic NTLM Authentication in Firefox

Posted by Michael Bray on October 2, 2009

When browsing using Internet Explorer to a site on an internal network that is configured with Integrated Windows Authentication, such as http://intranet, IE will automatically attempt to use your domain credentials to log in.  It’s always pained me that Firefox didn’t do the same thing.  I thought it had something to do with some M$ hocus pocus undocumented feature magic that prevented FF from being able to do this.  SO wrong.  It’s easy to enable Firefox to do the same:

To enable this feature in Firefox, go to the “about:config” url in Firefox, and then find the configuration parameters for “network.automatic-ntlm-auth.trusted-uris”, “network.negotiate-auth.delegation-uris”, and “network.negotiate-auth.trusted-uris”.  In those values, put the URIs that you want Firefox to automatically pass authentication to.  You can either use the http:// prefix or you can leave it off, and you can specify multiple parameters by separating them with a comma.

Posted in Uncategorized | Leave a Comment »

Reconfiguring BTARN manually.

Posted by Shaun McDonnell on August 26, 2009

I ended up changing my network domain name infrastructure a little bit and had to modify my host-headers in IIS so that everything would work well together (BizTalk, BTARN, Sharepoint, etc).  After I did this, I kept receiving the following error anytime I sent a message to BTARN:

RNIFReceiverWebApplication:  (404) Not Found

Obviously that means that the RNIFReceive.aspx was not passing the data off to the correct URL for the BTSHTTPReceive.dll.  I looked everywhere to reconfigure this without having to uninstall the WebApps aspect of BTARN and I couldn’t find it.  So, of course I looked in the registry and sure enough it was there:

image

This is located under HKEY_LOCAL_MACHINE/Software/Wow6432Node/Microsoft/BizTalk Accelerator for RosettaNet/2009 (this is for the 64-bit version of the accelerator. 

The keys you need to change are fairly obvious from here and you will need to perform an IIS reset afterwards to make sure the changes are propagated through the pipeline.

 

-Shaun

Posted in Uncategorized | Leave a Comment »

BizTalk 2009 and BTARN 3.5 on Windows Server 2008 Installation

Posted by Shaun McDonnell on August 20, 2009

I had some interesting problems occur when trying to install BizTalk 2009 and BTARN (BizTalk Accelerator for Rosetta Net) on Windows Server 2008.  At the end of the day the problems were trivial but kept halting my installation with errors I could not figure out.

The first error occurred when I ran the BTARN configuration and looked something like:

image

which reads:

“A BizTalk Isolated Host instance configured with the user account ‘BizTalkMumbles’ was either not running or does not exist on this computer.  Use the BizTalk Administration Console to create a new Isolated host or to reconfigure an existing host to run as ‘BizTalkMumbles’”

 

Well, I had done all of that already so this obviously wasn’t the problem.  It turned out I needed to use <COMPUTERNAME>\BizTalkMumbles or <DOMAINNAME>\BizTalkMumbles when I configured my BizTalk Host Application Instances.  Once I did this the error went away. 

Here is what the configuration looked like when I was getting the error:

image

And here is the configuration that made the error go away:

image

Note the change in the Logon.

I consider this to be Microsoft’s issue as the underlying logon user never changed but adding the machine or domain name helped.

Then, when I proceeded into my BTARN configuration, installing the Runtime and the WebApp failed miserably with errors in the log file that looked like this:

12:50:33 PM Info ConfigHelper]     Detected IIS version: 7
[12:50:33 PM Error ConfigHelper] d:\depot2300\mercury\private\common\configwizard\confighelper\iis.cpp(594): FAILED hr = 80040154

[12:50:33 PM Error ConfigHelper]     Failed to open application pool Error: d!
[12:50:33 PM Error ConfigHelper] Class not registered
[12:50:33 PM Error ConfigHelper] d:\depot2300\mercury\private\common\configwizard\confighelper\iis.cpp(151): FAILED hr = 80040154

[12:50:33 PM Info ConfigHelper]     Error -2147221164 occurred while attempting to retrieve site ID for site
[12:50:33 PM Error ConfigHelper] Class not registered
[12:50:33 PM Error RNConfig] c:\depot\europa2009\private\europa_source\btarnconfig\dll\rnconfig.cpp(2211): FAILED hr = 80040154

[12:50:33 PM Info RNConfig] Leaving function: CRNConfig::ConfigureFeature
[12:50:33 PM Warning Configuration Framework]Feature failed to configure: WebApps.
[12:50:33 PM Info Configuration Framework]Configuration Summaries:
[12:50:33 PM Error Configuration Framework]Feature: [Runtime] Failed to configure with error message [<Exception Message="Class not registered" Source="ConfigHelper" HelpID="HelpIdGetWebsiteID"/>]
[12:50:33 PM Error Configuration Framework]Feature: [WebApps] Failed to configure with error message [<Exception Message="Class not registered" Source="ConfigHelper" HelpID="HelpIdGetWebsiteID"/>]
[12:50:33 PM Info Configuration Framework]    Feature: Runtime    Configuration Enabled: yes    Sub UI: no    Configured: no
[12:50:33 PM Info Configuration Framework]    Feature: WebApps    Configuration Enabled: yes    Sub UI: no    Configured: no

I figured BTARN was having trouble talking to IIS and maybe needed IIS6 Compatability installed to be able to make the connection.  That turned out to be the case:

image

Make sure you have the ‘IIS 6 Management Compatability’ Role Service installed for IIS 7.

I searched and searched the net for answers on this and never found anything so I figured I would post my findings here.

-Shaun

Posted in Uncategorized | 5 Comments »

A mathematical diversion with LINQ

Posted by Michael Bray on July 18, 2009

Every now and then I’ll come across a math problem as part of my work…   It’s not what I do it’s just something that happens.  When it does happen, I either become obsessed with it until I solve it (or at least THINK I solve it, one way or another) or I eventually give up with the blunt realization that I just spent hours thinking about something that is likely to cause psychosis in old age.  Fortunately, the problem I ran across today seems to have fallen into the first category… 

Here’s the question, simplified…   Imagine you have a collection of at least 10 items, of which you are going to choose 5 at random.  One of those 5 is then taken away and replaced with a different NEW item (pulled from some other pile of items).  Next you choose another 5, again randomly.  The questions I asked myself in this scenario were:

  1. What are the chances that you WON’T see any of the same 5 that you originally picked? 
  2. What if the collection is 20 items instead of 10 items? 
  3. How many items have to be in the larger collection so that you have at least a 90% chance of NOT seeing any one of the originally chosen items if you are choosing 5 at a time?
The Math…

This actually is a fairly simple problem to solve…  but I ran thru an interesting programming journey on the way to the answers, and it was the programming aspect that prompted this post.  To reiterate the scenario, the collection starts with 10 items of which 5 are chosen and one is taken away; then another NEW item is added, again giving you 10 items from which to choose 5 of them, and out of the 10 from which you choose, 4 of them were ones you saw before. 

When working problems of this kind (because I’m not so good at probabilities) I prefer to back up to a simpler case.  So let’s consider what happens when you have 6 items in the collection, and you choose 3 at a time.  This means that on the second draw, there will be 2 that must be avoided.  If the items in the second draw are A, B, C, D, E, and F, and we presume that E and F must be avoided, then we have the following:

  • “Good” choices: ABC, ABD, ACD, BCD
  • “Bad” choices: ABE, ABF, ACE, ACF, ADE, ADF, AEF, BCE, BCF, BDE, BDF, BEF, CDE, CDF, CEF, DEF

So there are 20 possible choices, of which only 4 yield a good result.  Each of these numbers is a binomial coefficient.  The number 20 is the total number of 3-letter combinations, or 6C3. The number 4 is the number of 3-letter combinations of only the first 4 “good” letters, or 4C3. So it should be clear that in general, the number of total choices is NCr where N is the number of items in the collection, r is the number of items we are picking, and the number of “good” choices is MCr where M = Nr + 1.

So now the answer to the first question becomes easy…  If you only have 10 items to choose from at a time, this means that 5 were chosen from the original 10, and then one of those 5 goes away and will be replaced by a new (unseen) item, so there are 4 out of 10 that need to be avoided.  Thus in this case, N=10, r=5, and M=6.  And thus, the likelihood that you WON’T see any of the original 5 (but really 4) items is:

eqn7566   

Wow… the answer really is 42!!!  (Sort of.)

Ok, so what about the second question…   well the answer is still easy, because it is the same formula…  except now the numbers get bigger…   N=20, r=5, M=16:

eqn7566

Ok so what about the third problem?  Well it’s just a matter of plugging numbers in, but calculating binomial coefficients over and over for such large numbers really gets tiring…  and besides, like any good programmer, I wanted confirmation that I was doing my math right…   And that’s where we move to the fun part of this story.

Where’s the LINQ?

Ok so at this point I have two of the three answers, but I wanted to make sure I wasn’t screwing up the “easy” part.  I figured that this type of problem isn’t exactly custom-tailored for a LINQ query, but I figured I could have some fun and learn a bit more about Linq by using “Enumerable.Range” and some Linq extension methods.  So it’s just a matter of getting the code working…    But one thing that I really hate is using Visual Studio to create some dinky little project to do this sort of stuff – I’d much prefer a “snippet compiler” that will let me just type a bit of code and run it.  There are some programs around that do this, such as…  (wait for it…) SnippetCompiler.  It is a neat program because it basically let you write fully functional program without having to open VS.net.  But I found it’s IntelliSense somehow clunky and something about it always made me not like it too much, but it was still better than the alternative.  However, recently I have found a FANTASTIC application called LinqPad.  LinqPad can also compile snippets, but it is much more than just that…  It can dynamically evaluate LINQ expressions (or entire .NET programs), translate between LINQ syntax and lambda syntax, show you the generated IL, and can access databases on the fly so you are working with real data.  The author even touts it as a replacement for SSMS, and it certainly could, but I think that’s going a bit far since the results display isn’t quite tailored to that type of data, and I don’t think you can edit data in place (but I might be wrong).  It includes a lot of examples and apparently you can download more.  BUT… one of the really nice things is that it can compile and execute single statements – they don’t even have to be full programs as they do in SnippetCompiler.  For example, you can just type in “Enumerable.Range(10,10).ToList().ConvertAll(x => new { X=x, XSquared = x*x })” and here’s what you get out:

image

Amazing!  And trust me… that’s only the tip of the iceberg.  (Note that the shaded line is a “total sum” of the column – I don’t know why they do that, but I don’t see a way to turn it off.)  LinqPad also provides IntelliSense, although that is a feature you have to purchase.

Now comes the crazy part…

OK so I now started writing up some some LINQ and I quickly realized that there was no Factorial function in Math or any of the other standard libraries, and there was no way I was getting by without it.  So my first hunt was to find a Factorial function.  Not just any factorial function, but one written in LINQ, of course.  (Note that this was only because I was having fun; LinqPad is fully capable of compiling and executing non-LINQ C# code, so I could have just written a function to do it.)  My hunt took an odd turn, though, because it seems that writing a recursive function in Linq isn’t as easy as it is in good old fashioned code.  But with the magic and a bit of wizardry, it can be done.  I won’t try to explain it (because I don’t even come close to understanding it) but you can find the solution here.  They use something called a “YCombinator” to do it, but to keep things simple and clear, here is just the lambda that results from its use:

Func<int, int> factorial = Extensions.YCombinator<int, int>(fact => n => n < 2 ? 1 : n * fact(n - 1));

And a quick test of this shows that it works:

var N = Enumerable.Range(1,10).ToList().ConvertAll(x => new { x = x, factorial = factorial(x) });

image

Ok so now instead of building up a whole lot of factorial expressions, I’ll also define a lambda that handles the Combination function, like so:

Func<int, int, int> C = (n, r) => factorial(n) / factorial(r) / factorial(n - r);

var N = Enumerable.Range(3,10).ToList().ConvertAll(x => new { x = x, factorial = factorial(x), nC3 = C(x, 3) });
image

Coolio!!!  Alright now we are talking, because now I can verify my answers.  In order to do this, I’ll just calculate each of the values from N=10 to N=20 (why not!), along with the corresponding percentage calculation:

var N = Enumerable.Range(10,10).ToList();
int r = 5;
var y = N.ConvertAll(x => new {
    M = x-r+1,
    mCr = C(x-r+1, r),
    N = x,
    nCr = C(x, r),
    Frac = ((decimal)C(x-r+1, r) / C(x, r)).ToString("P2")
    });
image

Oops!!  Divide by zero???  How in the heck could that happen??  So I commented out the only place there could be a divide by zero, the Frac calculation:

var N = Enumerable.Range(10,11).ToList();
int r = 5;
var y = N.ConvertAll(x => new {
    M = x-r+1,
    mCr = C(x-r+1, r),
    N = x,
    nCr = C(x, r),
    //Frac = ((decimal)C(x-r+1, r) / C(x, r)).ToString("P2")
    });
image

Sure enough – there’s the zeros…   but WHY – there’s no way that a binomial coefficient can produce zero!  …And the first several answers are all correct.  Then I realized that the problem you always have when dealing with Factorials – the numbers get big really fast.  Maybe int wasn’t the best choice…  so I switched to long:

static Func<long, long> factorial = Extensions.YCombinator<long, long>(fact => n => n < 2 ? 1 : n * fact(n - 1));
static Func<long, long, long> C = (n, r) => factorial(n) / factorial(r) / factorial(n - r);
var N = Enumerable.Range(10,11).ToList();
int r = 5;
var y = N.ConvertAll(x => new {
    M = x-r+1,
    mCr = C(x-r+1, r),
    N = x,
    nCr = C(x, r),
    Frac = ((decimal)C(x-r+1, r) / C(x, r)).ToString("P2")
    });
image

Now that is more like it…  and so now I had the answers to TWO of the questions…   With 10 in the collection and choosing 5 at a time, you have only a 2.38% chance of not seeing one of the original items, and with 20 items you have a 28.17% chance of not seeing one of the original items.  So what would it take to get a 90% chance of not seeing one of the original items?  OK no big deal, I’ll just keep going…  Uhhhh…  wait a minute.  The long type ALSO has a maximum value…   I wondered how “long” would it be before I started getting mangled numbers?   Not very long it turns out.  In fact, the calculation goes bonkers on the very next value of N, N=21:

var N = Enumerable.Range(20,2).ToList();

image

So now what?  Double??  At first it appeared that it would work…   but RIGHT BEFORE I got to my answer of 90%, KABOOM

static Func<double, double> factorial = Extensions.YCombinator<double, double>(fact => n => n < 2 ? 1 : n * fact(n - 1));
static Func<double, double, double> C = (n, r) => factorial(n) / factorial(r) / factorial(n - r);
var N = Enumerable.Range(160,14).ToList();
int r = 5;
var y = N.ConvertAll(x => new {
    M = x-r+1,
    mCr = C(x-r+1, r),
    N = x,
    nCr = C(x, r),
    Frac = ((double)C(x-r+1, r) / C(x, r)).ToString("P2")
    });

image

At this point, I want you to take notice of the fact that I’m already up to 160+ items in the collection…  even with this many, when choosing 5, and replacing 1 of those 5 with a new item, and then picking 5 more from the full collection, you still don’t quite have a 90% chance of NOT seeing one of the original 5.  REALLY?!?!  Out of 160+ items I’m only picking 5, trying to avoid 4 of them, and I don’t have a 90% chance of doing that!?!?!  No wonder I always lost at Battleship.  I could pick 5 items from the collection 10 times over and still not have picked one-third of the available items…   odd… but ok, I trust the math.

Anyway…  Still without an answer to the question, and coming SO close, I couldn’t drop it now.  So what is out there that’s larger than a double and will operate on my measly 32 bit machine?  Ahhh yes…  BigInt!  So that started my quest for a BigInt class for C#, and I was surprised how hard it was to find one.  Apparently, there used to be a BigInt included in the System.Core library in the pre-release versions of .NET 3.5, but it was taken out before the official release.  Too bad – that would have been the easiest way to go.  I did eventually find a C# BigInt here.

So now I plugged in my BigInt, and after a few tweaks to handle the implementation of the BigInt class and some tweaks for efficiency and display, I arrived at my answer:

var N = Enumerable.Range(190,11).ToList();
int r = 5;
var y = N.ConvertAll(x => new {
    M = x-r+1,
    mCr = C(x-r+1, r),
    N = x,
    nCr = C(x, r)
    });
var z = y.ConvertAll(yy => new {
    M = yy.M,
    mCr = yy.mCr.ToString(),
    N = yy.N,
    nCr = yy.nCr.ToString(),
    Frac = (double.Parse(yy.mCr.ToString()) / double.Parse(yy.nCr.ToString())).ToString("P2")
    });

image

Thus…   I calculate that you would need a collection of 194 items from which to pull 5 items in order to have a >90% chance that you wouldn’t see one of the original 5 (really 4, since one is taken away).  That seems totally counter-intuitive to me, but this apparently a good example of diminishing returns! 

My next quest…   to find Factorial/Combination classes (probably utilizing BigInt) that can efficiently handle the fact that calculations of this kind, although they involve HUGE numbers if you work them out directly as I have here, actually represent relatively small numbers since factors often cancel out and I probably could have calculated the answer as fast on paper faster as it took me to write the code (assming I knew what the answer was!).  The above query didn’t take that long to run on my machine (almost 25 seconds) but it took me a while to figure out where the right value was.  The point is, with specially coded Factorial and Combination classes, I think this could be much faster and much more efficient.

Finally, along the course of this, I also found a nice LaTeX Equation Image Genarator on the web that I used for the math images… actually I found 3 or 4, but this was the only one that seemed to be working, so thanks to Roger!

 

~ Michael D. Bray

Posted in .NET, Math, Snippets, Uncategorized | Leave a Comment »

Windows 7 Slow. Constant Hard Drive Activity.

Posted by Shaun McDonnell on May 6, 2009

This one had me stumped for about an hour today. 

I have been running Microsoft Windows Vista Ultimate 64-bit for a couple years now on my Dell Precision with 0 problems.  So, naturally I decided it was time to upgrade to Windows 7 Ultimate.

Much to my dismay, after performing a fresh installation of Windows 7 Ultimate 64-bit Edition I found that it was acting very strange.  Sometimes it would sit for a few seconds when I did simple things like close a window or open the Start Menu.  It was very slow.  Furthermore, the hard drive light was always on and the hard drive was always making sounds.

I knew this had to be a driver issue because the machine had worked flawlessly under the heavy pressures of Vista.  So I started by flashing the BIOS.  That didn’t work.  I tried updating my display drivers and that did nothing.

I decided to see if I needed to update the Intel Chipset driver and it turns out that solved everything.  Microsoft has done a good job of making sure Windows 7 gets all of the correct drivers during installation as all of my other machines have worked flawlessly.

Unfortunately, Intel doesn’t have any Windows 7 x64 specific drivers:

http://downloadcenter.intel.com/filter_results.aspx?strTypes=all&ProductID=2261&OSFullName=Windows+Vista*+64&lang=eng&strOSs=150&submit=Go%21

However, using the Vista x64 drivers did the trick and everything works great now.

 

-Shaun

Posted in Uncategorized | 16 Comments »

Installing the Cisco VPN Client on Windows 7

Posted by Shaun McDonnell on March 3, 2009

In case you were wondering…

  • Download the Citrix DNE Update and Install it.
  • Reboot
  • Install Cisco VPN Client version 5 or newer.
  • Reboot

Good to go.

-Shaun

Posted in Uncategorized | Leave a Comment »

A Well Placed Advertisement

Posted by Shaun McDonnell on February 6, 2009

image

– Shaun

Posted in Uncategorized | Leave a Comment »

Fixing 404 Errors under MVC w/ IIS6

Posted by Michael Bray on December 30, 2008

I’ve run into this three times now, and you would think that one of the first two times I would have figured out exactly what the issue was.  Robert helped me fix this the first time, then I was able to duplicate it last night on another box, but I hit it again when I tried to make some configuration changes on the first box.  I have a rule that any issue that bite me three times gets extra attention, thus this post.  Writing about it forces my brain to push it into long-term memory, and hopefully if anyone else runs into the same problems, this will help. 

The symptoms are this: you’re running MVC (preview 5 as of this writing) on IIS6.  Opening the root of your application may work, but trying to navigate to a controller fails with a 404 error.  So you did some research, and you probably found some links…  Omar’s blog talks about several different issues, the first of which is most relevant to this issue.  He links to several forum posts, several of which contain a wonderful and easy solution (even if not the best solution), specifically, adding a wildcard application map in the Application Configuration.  Wildcard application maps may not be the best solution, but they are easy.  (Here’s a better way to do it.)

So you go an add your wildcard application map by clicking the Insert button to the right of the Wildcard application mappings (don’t confuse yourself and click ‘Add…’ under Application Extensions (see the image below).

image

So you think you fixed it….   you go back to your page and you STILL get the 404 errors.  You do everything from restarting IIS to rebooting the server to checking every permission and configuration setting you can find, but nothing works.

Well it turns out there is a bit of a misleading option that is critical to this working.  When you add the wildcard application map, you MUST uncheck the option “Verify that file exists.”  As I mentioned, there are several posts (here’s another) that talk about this, but it’s easy to overlook, especially if you are a ‘read every other word’ type of person like I am.  Worse, several other Google search results tell you to add the wildcard mapping but don’t say anything about the “Verify” option. 

Let me repeat this for those of you that are like me:

YOU MUST UNCHECK THE OPTION “VERIFY THAT FILE EXISTS”

image

This option does NOT mean “Make sure that ASPNET_ISAPI.DLL exists”…    it means “make sure the file that the user is requesting exists”.  Thus, if you do not uncheck this option, the server will see that the MVC page that the user is requesting doesn’t really exist as a file on disk, and will report a 404 error.

There.  I think that should be enough self-flogging for now.

Posted in Uncategorized | 1 Comment »