Friday, April 29, 2011

What is the mechanism that keeps various sections on page from being repositioned when browser resizes

In this web site when you shrink the browser window the white space on the left and right disapear first, following by the shrinking of the right panel, followed by the main container panel. I have recently started to use ASP.NET MVC and in my test case my containers drop below the other containers as I resize the browser window. I am using a a site.master page with a left, center and right section as part of the body. It there an attribute in css that dictates the behavior or an HTML element? I have viewed the page source of this site's main page and looked at the CSS but nothing obvious has jumped out at me as how this is being controlled.

Thanks any help is always appreciated.

From stackoverflow
  • It can be a combination of float, position, and margin and how you set these elements up. Without a URL, it will be hard to say exactly what the problem is or how to fix it.

    For a starting point, I would suggest taking a look at YUI CSS Grids or 960.gs (960 Grid System) and one of the various reset.css files floating around out there. YUI has a very good one. The reset.css file makes your css look and act the same in all browsers and the grid systems give you a starting point for designing your site. They also give you confidence that what you are designing will look and act the same in all browsers.

    http://developer.yahoo.com/yui/grids/ http://960.gs/

  • This is a html layout issue. Probaly the asp.net mvc layout is not very well done. Have a search for 'css column layout' on web there are plenty of examples on how to achieve a good layout. See for example In Search of the Holy Grail by MATTHEW LEVINE for a good discussion of a 3 column layout technique.

  • One of the great things about web development is that most often, when you see a site and think "How did they do that", it's very easy to look at the code and find out, and also to test it out - tools like Firebug for Firefox, the Developer Tools in IE 8 (F12) and Chrome will all display nicely formatted source and CSS, and will let you modify it in situ.

    In the case of SO, the main body of the site is contained in a div with class of "container", the style rules for "container" are:

    .container {
      margin: 0 auto;
      text-align: left;
      width: 950px;
    }
    

    The key thing we're looking at here is that this class has a fixed width - 950 pixels, and the margins are set to (expanded):

    margin-top: 0px;
    margin-right: auto;
    margin-bottom: 0px;
    margin-left: auto;
    

    Setting the left and right margins to "auto" has the affect of centering the div within the edges of it's container, and allowing them to expand to whatever width is needed once the container has taken up the required 950px.

    Inside the container div, you then have a div with id "content" (no style rules), and then two divs: "mainbar" and "sidebar" whose styles are:

    #mainbar {
      float: left;
      margin-bottom: 40px;
      width: 715px;
    }
    
    #sidebar {
      float: right;
      width: 220px; /* this is also set in the "style" attribute *
    }
    

    These left and right floats are what's positioning the bars in the right places.

    Another handy CSS rule is:

    clear
    

    this can be set to "both", "left" or "right", and will basically reset the floats on the containers.

    However, it sounds like you're after what is often called the "Holy Grail of CSS" (Rick points out that there's a bug in this with IE7, see here for a fix) for good reason: Three Columns, with at least one of them flexible.

    Other examples, of completely flexible layouts include:

    Rick : I used the article Holy Grail of CSS and updated my site and it worked well. But there was a problem with IE7/8 which Gerd Riesselmann posted a fix http://www.gerd-riesselmann.net/development/the-holy-grail-css-layout-fix-for-ie7. His fix worked well.
    Zhaph - Ben Duguid : Thanks for letting me know I'll add that to the answer :)

ReadOnlyAttribute vs PropertyDescriptor.IsReadOnly()

What is the difference between using a PropertyDescriptor that returns a value for the IsReadOnly() method, and one that is associated with a ReadOnlyAttribute?

From stackoverflow
  • No difference when I look at it using Reflector.

    One of the derived class SimplePropertyDescriptor has the following code.

    
        public override bool IsReadOnly
        {
            get
            {
                return this.Attributes.Contains(ReadOnlyAttribute.Yes);
            }
        }
    
    
  • The main difference is that this allows you to seize more control if you provide your own PropertyDescriptor implementation (via ICustomTypeDescriptor, TypeDescriptionProvider or TypeConverter). Then you can choose your own logic for when it is writeable - for example, based on access rights.

    But yes; under the default implementation, it will report read-only for properties without setters, and for properties marked with ReadOnlyAttribute.

    Eric Anastas : So say I am creating my own PropertyDescriptor via ICustomTypeDescriptor then the IsReadOnly() method will override whatever ReadOnly attributes have already been applied to it?
    Marc Gravell : That is correct.

Dealing with Nulls in Comparison Tests in SQL Server 2005

I was writing a Stored procedure today, and I ran into a problem where if one of the values is null (whether it be from a SELECT statement or whether it be a passed in parameter) my expression would evaluate to false where it ought to evaluate to true.

SET ANSI_NULLS ON;
DECLARE @1 INT;
DECLARE @2 INT;
DECLARE @3 INT;
DECLARE @4 INT;

SET @1 = 1;
SET @2 = NULL;
SET @3 = 3;
SET @4 = 3;

IF ((@1 <> @2) OR (@3 <> @4))
   BEGIN
     SELECT 1;
   END
ELSE
   BEGIN
     SELECT 2;
   END
SELECT @1, @2, @3, @4

Returns:

2

1, NULL, 3, 3

I expected it to return:

1

1, NULL, 3, 3

I know I'm missing something simple, anybody have any idea what it is?

Related Question

SQL: Why are NULL Values filtered Out within this WHERE clause?

From stackoverflow
  • One way of dealing with this is you can wrap your NULL values in a known unexpected value, i.e. -1:

    IF ((ISNULL(@1, -1) <> ISNULL(@2, -1)) OR (ISNULL(@3, -1) <> ISNULL(@4, -1)))
       BEGIN
         SELECT 1;
       END
    ELSE
       BEGIN
         SELECT 2;
       END
    

    Obviously if -1 was a possibility then use a different number. If there is no non-possible value, then you will have to use CASE statements.

    A concise way of assigning NULL values to a 'safe' value follows:

    SET @1 = ISNULL(@1, -1)

    This allows the contional test code to remain 'clutter-free'.

    ck : @Gortok: Yes, SET @1 = ISNULL(@1, -1)
    George Stocker : I edited your answer to include your comment, and marked as accepted. Thank you.
  • Any comparison that involves a NULL will evaluate to NULL instead of True or False. Hence the ELSE block of your code gets executed. Because although Null is not the same as False, it definitely isn't the same as True.

    George Stocker : Yea, I surmised as much. I'm hoping for a cleaner solution if you have one.
    codeulike : Use IsNull() with a dummy value as the others are suggesting. Or expand your logic with '@1 is null' type checks.
    codeulike : Like BradC's answer.
    codeulike : Or you can SET @1 = IsNULL(@1,-1) in the lines before if you want a tidier version.
    codeulike : wow, we are all totally scrambling to tell you the same thing!
  • Yes, nulls are a pain. A few ways to handle them. Some of these are MS-SQL specific functions:

    Method 1: Be real explicit about all the options

    IF ((@1 <> @2) 
    OR (@1 is NULL AND @1 IS NOT NULL)
    OR (@1 is NOT NULL AND @1 IS NULL)
    OR (@3 <> @4)
    OR (@3 is NULL AND @4 IS NOT NULL)
    OR (@3 is NOT NULL AND @4 IS NULL))
    

    Method 2: Us a function to change the null into something else, that you know won't match:

    IF ((IsNull(@1,-1) <> IsNull(@2,-1) 
    OR (IsNull(@3,-1) <> IsNull(@4,-1))
    

    Sometimes this first option is better because it is more explicit. The second one has the side-effect of matching a NULL to a NULL.

    Edit: if you want to set them ahead of time, just do

    SET @1 = IsNull(@1,-1);
    

    If it is null, it will set it to -1. If not, it will leave it alone. I think its cleaner to do it INSIDE the function, per my Method 2.

    George Stocker : Yea, the first truth test you listed didn't seem like a viable option. I'm looking for a concise way to re-assign the parameters to -1 if they end up being null (as the result of a select statement or parameters passed in). Any ideas there?
    BradC : Yes, that's what IsNull() does!
    dotjoe : set @1 = isnull(@1, -1);
  • Here's a way to do it without functions, and also might be easier to read. (My eyes start to cross when I see a bunch of NULL-testing functions close together.)

    IF (@1 IS NULL AND @2 IS NULL) OR (@1 = @2)
    BEGIN
        IF (@3 IS NULL AND @4 IS NULL) OR (@3 = @4) 
        BEGIN
            SELECT 2
        END
        ELSE
        BEGIN
            SELECT 1
        END
    END
    ELSE
    BEGIN
        SELECT 1
    END
    
  • If you want to be even more confused, try running the opposite test, as follows:

    SET ANSI_NULLS ON;
    DECLARE @1 INT;
    DECLARE @2 INT;
    DECLARE @3 INT;
    DECLARE @4 INT;
    SET @1 = 1;
    SET @2 = NULL;
    SET @3 = 3;
    SET @4 = 3;
    IF ((@1 = @2) AND (@3 = @4))
       BEGIN     SELECT 1;
       ENDELSE   
       BEGIN     SELECT 2;   
       END
    SELECT @1, @2, @3, @4
    

    The result will not be what you expect from your previous experiment.

    The reason is that SQL engages in a complicated three value logic when it's evaluating expressions that might contain NULLs.

    NULL = 3 is not TRUE. It's not FALSE either. It's NULL. NULL = NULL is not TRUE. It's not FALSE either. It's NULL.

    It's easy to get all mixed up with this. The best way to avoid confusion is to constrain all your critical data to be NOT NULL. However, the requirments may prevent you from doing this, in which case you are just going to have to figure out 3 valued logic, SQL style.

    Don't ask me to defend this.

    (In some environments, UNKNOWN is used in place of NULL for results that are not TRUE or FALSE.)

How do you get Cruise Control to Email the unit test results from Gallio(MbUnit)?

I have a build server that uses Cruise Control to run our test cases. I have successfully configured ccnet 1.4.2 to display the Gallio test results in the webdashboard but I can't seem to get ccservice to email the Gallio test results out in the auto generated Emails. I have tried editing the .xsl file but to no avail. I am merging the .xml output from the MsBuild Gallio task.

From stackoverflow
  • If you can get it to display as you want on the web dashboard then you are close. Now you just need to add the xsl sheet from your dashboard into the xsl folder on the build server and add a refrence to the xsl (just like you did in dashboard.config on the web side) in either the service (ccservice.exe.config) or the console (ccnet.exe.config) config file. And for good housekeeping and to prevent errors later, you should actually include it in both.

TOP N problem with GROUP BY clause

The problem: I need to find all active [GiftPledges] that have the last three [GiftDetails] have a zero amount.

SELECT gp.PledgeId FROM GiftPledge gp
      INNER JOIN GiftDetail gd ON gp.PledgeId = gd.PledgeId
      WHERE gp.PledgeStatus = 'A'
      GROUP BY PledgeId
      HAVING COUNT(PledgeId) >= 3

Now, I have all my [GiftPledges] that have at least three [GiftDetails].

SELECT TOP 3 gdi.Amt FROM GiftDetail gdi
      INNER JOIN GiftHeader ghi ON gdi.GiftRef = ghi.GiftRef
      WHERE gdi.PledgeId = gp.PledgeId
      ORDER BY ghi.GDate DESC

This gives me the three most recent [GiftDetails] associated with a given [GiftPledge]. The problem is that I don't know how to sum the second query and have it be a part of the WHERE clause in the first query.

I found this article about "Top n per Group" and that seems like the direction I need to be headed, but I'm not sure I'm on the right track.

Any help, clarifications or suggestions would be greatly appreciated.

From stackoverflow
  • SELECT gp.PledgeId FROM GiftPledge gp
          INNER JOIN GiftDetail gd ON gp.PledgeId = gd.PledgeId
          WHERE gp.PledgeStatus = 'A'
          GROUP BY PledgeId
          HAVING COUNT(PledgeId) >= 3 
    AND
    GP.PledgeID in (
    SELECT PledgeID From
    (
    SELECT TOP 3 gp.PledgeID, gdi.Amt  FROM GiftDetail gdi
          INNER JOIN GiftHeader ghi ON gdi.GiftRef = ghi.GiftRef
          WHERE gdi.PledgeId = gp.PledgeId
          ORDER BY ghi.GDate DESC
    ) x_amt 
    Group By PledgeID
    Having SUM(AMT) ) x_sum = 0
    

    something like that anyway.

Best practices for multiple associations with the same class in Rails?

I think my question is best described as an example. Let's say I have a simple model called "Thing" and it has a few attributes that are simple data types. Something like...

Thing
   - foo:string
   - goo:string
   - bar:int

That isn't hard. The db table will contain three columns with those three attributes and I can access them with something like @thing.foo or @thing.bar.

But the problem I'm trying to solve is what happens when "foo" or "goo" can no longer be contained in a simple data type? Assume that foo and goo represent the same type of object. That is, they are both instances of "Whazit" just with different data. So now Thing might look like this...

Thing
  - bar:int

But now there is a new model called "Whazit" that looks like this...

Whazit
  - content:string
  - value:int
  - thing_id:int

So far this is all good. Now here is where I'm stuck. If I have @thing, how can I set it up to refer to my 2 instances of Whazit by name (For the record, the "business rule" is that any Thing will always have exactly 2 Whazits)? That is, I need to know if the Whazit I have is basically foo or goo. Obviously, I can't do @thing.foo in the current setup, but I'd that is ideal.

My initial thought is to add a "name" attribute to Whazit so I can get the Whatzits associated with my @thing and then choose the Whazit I want by name that way. That seems ugly though.

Is there a better way?

From stackoverflow
  • There are a couple of ways you could do this. First, you could set up two belongs_to/has_one relationships:

    things
      - bar:int
      - foo_id:int
      - goo_id:int
    
    whazits
      - content:string
      - value:int
    
    class Thing < ActiveRecord::Base
      belongs_to :foo, :class_name => "whazit"
      belongs_to :goo, :class_name => "whazit"
    end
    
    class Whazit < ActiveRecord::Base
      has_one :foo_owner, class_name => "thing", foreign_key => "foo_id"
      has_one :goo_owner, class_name => "thing", foreign_key => "goo_id"
    
      # Perhaps some before save logic to make sure that either foo_owner
      # or goo_owner are non-nil, but not both.
    end
    

    Another option which is a little cleaner, but also more of a pain when dealing with plugins, etc., is single-table inheritance. In this case you have two classes, Foo and Goo, but they're both kept in the whazits table with a type column that distinguishes them.

    things
      - bar:int
    
    whazits
      - content:string
      - value:int
      - thing_id:int
      - type:string
    
    class Thing < ActiveRecord::Base
      belongs_to :foo
      belongs_to :goo
    end
    
    class Whazit < ActiveRecord::Base
      # .. whatever methods they have in common ..
    end
    
    class Foo < Whazit
      has_one :thing
    end
    
    class Goo < Whazit
      has_one :thing
    end
    

    In both cases you can do things like @thing.foo and @thing.goo. With the first method, you'd need to do things like:

    @thing.foo = Whazit.new
    

    whereas with the second method you can do things like:

    @thing.foo = Foo.new
    

    STI has its own set of problems, though, especially if you're using older plugins and gems. Usually it's an issue with the code calling @object.class when what they really want is @object.base_class. It's easy enough to patch when necessary.

  • Your simple solution with adding a "name" doesn't need to be ugly:

    class Thing < ActiveRecord::Base
      has_one :foo, :class_name => "whazit", :conditions => { :name => "foo" }
      has_one :goo, :class_name => "whazit", :conditions => { :name => "goo" }
    end
    

    In fact, it's quite similar to how STI works, except you don't need a separate class.

    The only thing you'll need to watch out for is setting this name when you associate a whazit. That can be as simple as:

    def foo=(assoc)
      assos.name = 'foo'
      super(assoc)
    end
    

What is the best choice for a corporate wiki/blog software tool

With no limits on the technology and cost what is the best wiki/blog solution for corporate use. I have a customer that wants to use blogs to post up-to-date information on company standards for discussion and dissemination, then when the blog entries have been massaged they want to move the content to a wiki page as a more permanent place. Internally they then want to make small modifications to these standards while it is on the wiki but have it readable to the outside world. They do not use share point.

From stackoverflow
  • Confluence is a very good one.

    Sorin Sbarnea : I have *many* years of wiki usage and I am a big fun of them but Confluence is one of the ones I would recommend only to enemies.
  • I'd have thought it would be the other way around: massaging and discussion on a Wiki and then move to a blog when done for viewing by the outside world.

    You can't go wrong with Wordpress for the blog. Free. Tons of themes. Tons of plugins.

  • I think wordpress and mediawiki would be a very acceptable (free) solution. There are several integration solutions for the two.

    Nick Presta : Multi-user WP: http://mu.wordpress.org/ with Automattic support (http://automattic.com/services/support-network/) should work very well, I think.
    Matt Dillard : I would vote against MediaWiki for general corporate use. In our company, the editing syntax and non-intuitive method of creating new pages has proven to be a significant barrier to adoption among the non-developers.
  • I like JSPWiki.

  • Screwturn has helped my team a lot, it's written in asp.net.

  • Is your company using SharePoint? If so, you can setup blog and wiki in SharePoint.

    marc_s : Sharepoint Wiki is a major disappointment - ugly, hard to use - I would stay away from it (even if your company uses Sharepoint elsewhere)...
  • I would look at what tech is in the company already ... you don't want to use wordpress/mediawiki if you already are running IIS and share point. Also look at authentication do you already have an LDAP server ... who will need to authenticate and from where. Try to set up as little extra infrastructure as possible.

  • Plone has a good document editing and publishing workflow. You can control what is being viewed internally and by the outside world.

  • At my work, we'd been using a mix of TiddlyWiki & Sharepoint, but we've now moved to Confluence. It's been really working well for us, and now tons of other teams at my company are also on Confluence.

    Confluence has WYSIWYG editing, email archiving, edit in Word, a Sharepoint Connector, tons of plugins & macros, connection to Jira, personal spaces, RSS feeds, email updates, front page with latest changes, favorite spaces/pages, page templates, page history and diff revisions, labels, export to PDF, comment threads per page, a people directory, etc.

    It's not free though, although I think they have a free version for open source projects.