Uncategorized

Craps Simulator, II

I identified a bug in the simulator and fixed it. Now, the traditional craps table performs better than the crapless table in all scenarios I’ve tested. I’m more comfortable with these results, which give about a 76-78% chance of breaking even or better given a certain ratio of bet size Read more…

By kryptx, ago
Uncategorized

Craps Simulation

I’ve been working on a craps simulator in c# lately, to figure out how to maximize my chance of leaving the casino with more money than I came in with. At this point it seems that you have the best chance if you bet about 10% of your total bankroll Read more…

By kryptx, ago
Uncategorized

Extension methods

Extension methods are methods that are added to existing compiled types. These are useful for adding new members to classes in the BCL or in assemblies for which source code is not available. However, extension methods can also be useful because they can be called on null references. For instance, an immutable Stack(of T) implementation might contain a head of type T and a tail of type Stack(of T). How do you create an empty stack if T is allowed to be a non-nullable value type? (more…)

By kryptx, ago
Uncategorized

Events, Anonymous methods, Lambda expressions

The event keyword in C# causes the compiler to provide registration and unregistration methods and member variables for delegate types. These methods could be written manually; the event keyword just saves time. An event is declared with the syntax public event DelegateType EventName;, and invoked with EventName(arguments_specified_by_delegate). Microsoft’s recommended event Read more…

By kryptx, ago
.NET

Object Lifetime and the Garbage Collector

The golden rule of .NET memory management is simple:

Allocate a class instance onto the managed heap using the new keyword and forget about it.
The garbage collector destroys an object when it is no longer needed, which is (basically) when the object is unreachable by the code base. (more…)

By kryptx, ago
Uncategorized

Cross-platform, Real-time AJAX Progress Indicator

Recently I've been developing an application which, on a user's request, has to perform a series of time-intensive tasks. Based on my understanding of the XmlHttpRequest object, the approach I decided to take was as follows:

  1. Set the series of steps in the session, including any and all parameters I was aware of at the time the process starts.
  2. Open a page which uses an XmlHttpRequest to make a single AJAX call to a handler, which would call the functions that do the actual work.
  3. Read and parse the output from the AJAX handler, and update the content of the page, when the XHR's readyState was equal to 3.
Any experienced AJAX developer knows what problem I eventually encountered. The app worked great while I was developing it. But when I went to run it in IE, it did not show any progress until the entire process was complete. You see, IE does not allow access to the responseText attribute of the XMLHTTP object until the page has finished loading (readyState == 4). (more…)

By kryptx, ago
Uncategorized

Solving strange problems with PHP/TDS/MSSQL

This afternoon I began working on bringing a new production server online to facilitate my client's customers paying their own invoices through an application I wrote. The application is written in PHP and the client's customer database, with which it interacts, is Microsoft SQL Server 7.0. The application worked wonderfully on my development machine. Unfortunately, upon installing it on the production server, it exhibited very peculiar behavior: it would connect successfully to MSSQL, and most queries would be accepted and return correct results. Of the entire app, it appeared that there was only one query which did not function properly. When PHP attempted to execute this query to MSSQL, I received a Fatal error: Allowed memory size of X bytes exhausted (tried to allocate Y bytes) error.   Increasing the memory limit did not relieve this error, and in fact, writing a very simple script containing only the problematic query exhibited the same behavior. (more…)

By kryptx, ago