September 2009 Blog Posts
Writing a calculator in C# using SableCC
Writing a calculator is a simple task - just add nine buttons labeled 1-9 and add a plus and minus button and we're almost good to go. In this entry I'm going to write a calculator called SimpleCalc that does not have a GUI, instead it'll take in an arbitrary expression and calculate the results of it. The input I'll use as my immediate goal is the following: 25-37+2*(1.22+cos(5))*sin(5)*2+5%2*3*sqrt(5+2)
According to Google the result is -9.83033875. Some of the tricky subjects we'll have to handle is operator precedence (multiplication before addition etc), nested expressions (2*1.22+cos(5) != 2*(1.22+cos(5))) and associativity (5+7...
IIS7 w3wp process hung on shutdown
Written on Friday, September 25, 2009 by Mark S. Rasmussen in Sysadmin: IIS
A single server has started to sometime leave zombie w3wp.exe processes when trying to recycle. A new process is spawned properly and everything seems to work, except the old processes are still present and take up memory. Task manager reports there's only a single thread left, far from the active ones that have between 40 and 70 threads usually. Using ProcDump I've taken a full memory dump to analyze further in WinDbg. The machine is a Server 2008 R2 x64 8 core machine as stated by WinDbg: Windows 7 Version 7600 MP (8 procs) Free x64
After loading...
IIS request filtering woes
Written on Wednesday, September 23, 2009 by Mark S. Rasmussen in Sysadmin: IIS
I recently put a number of load balanced websites in production by using the newly released IIS7 Application Request Routing v2 Beta extension. Everything seemed to run perfectly both performance and functionality wise. There was a slight problem however. Some users were reporting mysterious errors when uploading files to the website, apparently seeming like a timeout. When I tried to reproduce, all smallish files when through, though larger files did fail. I checked out the responses in Fiddler and to my surprise the ones working returned 200 while the failing ones returned a 404 error after a while. To...
Combining paths with multiple parts
Whenever you concatenate multiple strings into a path, you really ought to be using the System.IO.Path class's Combine method. At times you may be concatenating a number of smaller parts of a path instead of just the two that the Path.Combine() method takes. Nested Path.Combine calls quickly become difficult to read and error prone: string partOne = @"C:\";
string partTwo = "Windows";
string partThree = @"System32\drivers";
string partFour = @"etc\hosts";
string combinedPath;
combinedPath = Path.Combine(Path.Combine(Path.Combine(partOne, partTwo), partThree), partFour);
Often we won't have all of our path parts in named variables, and even when we do, they'll rarely be named partOne, partTwo, partX etc. If we...
The cost of latent logging code
Logging is an integral part of most applications, whether it's for logging performance metrics or causality data. Avoiding performance hits due to logging can be tricky though as we don't want to spend CPU cycles on the logging infrastructure when logging is disabled, while still keeping the full logging ability when required. Imagine the following scenario in which we want to log an exception in our application: Logger.Log("An error occured at " + DateTime.Now + " on computer " + Environment.MachineName + " in process" + Process.GetCurrentProcess().ProcessName + ".");
Inside the Logger.Log method we may have a check for...
|