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
R

Robert C Cartaino

@Robert C Cartaino
About
Posts
94
Topics
4
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Home! Sweet Home!
    R Robert C Cartaino

    I was about to check out another floor plan designer (FloorPlanner.com[^]) because it is free and online. I haven't tried it, yet, but I thought I would throw it out there in case anyone else was interested. I'll have to try this Sweet Home 3D, too. Thanks. Enjoy, Robert C. Cartaino

    The Lounge html database design algorithms

  • Have Time to Code More with a Feedbag
    R Robert C Cartaino

    New Wearable Feedbags Let Americans Eat More, Move Less[^] According to David Novak, CEO Yum! Foods, Inc, "Something that we heard over and over again was 'I really love your food, I just wish it wasn't so much effort to have to eat it.' ... It's hot, steamy food in your face right now." "Sometimes I don't feel like moving my arms," exclaimed one customer. Come on. You know you want to. Enjoy, Robert C. Cartaino

    The Lounge css com sysadmin sales announcement

  • PDF Mangement Software
    R Robert C Cartaino

    I have yet to find the "perfect" software for managing a large number of PDF documents. I had the best luck using two programs: Paperport[^] and iView Multimedia Pro (now Expression Media[^]). But they both had problems. With Paperport, I liked the visual interface (thumbnails) which helped me find my documents visually. But the older version I was using was strictly directory based. It didn't have a useful tagging interface so I could place documents into multiple categories. And the software never quite felt "finished" to me. There was a lot of needed functionality missing. Newer versions might have taken care of all these problems. I have not tried it lately. I loved iView Multimedia. It was really designed as a photo management system but it thumbnail-ed PDF files and I could take advantage of its excellent visual interface and all the cataloging features to manage my document collection. It was excellent. But it was bought out by Microsoft in 2006 and rebranded Expression Media (part of Expression Studio). I don't know if Microsoft maintained the PDF compatability. I haven't gotten around to trying it. If it does, fantastic. Expression Media is designed to manage all of your digital assets and Expression Studio creates all sorts of desktop and web content. They have a free trial, if you want to take a look at it. Enjoy, Robert C. Cartaino

    The Lounge database sysadmin question

  • Any Serious/Experienced Photographers Here?
    R Robert C Cartaino

    John Simmons / outlaw programmer wrote:

    I'm sure this is partially caused by my lack of familiarity with Photoshop, but I'm equally sure that a large part of the problem is my camera settings and lighting techniques. I'm doing this on as small of a budget as I can get away with,

    I have a lot of experience in photography and doing photo retouching work. I can give you a quick-but-effective fix for both the exposure and the white balance problems for the photos your already took. Here are your photos using the corrections I want to show you: Photo 1 - Before (top) and After (bottom)[^] Photo 2 - Before (top) and After (bottom)[^] 1. Open the photo in Photoshop. 2. Type Ctrl-L (Image > Adjustments > Levels). 3. Change the "Channel" dropdown to "Red". 4. In the histogram (input levels), move the left slider (black) and right slider (white) until they just touch the middle bulk portion of the curve (Here[^] is what the red channel looks like when I'm done). 5. Repeat step 4 with both the "Blue Channel" and the "Green Channel". I think your lighting setup is fine the way it is. If you were doing this professionally or doing a huge quantity of photos, we could get into better lighting setups and properly setting your white balance with an 18% grey card. But, without getting into the effort or expense, you can get pretty good results with a bit of post processing. 'Just my opinion. Enjoy, Robert C. Cartaino

    The Lounge com adobe help question announcement

  • Subtle SQL Error
    R Robert C Cartaino

    Harvey Saayman wrote:

    I code with the Courier New font @ a size of 8 @ a screen resolution of 1280 X 1024, the difference between a ( and a { is hardly noticeable!!

    I've been there. If you have ClearType font smoothing turned on, try switching to Consolas for your monospaced programming font. Without font smoothing, Consolas has a lot of problems. When you have ClearType turned on, a lot of the font details are obscured in Courier New. So Consolas was designed with font-smoothing and programming in mind. I think it is going to become the de facto standard as programmers move to Vista and beyond. Jump into Word and type { } in both Courier New and Consolas. Even at 8 point, you can see the added definition. Enjoy, Robert C. Cartaino

    Clever Code csharp database help question

  • Gauging Interest
    R Robert C Cartaino

    Yes, I would be interested in reading about your program. Please post.

    The Lounge csharp winforms tools help question

  • Avoid return statement in the middle - horror or not?
    R Robert C Cartaino

    Andrew Torrance wrote:

    if( !FlagA || !FlagB || !FlagC) // Select Variant on !Flagx or Flagx == false depending on language DoOtherThing(); else { if(PromptUser()) DoSomething(); }

    ...except if PromptUser() fails, you also have to execute DoOtherThing(). So you need to add to your code:

    if( !FlagA || !FlagB || !FlagC) // Select Variant on !Flagx or Flagx == false depending on language
    DoOtherThing();
    else
    {
    if(PromptUser())
    DoSomething();
    else DoOtherThing();
    }

    The Weird and The Wonderful question

  • Avoid return statement in the middle - horror or not?
    R Robert C Cartaino

    harold aptroot wrote:

    Java also seems to behave differently from what you said:

    I think you are right. I was looking at this section[^] of the Java language specification: 15.7.2 Evaluate Operands before Operation The Java programming language also guarantees that every operand of an operator (except the conditional operators &&, ||, and ? : ) appears to be fully evaluated before any part of the operation itself is performed. They do explicitly exempt the logical operators. Let's hope that && is not overloaded -- in C++ at least -- then short circuiting does not apply. Then I was reading this on C++ Sequence Points[^]. It says that "the left operand of the logical AND operator is completely evaluated and all side effects completed before continuing. There is no guarantee that the right operand of the logical AND operator will be evaluated. Of course, it doesn't say that is guaranteed not to be evaluated, either. Then it says this: "The controlling expression in a selection (if or switch) statement. The expression is completely evaluated and all side effects completed before the code dependent on the selection is executed." So, who knows. My conclusion would be that a C/C++ compiler is indeed supposed to do left-right evaluation and short circuiting. But I still say it's irrelevant. If I have to hunt that hard to get down into the bowels of how a compiler works to determine how my code will execute, I say it's a bad programming practice. I'll take these guys word for it: ...The moral is that writing code that depends on order of evaluation is a bad programming practice in any language. Naturally, it is necessary to know what things to avoid, but if you don't know how they are done on various machines, you won't be tempted to take advantage of a particular implementation. -- The C Programming Language[

    The Weird and The Wonderful question

  • Avoid return statement in the middle - horror or not?
    R Robert C Cartaino

    I completely agree with your sentiment. But in this specific example, it looks like processes generating FlagA, FlagB, and FlagC should always execute, regardless of whether any of the previous processes fail. Your guardConditionals don't allow for that.

    The Weird and The Wonderful question

  • Avoid return statement in the middle - horror or not?
    R Robert C Cartaino

    [Message Deleted]

    The Weird and The Wonderful question

  • Help with a Linked List Program
    R Robert C Cartaino

    I don't know the specifics of your implementation of "LinkedList.h" but here are a couple of quick things to get you started. You don't ever really "append a node". When you add "7 feet, 2 inches", you are really inserting it (in the middle of your list). You have to find the node you want to add before (just before "8 feet, 9 inches") and then insert your node. You are inserting distance4 before you create it. You have to create the object first, then insert it. In your code, you say you are "deleting the last node" but that's not what you are doing. Do are deleting a specific node. To delete the last node, you have to go to the end of the list and then delete that node.

    C / C++ / MFC data-structures help

  • Clarke and Wright Algorithm
    R Robert C Cartaino

    Try this: Single-Depot VRP[^]. They don't give you the code but there's more than enough information to show you how to implement it.

    Algorithms algorithms help

  • Avoid return statement in the middle - horror or not?
    R Robert C Cartaino

    You forgot to execute DoSomething() in your second example. That aside... I don't necessarily dislike "return in the middle." But I expect early returns to be an error condition (i.e. invalid parameter, resource not obtained, etc) to keep the method from continuing. In your example, the early return seems to be the normal, successful condition and that makes me uncomfortable. So looking at your code samples... Definitely not the first example. If you ever want to add more logic around DoOtherThing(), you've essentially "cut-and-pasted" your code all over the place (a big no-no). There are a lot of conditions where DoOtherThing() would be executed. According to your logic, if each process (A, B, and C) passes, ask the user if they want to DoSomething(). If user says "no" or any of the processes fail, then DoOtherThing(). To make my intentions clear, I would try and write the logic exactly as I would describe it (of course, the variables would be more "English-Like" if I knew their purpose). Maybe something like this:

    // assume for the moment, we don't need to DoSomething()
    bool DoSomethingNeeded = false;

    if (FlagA && FlagB && FlagC)
    {
    // if all processes passed, ask the user if we need to DoSomething()
    DoSomthingNeeded = PromptUser();
    }

    if (DoSomethingNeeded)
    {
    DoSomething();
    }
    else
    {
    DoOtherThing();
    }
    return;

    The Weird and The Wonderful question

  • regular expression cleanup!
    R Robert C Cartaino

    I think you should forget about regular expressions as a solution to your problem. You really should consider cleaning up and re-working your code first... at least for the learning experience. Learning how to do these types of manipulations is pretty important and, looking at your code, you're just not there, yet. All those temp variables and creating new strings in the loops area really expensive. Learn how strings work. Learn what immutable means and what happens when you build strings repeatedly within a loop. As a first step, start from the basics. Learn to traverse a string and manipulate it character by character (as you attempted above). Start with something like this:

    private string CleanString(string dirtyString)
    {
    StringBuilder cleanString = new StringBuilder(); // Learn what this does and why to use it
    foreach (char c in dirtyString)
    {
    // Note: C# strings are made up of 2-byte Unicode/UTF-16 characters, not ASCII characters.
    if ((c != '\u0009') || (c != '\u000B') ... etc. )
    {
    // if character is not dirty, add it to the new string
    cleanString.Append(c);
    }
    }
    return (cleanString.ToString());
    }

    Get that working, but then start using .NET's built in methods to improve your code. Next, read about string.IndexOf(char) so you can search the entire string at once for a character. Rewrite your code and get that working. Then, try creating an array of "dirty characters" so you can search for them all at once. Start by reading about this stuff:

    char[] dirtyChars = new char[] { '\u0009', '\u000B', ... etc. };
    int dirtyIndex = dirtyString.IndexOfAny(dirtyChars);

    Then rewrite your code again and get it working. Then read about regular expressions, if you're curious. Will regular expressions work better? Maybe marginally... that's a really small "maybe." Probably not enough to matter. More readable?... I doubt it. Enjoy, Robert C. Cartaino

    modified on Wednesday, November 19, 2008 5:24 PM

    C# html regex performance help question

  • Case select versus IF Statement
    R Robert C Cartaino

    EliottA wrote:

    So there is no actual efficiency when using a select case over a bunch of if statements?

    In your situation, there is no "actual efficiency" in terms of performance using if statements vs using switch statements. If your deepest loops are taking 2 seconds to execute, switching from if to switch may improve your execution time by the tiniest fraction of a millisecond. But that's besides the point. Unless you absolutely need to shave milliseconds off your code, decisions about how your code is organized should be about readability and communicating your intent to future readers of the code. Don't prematurely optimize. That aside, there is more opportunity for a compiler to optimize long switch statements than with a series of if statements. The compiler will typically convert if statements into a series of compare-and-jump operations. Switch statements (in C#) can be implemented using techniques like jump tables (when comparing ints) or hash tables (when comparing strings) to increase code efficiency. But we're talking about real low-level, behind-the-scenes stuff that the average developer will likely never have to consider in real-world applications. Enjoy, Robert C. Cartaino

    C# question

  • Worse Than Global Warming
    R Robert C Cartaino

    I have been alarmed by a trend I noticed over the last couple of months. My discovery is SO DISTURBING, that it requires absolutely no scientific proof AT ALL. It is time to panic. Over the last couple of months, it seems that each day there is just a little less sunlight than the day before. No, really. It's true. My measurements show that there was less sunlight from July to August. There was even less sunlight from August to September. The day-to-day loss of sunlight is subtle but, if this trend continues, soon there will be NO SUNLIGHT AT ALL! "So what?" you may say. "My laptop has no anti-glare screen so reading it will be easier." That's true. The sun is already THOUSANDS of times brighter than your laptop so who cares? But there's a downside. In the last 30 days, there has been a loss of 47 minutes of daylight. This may not seem like much but the cumulative effects are disturbing. According to my calculations, by January 5th, 2010, there will be NO SUNLIGHT AT ALL! Fourteen months may seem like a long time to you and me but let’s not leave this stratospheric calamity to our grandchildren. We have to do something now! For those of us without advanced degrees in meteorological phenomena, I asked a leading scientist what a world without daylight would mean: It will suck. First of all, it will be dark. It will be cold. All plant life will die. I’m not just talking about algae and spathiphyllum here. I’m talking about orchids and cantaloupe and peanuts and white tea which still has a naturally light flavor. Without plants, plant-eating animals will die. Then people. The vegetarians will go first; then the Democrats, followed by the turtles; then the pigeons and, finally, the dolphins. Don’t get me wrong. I’m no science freak. But I love the sun. It makes me happy. I can’t imagine a world without sunlight. You may ask why no one else has noticed this phenomenon. I found an interesting website run by the U.S. Naval Observatory (Astronomical Applications Dept) which has a document called "Rise and Set for the Sun for 2008." What I discovered is that THE GOVERNMENT ALREADY KNOWS ABOUT THE PRECIPITOUS LOSS OF DAYLIGHT over the last couple of months. Why haven't they told us? Is it a cover up? I’ve concluded that a conspiracy is underway, supported by the lobbyists working for the BEACH UMBRELLA industry. Think about it. Surely the government has developed some sort of advanced “artificial sun” technology to keep the fat cats of Malibu hip deep in their suntan-oil fortunes. No b

    The Lounge css question

  • Analysis and Design book?
    R Robert C Cartaino

    For object-oriented analysis and design, I would recommend this book: Object Design: Roles, Responsibilities, and Collaborations[^].

    Work Issues csharp learning design tutorial question

  • Monte carlo Rabin_Karp Search
    R Robert C Cartaino

    From this website[^]. Algorithm 9.2.8 Monte Carlo Rabin-Karp Search This algorithm searches for occurrences of a pattern p in a text t. It prints out a list of indexes such that with high probability t[i..i +m− 1] = p for every index i on the list.

    Input Parameters: p, t
    Output Parameters: None

    mc_rabin_karp_search(p, t)
    {
    m = p.length
    n = t.length
    q = randomly chosen prime number less than mn2
    r = 2m−1 mod q

      // computation of initial remainders
      f\[0\] = 0
      pfinger = 0
      for j = 0 to m-1 
      {
            f\[0\] = 2 \* f\[0\] + t\[j\] mod q
            pfinger = 2 \* pfinger + p\[j\] mod q
      }
    
      i = 0
      while (i + m ≤ n) 
      {
            if (f\[i\] == pfinger)
                  prinln(“Match at position” + i)
    
            f\[i + 1\] = 2 \* (f\[i\]- r \* t\[i\]) + t\[i + m\] mod q
            i = i + 1
      }
    

    }

    Algorithms

  • Factorials (C#)
    R Robert C Cartaino

    Ri Qen-Sin wrote:

    You might as well as craft a method to look up the answer in a pre-made dictionary or table of some sort.

    I just posted this above:

        public static ulong factorial(int factor)
        {
            ulong\[\] factorials = { 1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800, 
                                    39916800, 479001600, 6227020800, 87178291200, 1307674368000, 
                                    20922789888000, 355687428096000, 6402373705728000, 
                                    121645100408832000, 2432902008176640000, 14197454024290336768 };
    
            return factorials\[factor\];
        }
    

    An unsigned long value will overrun after 21!.

    The Lounge question csharp html com

  • Factorials (C#)
    R Robert C Cartaino

    Marc Clifton wrote:

    I was annoyed to find that the Math class doesn't include a Factorial method

    Too bad C# doesn't support extension methods for static classes. You could have written something like:

    public static class MyExtensions
    {
    public static ulong factorial(this System.Math, int factor) { ... } ; // THIS WONT WORK
    }

    and called : ulong factorial = Math.factorial(10); But... nope. I guess you could do this:

    namespace MarcsCoolStuff
    {
    public static class Math
    {
    public static ulong factorial(int factor)
    {
    ulong[] factorials = { 1, 1, 2, 6, 24, 120, 720, 5040, 40320, 362880, 3628800,
    39916800, 479001600, 6227020800, 87178291200, 1307674368000,
    20922789888000, 355687428096000, 6402373705728000,
    121645100408832000, 2432902008176640000, 14197454024290336768 };

            return factorials\[factor\];
        }
    }
    

    }

    Wrap the array lookup around a try/catch IndexOutOfRange exception if you want bounds checking. And now you can call: ulong factorial = MarcsCoolStuff.Math.factorial(10); ;) Nah, don't do that. It's too obtuse to "fake" a Math class. It's screaming fast though.

    The Lounge question csharp html com
  • Login

  • Don't have an account? Register

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