Friday, May 6, 2011

What does it mean when "virtual" is in "class Foo : public virtual Bar" as opposed to "virtual void frob()"?

What does it mean when "virtual" is in "class Foo : public virtual Bar" as opposed to "virtual void frob()"?

For a given method there are 8 cases stemming from the presence or absence of virtual in the following three locations.

  1. A superclass's functions.
  2. The inheritance chain for this class.
  3. This classes functions.

I think I understand how numbers 1 and 3 interact but number 2 seems redundant. Is it? What am I not understanding?

From stackoverflow
  • That's virtual inheritance, you do it when you know you'll be doing multiple inheritance. That page goes into way more detail.

Basic yet thorough assembly tutorial (linux)?

I want to learn some practical assembly language having just learned the basic concepts in class. Are there any decent books or tutorials (nasm, etc) that would be recommended?

From stackoverflow
  • PC Assembly Language is my favorite resource on assembly programming. It's modern, free, and covers a variety of topics. It uses NASM and the examples are available for Linux (among several other systems).

  • I agree that PC Assembly Language is very good. Other good ones using GAS are:

    Johnd : Professional Assembly Language is a great book, I recommend it, too
  • I recommend the official Intel manuals. You can request the hard copy on Intel's website.

    See http://en.wikipedia.org/wiki/X86_assembly_language#External_links

    * Intel 64 and IA-32 Software Developer Manuals
    * AMD64 Architecture Programmer's Manual Volume 1: Application Programming (PDF)
    * AMD64 Architecture Programmer's Manual Volume 2: System Programming (PDF)
    * AMD64 Architecture Programmer's Manual Volume 3: General-Purpose and System Instructions (PDF)
    * AMD64 Architecture Programmer's Manual Volume 4: 128-Bit Media Instructions (PDF)
    * AMD64 Architecture Programmer's Manual Volume 5: 64-Bit Media and x87 Floating-Point Instructions (PDF)
    

    Some resources from my personal friend, Google:

    • Function calling convention:

    http://unixwiz.net/techtips/win32-callconv-asm.html

    http://www.delorie.com/djgpp/doc/ug/asm/calling.html

    • Brief tutorial

    http://www.csn.ul.ie/~darkstar/assembler/

    • Using SSE

    http://www.neilkemp.us/v4/articles/sse_tutorial/sse_tutorial.html

  • A side question: what is the point in learning assembly just for the heck of it? The thing is, it seems that it would be hard to find a practical application for it, because if you need "low-levelness" you can just write it in pure ol' C.

    Please note, that I am not trying to label your question is useless, on the contrary, I absolutely love coding in assembly languages, even though I haven't done very much of it (yes, sadly it is a bit of a platonic love), - precisely because, it seems, I am unable to find something practical, that can be done in assembly only (after all, if it can be done in C, why use assembly, then?).

    P.S. I am terribly sorry for adding this as an answer, it was too long for a comment :(

  • http://en.wikibooks.org/wiki/X86_Assembly

  • "what is the point in learning assembly just for the heck of it? "

    Because you get to learn HOW the CPU works and get a better understanding of the system. I would say understanding assembler is in itself practical.

  • I would recommend the assembly tutorials page at http://pickatutorial.com

    I hope it helps.

Is there any free java open source application that can monitor website status?

Anyone know any? I need to send in a http request and make sure the http response i got back is not http 500

From stackoverflow
  • You could use httpunit - web-centric unit testing

    John Munsch : But, he's not unit testing. He clearly says that he's monitoring here. Why wouldn't you use a monitoring tool like Big Sister, Hyperic, Monit, etc.?
  • I believe Hyperic HQ meets all of your criteria. It is open source, I believe it is written at least partially in Java, and it is designed to do all kinds of server monitoring.

    It should be able to handle not only the kind of monitoring you requested but other necessary monitoring like memory, CPU usage, and disk space on your servers as well.

  • http-unit or html-unit.

  • If you want to do this yourself, Apache HttpClient is an option:

    GetMethod get = new GetMethod("http://www.stackoverflow.com");
    try
    {
        int resultCode = client.executeMethod(get);
        if (resultCode == 500)
        {
         //do something meaningful here
    
        } // if
    } // try
    catch (Exception e)
    {
        e.printStackTrace();
    }
    finally
    {
        get.releaseConnection();
    }
    
  • While you find it you can use this:

    import java.net.HttpURLConnection;
    import java.net.URL;
    import java.io.IOException;
    
    public class SimplisticMonitor { 
    
        public static void main( String [] args ) throws IOException { 
    
            HttpURLConnection c = ( HttpURLConnection ) 
                          new URL( "http://stackoverflow.com" ).openConnection();
    
            System.out.println( c.getResponseCode() );
        }
    }
    

Rich Faces Tree Control for handheld device

Currently I have a rich tree which works as expected; however the tree itself is not appropriate for small devices where you use your finger for navigation. The arrow that represents the child nodes, and their expansion, is too small. Is there any way to change that graphic, or increase its size?

From stackoverflow
  • Try the icon attribute of the treeNode

  • I discovered that I have to change the style of rich-tree-node-handleicon-expanded and rich-tree-node-handleicon-collapsed.

    .rich-tree-node-handleicon-expanded {
    background-position: top left;
    background-repeat: no-repeat;
    width: 32px;
    height: 32px;
    }

    .rich-tree-node-handleicon-collapsed {
    background-position: top left;
    background-repeat: no-repeat;
    width: 32px;
    height: 32px;
    }

    ChrisAD : Did this solve it? It looks like it should. You can find all the information you need about editing the css here: http://www.jboss.org/file-access/default/members/jbossrichfaces/freezone/docs/devguide/en/html/tree.html

How do I switch panels inside a frame depending on a button action?

I have created an application that has a toolbar, menubar and content area. I have added the menu and toolbar to the application window, but I am stuck with displaying the panel in content area based on the button action (like add, display) which is clicked through the toolbar. Is this a right way to do this? Is there any better way to do this?

From stackoverflow
  • If I understand correctly, you want to have multiple JPanels, only one of which is shown at a time? If that's the case, it sounds like a CardLayout is what you need. You basically add all your JPanels to it with unique names, and then you can tell the CardLayout which of them to show.

    : thank you, this sounds like good idea and I will give it a try. I never thought of this, i was trying assign a Jpanal variable to a content area pane and then change the value of Jpanel variable on the basis of button pressed.
  • I think CardLayout is probably what you want, but if something like memory usage is a concern and you really want to remove and add a new JPanel/Component, you need to remove the old JPanel and add the new one (with proper constraints and/or index depending on the layout). You'll have to validate() the content pane after you make the switch.

probability and relative frequency

If I use relative frequency to estimate the probability of an event, how good is my estimate based on the number of experiments? Is standard deviation a good measure? A paper/link/online book would be perfect.

http://en.wikipedia.org/wiki/Frequentist

From stackoverflow
  • Probably a chi-squared test is what you want. See, for example, the wikipedia page on Pearson's chi-square test. Standard deviation isn't what you want, since that's about the shape of the distribution, not how accurate you estimate is of the actual distribution. Also, note that most of these things are about "normal" distributions, and not all distributions are normal.

  • I believe you are looking for the confidence interval for a sample proportion. Here are some resources that might be helpful:

    Confidence Interval for Proportion Tutorial
    Confidence Interval for Proportion Handout

    Basically your estimate improves inverse proportionally to the square root of the number of samples. So if you want to cut your error in half you are going to need four times as many samples.

  • You count the number of successes s in a sequence n of Yes / No experiments, right? As long as the single experiments are independent you are in the realm of the Binomial distribution (Wikipedia). Frequency of success f = s / n is an estimator of the success probability p and. The variance of your frequency estimate f is p * (1-p) / n for n draws.

    As long as p is not too close to zero or 1, and as long as you do not have "too small" a number of observations n, the standard deviation will be a reasonable measure for the quality of your estimate f.

    If n is large enough (rule of thumb n * p > 10), you can approximate by a normal distribution N(f, f * (1-f) / n), and standard deviation estimate is a good measure. See here for a more extensive discussion.

    This said the approximation with the standard deviation will not cut any ice if this needs to have some academic rigour (e.g. is a homework).

Fluent NHibernate Classes as code behind for Domain classes

Ok, so I want to create a code behind for non-aspx classes. I have mapping files (classes) that I want to show in project as a code behind for entites. Is there a way to do that in VS2008.

From stackoverflow
  • you can create a designer file by naming it Class.Designer.(vb or cs) and it will show up as a code behind for whatever class you're creating. One of the classes will have to be a partial class, however.

  • It sounds like you're talking about files showing up as nested in Solution Explorer. ASP.NET Codebehind files are just one example of that.

    What you want in the project file is something like this:

    <ItemGroup>
        <EmbeddedResource Include="Resources.resx">
          <Generator>ResXFileCodeGenerator</Generator>
          <LastGenOutput>Resources.Designer.cs</LastGenOutput>
          <SubType>Designer</SubType>
        </EmbeddedResource>
    </ItemGroup>
    <ItemGroup>
        <Compile Include="Resources.Designer.cs">
          <DependentUpon>Resources.resx</DependentUpon>
          <AutoGen>True</AutoGen>
          <DesignTime>True</DesignTime>
        </Compile>
    </ItemGroup>
    

    I believe it's the <DependentUpon> element that indicates the nesting.

  • I actually got this to work. Now all "Map" show as code behind classes for my entities, saves me lot of time when looking up the Mapping for the entity. Here is how it looks in the project file.

    <Compile Include="Entities\OrderMap.cs">
      <DependentUpon>Order.cs</DependentUpon>
    </Compile>
    

    We also created a template so that one can just right click, choose add NH entity and it gets saved to the project as shown above. Only problem right now is re-naming of the entity, one has to go in the project and manually change the name. But that does not happen that often and is a small trade off for gain in the productivity.