Thursday, March 31, 2011

Firefox Div Problem

I'm trying to make a little gallery of some school works I've done in my animation class. I want to put 3 images on each line and they are all in divs because I did onion skin wrapping for a dropshadow on them. Unfortunately this makes them all just stick together in two lines across the page. But I want them specifically formatted so I tried to wrap a div of 480px wide around each set of 3. In IE this works great and it looks perfect. However in firefox it does this

I can't figure out why it is putting that one left aligned on the second line and therefore screwing up the order of the rest. Here's my code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Ryan Merl's Portfolio</title>
<style type='text/css'>
    * {
     padding: 0px;
     margin: 0px;
     font-family:Verdana, Arial, Helvetica, sans-serif;
     font-size: 11px;
    }
    body {
     background-color:#333333;
     background-image: url('images/head.png');
     background-repeat: repeat-x;
    }
    a {
     color:#333333;
     text-decoration: none;
    }
    a:hover {
     color:#000000;
     text-decoration:underline;
    }
    div.main {
     width: 800px;
     background-color:#FFFFFF;
     margin-top: 10px;
     color: #000000;
     height: 1000px;
     margin-bottom: 10px;
    }
    img.thumb {

    }
    .wrap1, .wrap2, .wrap3 {
     display:inline-table;
     /* \*/display:block;/**/
    }
    .wrap1 {
     float:left;
     background:url('images/shadow.gif') right bottom no-repeat;
    }
    .wrap2 {
     background:url('images/corner_bl.gif') left bottom no-repeat;
    }
    .wrap3 {
     padding:0 4px 4px 0;
     background:url('images/corner_tr.gif' ) right top no-repeat;
    }
</style>
<link rel="stylesheet" type="text/css" href="doc/css/style.css" />
<script type="text/javascript" src="src/adapter/shadowbox-base.js"></script>
<script type="text/javascript" src="src/shadowbox.js"></script>
<script type="text/javascript" src="glossy.js"></script>
<script type="text/javascript">

Shadowbox.loadSkin('classic', 'src/skin');
Shadowbox.loadLanguage('en', 'src/lang');
Shadowbox.loadPlayer(['flv', 'html','img', 'swf'], 'src/player');

window.onload = function(){
    Shadowbox.init();
};

</script>
</head>
<body>
    <center><div class='main'>
        <img src='images/theantistudio.png' /><br /><br />

     <img src='images/gallery.png' /><br />
        <div style='text-align:center;width:480px;'>
            <div class="wrap1">
                <div class="wrap2">
                    <div class="wrap3">
                        <a href='video/rmerl_particle_fire.flv' rel='shadowbox'><img class='thumb' src='thumbs/thumb_fire.png' /></a>
                    </div>
                </div>
            </div>
            <div class="wrap1">
                <div class="wrap2">
                    <div class="wrap3">
                        <a href='video/rmerl_firework.flv' rel='shadowbox'><img class='thumb' src='thumbs/thumb_firework.png' /></a>
                    </div>
                </div>
            </div>
            <div class="wrap1">
                <div class="wrap2">
                    <div class="wrap3">
                        <a href='video/rmerl_fountain.flv' rel='shadowbox'><img class='thumb' src='thumbs/thumb_fountain.png' /></a>
                    </div>
                </div>
            </div>
        </div>
        <br />
        <div style='text-align:center;width:480px;'>
            <div class="wrap1">
                <div class="wrap2">
                    <div class="wrap3">
                        <a href='video/rmerl_logo.flv' rel='shadowbox'><img class='thumb' src= 'thumbs/thumb_logo.png' /></a>
                    </div>
                </div>
            </div>
            <div class="wrap1">
                <div class="wrap2">
                    <div class="wrap3">  
                        <a href='video/rmerl_rocket_ship.flv' rel='shadowbox'><img class='thumb' src='thumbs/thumb_rocket.png' /></a>
                    </div>
                </div>
            </div>
            <div class="wrap1">
                <div class="wrap2">
                    <div class="wrap3">
                        <a href='video/rmerl_solar_system.flv' rel='shadowbox'><img class='thumb' src='thumbs/thumb_solar_system.png' /></a>
                    </div>
                </div>
            </div>
        </div>
        <br />
        <div style='text-align:center;width:480px;'>
            <div class="wrap1">
                <div class="wrap2">
                    <div class="wrap3">
                        <a href='video/rmerl_space_ship.flv' rel='shadowbox'><img class='thumb' src='thumbs/thumb_space_ship.png' /></a>
                    </div>
                </div>
            </div>
            <div class="wrap1">
                <div class="wrap2">
                    <div class="wrap3">
                        <a href='video/rmerl_still_life.flv' rel='shadowbox'><img class='thumb' src='thumbs/thumb_still_life.png' /></a>
                    </div>
                </div>
            </div>
            <div class="wrap1">
                <div class="wrap2">
                    <div class="wrap3">
                        <a href='video/rmerl_walkthrough.flv' rel='shadowbox'><img class='thumb' src='thumbs/thumb_walkthrough.png' /></a>
                    </div>
                </div>
            </div>
        </div>
    </div></center>
</body>
</html>
From stackoverflow
  • I cannot see your picture, but based on your description it sounds like you're not clearing the floats. You have a br after each block of three images in a div, so adding the following CSS will clear the floats and show three in a row.

    br { clear: both; }
    
    annakata : he could do that on the parent div of .wrap1 - the br is entirely extraneous
    Rich Adams : Very true. There's also no need for the inline styles on the parent div to .wrap1.
  • Also, if there is not enough width on a specified "line", it will drop down to the next line. Try making the window as wide as possible (click n drag) and see if this is the issue.

  • It looks like your second image may be slightly taller than your third. So your floated second line is only floating back until it hits the second image. Either set your image or wrap1 heights, or add style="clear:both" to the break tags between lines.

Tools for programming tutorials?

I engage in lot of training sessions and I would like to create video tutorials of all my sessions so that I can distribute it. What are the best Windows-based tools to add my PowerPoint slides, notes, voice and video (tutorials of code I write) and compile them into one video?

From stackoverflow
  • Camtasia, if you're on Windows.

    Dacto : Got me exactly 1 second before i posted! :)
    David Anderson : +1 for suggesting a really awesome suite!
    Shoban : Thanks! Any free tools?
  • Techsmith Camtasia. Supreme Screen/voice recorder with extensive deployment option (ie. as flash, avi, etc..)

  • We are using Camtasia (http://www.techsmith.com/camtasia.asp) but I've heard that Adobe's Captivate (http://www.adobe.com/products/captivate/) is way better. Both solutions are commercial.

    If you are looking for a free alternative, Camstudio(http://camstudio.org/) is pretty good, although it lacks a lot of features.

    Dacto : it's a shame that captivate doesnt come with CS4 master collection.
    Shoban : Thanks +1 :) Its sad that I cannnot mark two answers as accepted answer
  • CamTasia (TechSmith.com) integrates with PowerPoint, has an excellent editor and is very powerful. If you're spending more than a few hours on screencasts, get CamTasia. It can integrate a webcam too and export SCORM for e-learning.

    CamStudio is gpl, fine for simple screencasts, lacks an editor and has problem with audio/video synchronisation after 10s of minutes of recording (CamTasia has no synch problems)

    HyperCam is a no-frills shareware recorder, similar to CamStudio, no synch bugs, but no editor either. The author is responsive to bugs, I used it a few yrs back, it does fine for basic recordings.

    VirtualDubMod is a gpl video editor, it is clunky but will give you some editing+merging power if you're using CamStudio

    I'd suggest getting a reasonable mic (£40UK on a usb mic should do fine), avoid 3.5mm analogue jack mics as motherboard electrical noise will come through in your recording.

    ShowMeDo.com (disclosure: I'm a co-founder) hosts 800 open-source tutorial screencasts made by >100 open source authors. If you want diverse examples of presenting presentation+programming material, you'll find many examples and a friendly community here.

    I'm a professional screencaster with 4 yrs experience. I've been gathering various articles and interviews (disclosure: some interviews are with me) that should give you further background, they cover open-source tutorials, product demos, how-tos etc:

    blog.procasts.co.uk/2009/01/screencaster-interviews-and-articles/

    David : I would +10 this if I could. Great overview of the existing tools, and thanks for introducing us to ShowMeDo.

asp.net MVC - ValidationSummary not displaying

Hi All

I have a strange problem whereby the ValidationSummary is not being displayed. However, the ValidationMessage's are being displayed. I've checked the output page source and it's not as though they are in a colour that is obscuring them. I'm using the RC. Any ideas?

Edit: Break point set at ValidationSummary shows:

ViewData.ModelState.Values[1].ErrorMessage = ""
ViewData.ModelState.Values[1].Exception.InnerException.Message = "4a is not a valid value for Int32"

Does ValidationSummary use ErrorMessage and ValidationMessage use InnerException.Message?

My view code is:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master"
Inherits="System.Web.Mvc.ViewPage<App.Models.PurchaseOrdersView>" %>


<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <title>Edit</title>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <h2>Edit</h2>

    <%= Html.ValidationSummary() %>

    <% Html.BeginForm("Edit", "PurchaseOrder", FormMethod.Post); %>
    <table>
        <tr>
            <td>
                Purchase Order Id:
            </td>
            <td>
                <%= Html.TextBox("PurchaseOrderId", Model.PurchaseOrderId)%>
                <%= Html.ValidationMessage("PurchaseOrderId")%>
            </td>
        </tr>
        <tr>
            <td>
                Date:
            </td>
            <td>
                <%= Html.TextBox("Date", Model.Date.ToString("dd-MMM-yyyy"))%>
                <%= Html.ValidationMessage("Date")%>
            </td>
        </tr>
    </table>
    <input type="submit" value="Save" />

    <% Html.EndForm(); %>

</asp:Content>
From stackoverflow
  • You don't say what the errors are that are not displaying, but there are some errors which will be displayed in ValidationMessage but not in ValidationSummary. I think that this is a bug in the Release Candidate, but I am open to other interpretations. In particular, consider this line from the ValidationSummary source code:

    string errorText = GetUserErrorMessageOrDefault(modelError, null /* modelState */);
    

    Note that nothing is passed for modelState. Now contrast that with ValidationMessage:

    ... GetUserErrorMessageOrDefault(modelError, modelState) ...
    

    Finally, let's look at GetUserErrorMessageOrDefault:

        private static string GetUserErrorMessageOrDefault(ModelError error, ModelState modelState) {
            if (!String.IsNullOrEmpty(error.ErrorMessage)) {
                return error.ErrorMessage;
            }
            if (modelState == null) {
                return null;
            }
    
            string attemptedValue = (modelState.Value != null) ? modelState.Value.AttemptedValue : null;
            return String.Format(CultureInfo.CurrentCulture, MvcResources.Common_ValueNotValidForProperty, attemptedValue);
        }
    

    What this tells us is that if you specify a custom error message when you add an error to the model state, it will be displayed. If, however, an exception is added (there is one overload for AddModelError which takes an exception, another which takes a string; implementing IDataErrorInfo works like the string case), instead of a string error message, it will only be displayed if modelState is non-null, and then we'll give you a generic message instead of the error message on the exception.

    Update

    Does ValidationSummary use ErrorMessage and ValidationMessage use InnerException.Message?

    Yes, that's more or less the effect. Like I said, I think this is a bug.

    Alan T : Hi Craig: For PurchaseOrderId (integer) and Date (date) I entered strings. I tried with/without custom error messages. I use UpdateModel to get add errors. I'm a n00b and I just about undertand what you're saying. I've updated my question with a bit more info.
    Naz : Hi I also think this is a bug as my validation summary isn't displaying all the errors but my in-line validation messages are. I think this bug was introduced in MVC2 RC2.
  • Try

    <%= Html.ValidationSummary(false) %>
    

rails if object.nil? then magic '' in views?

This is one of those things, that maybe so simple I'll never find it because everyone else already knows it.

I've got objects I have to check for nil in my views so I don't dereference a nil:

<%= if tax_payment.user; tax_payment.user.name; end %>

Or I could do this variant:

<%= tax_payment.user ? tax_payment.user.name : '' %>

So this is ok ... for most languages. But I feel like there must be some bit of shiny ruby or railness I'm still missing if this is the best I can do.

From stackoverflow
  • What about:

    <%= tax_payment.user.name if tax_payment.user %>
    
    Jeremy : I knew it would be a head slapper, thanks.
  • You can also try the new Object.try syntax, pardon the pun.

    This is in the shiny new Rails 2.3:

    tax_payment.try(:user).try(:name)
    
    Jeremy : Cool that is also like what I was looking for, I look forward to that release.
  • For a little more comprehensive solution, you could check out the Introduce Null Object Refactoring. The basic mechanics of this refactoring is that instead of checking for nil in the client code you instead make sure that the provider never produces a nil in the first place, by introducing a context-specific null object and returning that.

    So, return an empty string, an empty array, an empty hash or a special empty customer or empty user or something instead of just nil and then you will never need to check for nil in the first place.

    So, in your case you would have something like

    class NullUser < User
        def name
            return ''
        end
    end
    

    However, in Ruby there is actually another, quite elegant, way of implementing the Introduce Null Object Refactoring: you don't actually need to introduce a Null Object, because nil is already an object! So, you could monkey-patch nil to behave as a NullUser – however, all the usual warnings and pitfalls regarding monkey-patching apply even more strongly in this case, since making nil silently swallow NoMethodErrors or something like that can totally mess up your debugging experience and make it really hard to track down cases where there is a nil that shouldn't be there (as opposed to a nil that serves as a Null Object).

  • I just do

    <%= tax_payment.user.name rescue '' %>
    
  • I do:

    <%= tax_payment.user.name || '' %>
    

    This seems the cleanest and simplest to me.

    Jeremy : You'll get a nil object error when user is nil.
    The Wicked Flea : Good point. I haven't used it that deep. But it also depends on the page logic, the page may never get to that point because a payment requires a user. Etc. So, there are some failsafes to consider BEFORE voting me down.
    Nick : The things about the "failsafes" you mention is that they too sometimes fail.
    The Wicked Flea : Sure. So check the failsafe and the input. Ensure that output is fine that way, or redirect to an error page.
  • The Ruby community has put an incredible amount of attention to automating this idiom. These are the solutions I know of:

    The most well-known is probably the try method in Rails. However, it has received some criticism.

    In any case, I think Ben's solution is perfectly sufficient.

  • Another option, which makes sense occasionally...

    <%= tax_payment.user && tax_payment.user.name %>

    If tax_payment.user returns nil, nil.to_s (an empty string) is printed, which is harmless. If there is a user, it will print the user's name.

What model/pattern should I use for handling multiple data sources?

As part of an ecommerce system I need to design and implement a blackbox of sorts. This needs to accept customers and orders from various internal and external data sources (i.e., web site, extranet, yahoo store, amazon xml feeds, etc.) and insert/update a backend system. The api's to insert/update customer and order data are in place for the web site and working well. Now we need to add the ability to process orders from other data sources.

I've been leaning towards the provider model (one provider for each data source) and using it to standardize data into sql server tables before calling the api's to actually add customers and place orders. Are there other models or patterns that I should consider? Have you dealt with this issue before and how did you solve it? Are there any resources (articles, books, projects, etc) I should look at?

From stackoverflow
  • You may find an ETL (Extract-Transform-Load) tool will make your life easier than trying to solve your problem in code.:

    These are designed specifically for the type of data loading work that you described.

    EDIT

    While I still maintain that an ETL tool will best serve your needs, if you insist on doing it in code, you should think about implementing ETL as a pattern. The reason for this is that ETL is a well established best practice for loading data from various sources. You should take some time to study how ETL is implemented.

    At a basic level, you should have three layers, an extraction layer, a transformation layer, and a loading layer.

    The extraction layer should be responsible for retrieving the data from the source. It should not worry about the shape of the data at this points. To keep the layer clean, you should only implement code that "gets" the data here. Worry about shaping it in the transformation layer.

    The transformation layer should be responsible for taking data extracted from various sources and transforming it to the destination's shape. ETL tools do this very efficiently by treating the data as pipelines. These can be split and parallelized. You probably won't have the time or resources to do this. An alternative may be to load the data into staging tables (a less normalized representation of the data).

    The load layer takes the transformed data (in the above case from the staging tables) and loads them in to the final destination location.

    This sufficiently separates your layers so that you can protect yourself from future change. Keep in mind, however, that you're really just doing what an ETL tool will do for you out of the box.

    Geri Langlois : I've looked at SSIS as I'm in the MSSQL Server environment but found problems with that approach: http://ayende.com/Blog/archive/2007/07/15/SSIS-15-Faults.aspx http://ayende.com/Blog/archive/2008/01/15/SSIS-vs.-CSV.aspx I'm really looking for a code solution although I will consider alternatives.
    Michael Meadows : SSIS and ODI are technology specific. I agree that SSIS suffers from Microsoft's pre-version-3 problem; although it's imperfect, it is useful. Informatica is not technology specific, and it is very good, although expensive. Updated answer to include a starting point for a code solution.
  • As mentioned, ETL is probably the way to go, unless you can standardize the way the orders come in at the front, like EDI or web services.

    Use the ETL tools to transform from the sources (email, FTP files, etc) into a common pipeline in your SQL Server and then have a separate process which processes the pending batches in the pipeline.

Java split() method strips empty strings at the end?

Check out the below program.

public class test {

  /**
   * @param args
   */
  public static void main(String[] args)  {
    try {
      String data = null;
      // TODO Auto-generated method stub
      BufferedReader br = new BufferedReader(new FileReader(new File("D:/sample.txt")));
      while((data=br.readLine())!= null){
        String[] de = data.split(";");
        System.out.println("Length ="+de.length);
      }
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
}

Sample.txt:

1;2;3;4
A;B;;
a;b;c;

Output:

Length =4
Length =2
Length =3

Why second and third output is giving 2 and 3 instead of 4. In sample.txt file, condition for 2nd and 3rd line is should give newline(\n or enter) immediately after giving delimiter for the third field. Can anyone help me how to get length as 4 for 2nd and 3rd line without changing the condition of the sample.txt file and how to print the values of de[2] (showing an arrayindexoutofbound exception)?

From stackoverflow
  • have a look at the docs, here the important quote:

    [...] the array can have any length, and trailing empty strings will be discarded.
    

    If you don't like that, have a look at Fabian's comment. When calling String.split(String), it calls String.split(String, 0) and that discards trailing empty strings (as the docs say it), when calling String.split(String, n) with n < 0 it won't discard anything.

  • You can specify to apply the pattern as often as possible with:

    String[] de = data.split(";", -1);
    

    See the Javadoc for the split method taking two arguments for details.

    raja : Yeah.. I got it.. Its working fine now. Thanks alot..
    Alan Moore : So mark the answer as accepted.

How do I figure out which changeset a label in TFS was applied to?

We're using Team Foundation Server and we are using Labels to create points in our version history where specific versions (either internal or external) were produced.

Right now we were wondering if a particular changeset was done before or after a specific label (and thus included in that version or not), but we must be looking in the wrong place. This information is usually provided in the bug-tracking system but this time this field was left open so we thought we could use TFS to figure it out.

The version history for a file doesn't include labels applied. To find labels, the place I know to look is to use the "Get Specific Version" dialog, set type to Label and use the Label selection dialog to see which labels we've made, but this dialog doesn't tell me the changeset before/after the label was applied.

Is the only way to figure out if a particular change was part of that release or not to create a new workspace, map up the directory with the files to a temporary directory on disk, use the Get Specific Version dialog to extract that release and do a file-diff?

Please tell me how stupid I am and point me in the right direction.

From stackoverflow
  • Have you tried opening Source Control Explorer, File -> Source Control -> Labels -> Find Label? [EDIT: that may have been in a beta version, and I don't have TFS here atm...]

    Also, are you using SideKicks? The Labels SideKick allows you to find a label and see the related changesets.

    Lasse V. Karlsen : If I use the Find Label dialog, which is basically the same one I reach from Get Specific Version, I can see a list of all the files and directories and their associated changeset, but I'd have to scroll through them all and find the maximum one. I'll look at SideKick, thanks!
    Lasse V. Karlsen : SideKicks was exactly what we needed, thanks!
  • A label in TFS does not represent a specific point in time - and a label can actually be edited after the event. See the following posts for more information:

    For this reason, I tend to use Changesets in TFS when recording the point in time for a particular release (in fact we label our binaries and installers with the actual changeset number that they were built from just to make it easier to track). (A changeset does represent a unique point in time for the state of the repository).

    Hope this helps,

    Martin.

    Lasse V. Karlsen : Well, I certainly understand that labels in TFS are not like in SourceSafe, but if I look at a single file's version history, surely the label could be included in that list, even when taking that article by Brian Harry into account? Anyway, SideKicks gave us our answer.