Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
S

Sean Michael Murphy

@Sean Michael Murphy
About
Posts
122
Topics
4
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Discworld - Who's the best? [modified]
    S Sean Michael Murphy

    "Oh, please sue the university! We've got a pond full of people who tried to sue the university..." - Archchancellor Ridcully Ridcully plays hardball, man. My favourite sentiment from any of the books.

    The Lounge question

  • updating parent form from child object
    S Sean Michael Murphy

    shwaguy wrote:

    Using C#.net express edition I created an application that has the main code in the parent form. In this form I create an object and I want that object to change values in the parent form before the object returns a value (I am doing a progressbar). I could create a form object from the child object but that would not look as nice.

    Either have your object fire progress events, which you can wire and use to update your ProgressBar from the main form, or pass the ProgressBar to the object and have it do the update directly. The first method is more code, but vastly preferrable. If your object uses threads, beware of UI marshalling issues. Share and enjoy. Sean

    C# csharp help

  • How much does MSDN Magazine pay for an article?
    S Sean Michael Murphy

    Marc Clifton wrote:

    Or any of the other rags out there? Is it worth it? I would think not, but I want some facts, not conjecture, for a discussion I'm having with someone. Marc

    In 2000 I sold an article to the Visual Basic Programmer's Journal, for which I was paid approx $900USD. I don't know if a word-count formula was involved, or how they arrived at that sum, but it was a huge amount of money at the time considering the CAD->USD exchange. I was a poor youngster then and all that lovely money showed up the same month I got married, so it was very handy. I never did the effort/reward calculation to determine its absolute "worthfulness", but being published was something I always wanted to do so the effort was not a consideration. Share and enjoy. Sean

    The Lounge com question discussion

  • Process.Start
    S Sean Michael Murphy

    eggie5 wrote:

    Currently, this code will return immediately after the process is started. How can I modify it so that it will not return until the process has stopped?

    process.Start();
    process.WaitForExit();

    Share and enjoy. Sean

    C# question

  • Talking about the dollar...
    S Sean Michael Murphy

    73Zeppelin wrote:

    I see you're working in T.O. Your name is more east-coast though. What's the sentiment over there with the dollar so high?

    I was born in Montreal, but lived in the Toronto area pretty much my whole life. I work at a huge multinational corp. and don't travel much with a 2 1/2yr old, so I'm pretty insulated from caring about the exchange rate. In conversations with others though there appears to be lots of national pride over the surging dollar. Misplaced pride, in that currency speculators are probably just selling USD and buying anything else, rather than explicitly endorsing the Great White North. IANAE*, but I think everyone recognizes that Canada just isn't competitive enough in manufacturing to sustain this kind of exchange for too long without crippling job losses. Fun in the short-term though... Share and enjoy. Sean * I am not an economist

    The Back Room adobe question

  • Talking about the dollar...
    S Sean Michael Murphy

    73Zeppelin wrote:

    Does anyone really give a sh*t?

    Yeah, apparently the sarcasm didn't come through as loud and clear as I had hoped. For the record, I don't care how Heidi or any of her friends demands their payments. I don't care what they (or any other celebrity) think of the stability or the future value of the USD. Allan Greenspan doesn't want to get paid in USD? Suddenly I'm interested. Heidi? Not so much. Share and enjoy. Sean

    The Back Room adobe question

  • Talking about the dollar...
    S Sean Michael Murphy

    leckey wrote:

    I read that the US dollar is so bad that Heidi Klum refuses to be paid in US dollars.

    Bwahaha. A German national refuses to be paid in US dollars? I think this says more about Heidi Klum than it does the currency. What about the other non-American-30-somethingish-former-supermodels? Will they still take USD? Did you read this in the economics section of Cosmo? I need a citation. Let me know when Britney refuses US dollars. Only then will I worry. And, as a couple of people have already pointed out, the Canuck Buck is kicking ass and taking names. Up to $1.09USD, before retreating slightly. We're passing a hat around the office and once we have $25CAD (several million US), we're going to buy Mt. Rushmore and carve the faces of our national idols (Bob and Doug McKenzie, Wayne Greztky and Don Cherry) into it. Share and enjoy. Sean

    The Back Room adobe question

  • Another Error Message That's Helpful (NOT)
    S Sean Michael Murphy

    Chris Meech wrote:

    I'm beginning to thing you and I work for the same company. Let's see know, large Canadian financial institution. Can you say BANK.

    Yeah, I just looked you up in the enterprise directory and apparently we do share an employer. I am ashamed to say that I was an active participant in the UAT of that particular upgrade, and I gave the upgrade a lukewarm endorsement prior to it being rolled out. I didn't get that stupid error during the UAT. Not that it would have mattered, of course. We had to upgrade. The performance of the server of the old version was shameful. The new back end is supposed to be much better. Share and enjoy. Sean

    The Lounge help tutorial question

  • Another Error Message That's Helpful (NOT)
    S Sean Michael Murphy

    Chris Meech wrote:

    I won't mention the particular piece of software, but I just opened up a client application and received the following in a message box, "Cannot show view information: neuron I/O error: The pipe is being closed".

    I know the application. By the most improbable coincidence I got that error (first time I've ever seen it) this morning too. Let me guess: A source control application? From a Canadian vendor? Am I getting warm? I like the "neuron" bit. Make it feel like there's some AI going on in the background... Share and enjoy. Sean

    The Lounge help tutorial question

  • Count Decimals
    S Sean Michael Murphy

    jgasm wrote:

    I simply want to count how many decimals are in the string, unfortunately everything in regex seems to involve replacing the decimals...and regex seems really heavy way of doing something that should be simple.

    If you know the string always has a decimal:

    Int32 decimalCount = text.Split('.')[1].Length

    If it doesn't always have a decimal, it gets much more complicated :):

    Int32 decimalCount = text.IndexOf('.') > -1 ? text.Split('.')[1].Length : 0;

    Share and enjoy. Sean

    C# algorithms regex question discussion

  • Buzzycode.com
    S Sean Michael Murphy

    My Indian doppleganger[^] is Pontius Pilate[^]! My other articles are copied, but don't have as interesting authors... Sean

    Site Bugs / Suggestions database com architecture tutorial

  • Console output to a file
    S Sean Michael Murphy

    sanki779 wrote:

    For the Debugging purpose I need that whatever output I am getting to be pasted to a log file also say to C:\Log.txt file. How is it possible to redirect all the console output to a file.

    If your app doesn't accept any input, don't modify it at all. Just call it from the command line and redirect the output using DOS to wherever you want.

    c:\>myapp.exe > c:\log.txt

    If your app needs input, naturally this won't work. Share and enjoy. Sean

    C# csharp

  • maximum number of methods supported in C# class
    S Sean Michael Murphy

    PIEBALDconsult wrote:

    A) I don't think there's any need for including the NewLines. B) Why step by one? Why not double methodCount after each successful compile?

    Both excellent suggestions. 1) The NewLines was so I could preview the code during the initial stages of development. Same reason for the indents. I like even my autogenerated code to be neat and tidy. :) 2) Yup. Could have done a more efficient search, but was more interested in starting the app to get the result. By the time I had written the original and the slightly optimized version, I had spent 45 minutes and was getting tired of the exercise. And I thought that The Answer would actually be fairly low (thought it would probably be 256, 512 or 1024 max). I was surprised to see it climb over 2K, but kept expecting it to fail shortly. It never did, so I published the snippet and the result and encouraged others to continue in the work. The application was really intended as a starting point for figuring out the answer to this guys question. It was not a fully peer reviewed, optimized, documented, shrink-wrapped product, as you and others have adequately demonstrated by now... Sean

    C# question csharp

  • TCP connection
    S Sean Michael Murphy

    pmartike wrote:

    If anyone knows how to make a TCP connection where the same client can connect and disconnect multiple times.

    Sure. In your code above, you're only listening for the first connection. Your Listen_Button_Click() method calls BeginReceive() and passes it the delegate for AcceptConn(). So far so good, but once that method is called your socket isn't listening anymore. You have to re-wire the callback by invoking BeginReceive() again to listen for more incoming connections. Share and enjoy. Sean

    C# help com sysadmin tutorial

  • maximum number of methods supported in C# class
    S Sean Michael Murphy

    vytheeswaran wrote:

    Now I feeling, I shouldn't ask this question first of all

    Don't be crazy. I enjoyed thinking about it. Sean

    C# question csharp

  • maximum number of methods supported in C# class
    S Sean Michael Murphy

    dnh wrote:

    No wonder, always use StringBuilder for string concatenation in a loop.

    Hmmm. Interesting. When I originally undertook to code this snippet to try to figure an answer to this guys question, optimization was pretty far from my mind. I mean, I cranked the original bit of code out in 15 minutes (or so) and had originally coded it so the methods would be recreated every time. I took another 5 minutes and optimized it so that only 1 method (the new one) would have to be concatenated to the "guts", which was then stuck in between the fixed "header" and "footer" of the class. It ran slowly, but I assumed that most of the overhead was in the actual code compilation (compiling classes of 15000 lines), and not a little bit of string concatenation. So I've re-written it using StringBuilder and timed both versions for 500 iterations. The original code did 500 iterations on my PC in 161.5222 seconds. This version:

    StringBuilder inner = new StringBuilder();
     
    DateTime startTime = DateTime.Now;
       
    for (Int32 i = 0; i < 500; i++) {
       inner.Append(" public Int32 Method" + methodCount.ToString() + "() {" + Environment.NewLine +
                    " return 42;" + Environment.NewLine +
                    " }" + Environment.NewLine);
     
       StringBuilder code = new StringBuilder(pre);
       code.Append(inner);
       code.Append(post);
       cr = icc.CompileAssemblyFromSource(cp, code.ToString());
     
       if (cr.Errors.Count > 0)
          break;
     
       methodCount++;
     
       if (methodCount % 10 == 0)
          System.Console.WriteLine(methodCount.ToString());
    }
     
    TimeSpan ts = DateTime.Now - startTime;
     
    System.Console.WriteLine(ts.TotalSeconds);

    did it in 160.111. Much less that 1% slower. Not a string concatenation to be found, except for the line joins. Anything to add? Thanks. Sean

    C# question csharp

  • maximum number of methods supported in C# class
    S Sean Michael Murphy

    I let this run for an hour to get to 5000 before I gave up. Someone with more CPU and physical RAM than I have should run it and see where it ends...

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.CodeDom.Compiler;
       
    namespace MethodCountLimitFinder {
       class Program {
          static void Main(string[] args) {
             Int32 methodCount = 1;
             Microsoft.CSharp.CSharpCodeProvider cscp = new Microsoft.CSharp.CSharpCodeProvider();
             ICodeCompiler icc = cscp.CreateCompiler();
       
             CompilerParameters cp = new CompilerParameters();
             cp.GenerateExecutable = false;
             cp.GenerateInMemory = true;
       
             CompilerResults cr = null;
             string pre = "using System;" + Environment.NewLine +
                      Environment.NewLine +
                      "namespace Tester {" + Environment.NewLine +
                      " class Test {" + Environment.NewLine;
             string post = " }" + Environment.NewLine +
                      "}";
             string inner = string.Empty;
       
             while (true) {
                inner += " public Int32 Method" + methodCount.ToString() + "() {" + Environment.NewLine +
                         " return 42;" + Environment.NewLine +
                         " }" + Envi

    C# question csharp

  • compression
    S Sean Michael Murphy

    Dave Kreskowiak wrote:

    There's a full 101 key keyboard in front of you. Use it.

    Hey, the subject of the post is "compression". Maybe he's proposing some sort of text compression algorithm. Lossy, obviously... Anyway, your guess is as good as mine... Sean

    C#

  • decision matrix in C#
    S Sean Michael Murphy

    amatbrewer wrote:

    Thanks for the reply!

    No prob. Evaluating card hands with multi-dimensional arrays[^] is sort of a hobby of mine. :) Share and enjoy. Sean

    C# csharp data-structures question discussion

  • decision matrix in C#
    S Sean Michael Murphy

    amatbrewer wrote:

    While playing around with a Black Jack program, I got wondering about the best way to do a decision matrix in C#. What I am thinking of is basically a 2 dimensional matrix with each row/col combination containing a value representing 1 of a number of different options (e.g. Hit, Stand, Double, Split, etc). Is a 2 dimensional array the best way to implement it, or is there a better method?

    That seems pretty elegant to me, but what you're proposing is only good for evaluating the 1st move of the hand. If one axis represents what the dealer is showing, and the other axis represents what you have showing, it's a very fast lookup of what to do. After the first move, you either need to code a more traditional if {} else {} type code construct, or have another decision matrix, since you don't have options like splitting and doubling-down available to you after the first decision... The pure decision matrix approach scores higher for me than the if {} else {} construct for your purpose because: 1) Once the array is initialized, evaluating decisions is very, very fast 2) If you structure your code properly, your intentions are perfectly clear. You cannot mess up the logic. Pseudo-code:

    enum Action {
       Hit = 0,
       Stand = 1,
       DD = 2,
       Split = 3
    }
     
    private static Action[][] _decision = new Action[][]
    // Dealer showing -> 2 3 4 5 6 ...
    // You showing V
    { new Action[] */ 2 */ { Hit, Hit, Stand, DD, Hit, ... },
      new Action[] /* 3 */ { Hit, Hit, Stand, Hit, DD, ... },
    .
    .
    .
      new Action[] /*21 */ { Stand, Stand, Stand, Stand, ...}
    }
     
    private static Action Decision(Int32 dealerShow, Int32 meShow) {
       return _decision[meShow - 2][dealerShow - 2];
    }

    Share and enjoy. Sean

    C# csharp data-structures question discussion
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups