Wednesday, March 30, 2011

Live xpath search in your browser

Is there a tool or browser plugin (not sure if Firebug can do this) that will let you open a web page and then using the tool/plugin to search using an xpath query and it will highlight the things on the screen that match your query?

From stackoverflow
  • Firebug offers the $x() convenience function, which dumps the results of an xpath query to the console (where they can be hovered over to highlight). Not quite what you want though.

    And then there's XPather, which does a whole lot more.

    digiarnie : xpather seems to do the trick. I can enter in an xpath and it will show me the matching node/s. thanks!
  • The XPathVisualizer (abbreviated as XPV in this answer) does exactly what is described. There are two separate versions: a version for IE and a version for Mozilla/Firefox.

    One starts the XPV by doubleclicking on its filename (.htm) in Windows explorer.

    Then one chooses an XML file that is dispayed in a very similar way to the IE display of XML files.

    Then one can enter any XPath expression and all selected nodes are highlighted.

    There are additional capabilities, such as defining variables and xsl:key-s that once defined can be referenced within an XPath expression. Namespace prefixes are automatically discovered and bound to the correct namespace-uri.

    XPath expressions that evaluate to atomic values (not nodes) are also displayed as result of any such XPath expression.

    This tool has been used for many years by thousands of people to learn XPath the fun way.

    It comes, of course, with full source code (Javascript + XSLT).

    The XPV for IE can be downloaded here.

    The XPV for Mozilla/Firefox can be downloaded here.

How to disable AJAX-y links before page Javascript ready to handle them?

I am implementing a shopping cart for my website, using a pseudo-AJAX Lightbox-esque effect. (It doesn't actually call the server between requests -- everything is just Prototype magic to update the displayed values.)

There is also semi-graceful fallback behavior for users without Javascript: if they click add to cart they get taken to an (offsite, less-desirable-interaction) cart.

However, a user with Javascript enabled who loads the page and then immediately hits add to cart gets whisked away from the page, too. I'd like to have the Javascript just delay them for a while, then execute the show cart behavior once it is ready. In the alternative, just totally ignoring clicks before the Javascript is ready is probably viable too.

Any suggestions?

From stackoverflow
  • Is your code really that slow that this is an issue? I'd be willing to bet that no one is going to be buying your product that soon after loading the page. In any reasonable case, the user will wait for the page to load before interacting with it, especially for something like a purchase.

    But to answer your original question, you can disable the links in normal code, then reenable them using a document.observe("dom:loaded", function() { ... }) call.

    bendewey : if he disables the links and the user doesn't have javascript enable will his failsafe still work?
    Ben Alpert : Well, depends how you disable them. If you have a short JavaScript snippet that doesn't depend on anything else being loaded, you can run that easily even before the page is completely ready.
    bendewey : Like at the end of the page, because otherwise the elements wouldn't be there yet. right?
  • You can try, hiding the links in css then show them when the page loads.

    <script type="text/javascript">
      document.write('<link rel="stylesheet" type="text/css" href="someCssThatHidesLinks.css" />');
    
      window.onLoad = function() {
        //show links
      }
    
    </script>
    

    This way, if your user doesn't have javascript, then their links are still active, otherwise if they do, then the links are hidden until you load and activate them. Never done this before, but i think this should work if you want to retain the features of your failsafe page.

    strager : Disabling in CSS? How would you do that?
    bobince : Only by making them completely disappear, I think—not a good idea.
    bendewey : don't know what i was thinking
  • However, a user with Javascript enabled who loads the page and then immediately hits add to cart gets whisked away from the page, too.

    When are you starting up your scripts? If you're using document onload, it will be waiting for all the images to download before initialising, which would indeed give the user a chance to click-to-buy.

    If you trigger the JS enhancement when the DOM is ready, either by just putting your <script> at the bottom of the page, or by using a DOMContentLoaded-style event supplied by your framework, the links should adapt fast enough that the user is very unlikely to be clicking the button first.

    If you really, really want to delay clicks that are placed between the element first being parsed, and the document being loaded, you could write something like:

    <script>
        function methodcall(obj, name) {
            return function() {
                obj[name].call(obj);
            };
        }
    </script>
    ...
    <a href="nonjsversion" onclick="setTimeout(methodcall(this, 'click'), 500); return false;">Buy</a>
    ...
    

    So that it'd just spin there polling (and, on IE, leaking memory) until the link's real click handler was in place. It's pretty ugly though, and fragile in that if your script breaks for some reason (and it's JavaScript, so it's pretty likely that at some point, on some browser, it will), your button will break. This problem applies to all potential solutions that rely on a later-running JavaScript enabling previously-disabled actions.

    And there's nothing worse for business than a broken buy button.

  • I now do this with jQuery b/c I vaguely recall browser differences which jQuery takes care of:

    Try

    $(document).ready(function() { // put all your jQuery goodness in here. });

Can you control the speed of a video clip playing in Quartz Composer?

Is there a way to manipulate the speed of the video playback? I'm especially interested in a way to slow down with frame blending, exactly like the function in Final Cut Pro.

From stackoverflow
  • Interpolation should be able to help you. There's an example included with Quartz Composer (Interpolation Modes.qtz) and a beginning tutorial here that breifly mentions it (step 5). this wiki article also discusses it and talks about the different types.

    Note: I don't actually have a Mac that can run QC, so this is just what I've been able to find through Google, but it sounds like it should get you on the right track.

    thescreamingdrills : Thanks, but that wasn't quite what I'm looking for. I did find a clue though, by right clicking on the movie (the Movie Loader), I can change the time base to external. That gives me a "patch time" to edit, and I think the integers indicate frame numbers.
    HitScan : Sorry that wasn't more helpful, but I'm glad to hear it helped you find a clue.
  • Currently it's not possible to do frame-blending using the built-in Movie Loader patch.

    You can arbitrarily control the playback head, though.

    • Insert a Movie Loader patch, and set the Movie Location.
    • Connect it to a Billboard. The movie should play at normal speed.
    • Right-click on the patch, select Timebase, and then select External. This gives the Movie Loader patch a Patch Time input, and freezes it at the first frame.
      • The value you enter for Patch Time is the time offset, in seconds, at which the Movie Loader should render.
    • Insert a Patch Time patch, and connect its output to the Movie Loader's Patch Time input. The movie should again play at normal speed.

    Now comes the fun part:

    • Insert a Mathematical Expression patch and enter t/2 for the equation.
    • Connect the Patch Time patch to the input of the Mathematical Expression, and the output of the Mathematical Expression to the Patch Time input of the Movie Loader patch --- the movie now plays at half speed.

    You can alter the equation to change the playback rate --- t/3 will play at 1/3 speed, t*2 will play at double speed, and so forth.

    However, if you change the playback rate equation while the movie's playing, you'll notice that the playback head jumps to a new position rather than continuing on from the previous time.

    To solve this, you'll want to use the Integrator patch.

    • Create an Integrator, set the Value to 1, and connect the Integrator's output to the Movie Loader's Patch Time input. The movie should play from the beginning at normal speed.
    • Change the Integrator's Value to 0.5. The movie should play at half speed, continuing from the current position.

    You can even play movies backwards using this technique (though, depending on what codec you use, it may severely impact performance).

.NET: ListView blues?

Selection count, .SelectedItems.Count, does not change when the Selected property is set to true on an item in the Items collection of an ListView.

Example:

  lvPept.SelectedItems.Clear()
  lvPept.Items(6).Selected = True
  Dim newLen As Integer = lvPept.SelectedItems.Count

lvPept is a ListView and contains 10 elements.

newLen is expected to be 1, but is 0 when the problem occurs and the SelectedIndexChanged event is not fired. With other datasets it is 1 as expected and the SelectedIndexChanged event is fired.

Under what circumstance or in what state can lvPept be in for this to happen? BeginUpdate()/EndUpdate() is not used with lvPept.

Background:

I am trying to track down a problem one of the users of my open source .NET application, MSQuant (http://msquant.sourceforge.net/), encountered.

I have run out of ideas of what could be the cause of this problem.

The problem is reproducible and I can reproduce it in my development environment, Visual Studio 2008. It seems to be independent of the Windows version (Win2000/WinXP 32 bit/ WinXP 64 bit), the .NET runtime version (2.0/3.5) and Visual Studio version (2005/2008).

Other context: the application is written in VB.NET and in C# and is a WinForms application. The source code for the class in question is at http://shrinkster.com/14bg. The form class that the ListView is in was initially generated by one of earliest official versions of Visual Studio that supported .NET, ca. 2002.

Update 1: as I have both a working case and a broken case I have compared the content of lvPept. The only difference except for properties "Handle", "MousePosition" and "TopItem" (as it is a different protein with different peptides) is property "Created". It was False for the broken case. It makes sense that a partly constructed object can not function properly, but how can it happen?

Update 2: property "Created" being false turned out to be a good lead. I think the real problem was doing this at construction time and not at form load time. I have now added ASSERTs for property "Created", refactored and changed all the operations to happen at form load time. It now works as expected and the user with the problem has got a new version of the application.

The old bad way had been in there since the application's inception in 2002. I am just wondering if some experts could shred light on why it worked 99.9% of the time and only failed in a few cases and reproducably so.

From stackoverflow
  • That's an interesting one.

    The only thing that I think could make this happen is if the ListView didn't realize that the ListItem had changed it's "Selected" value and therefore doesn't update its selected item collections.

    The .SelectedItems property is not necessarily generated each time you get the property - if you reflect the System.Windows.Forms assembly:

        if (this.selectedListViewItemCollection == null)
        {
            this.selectedListViewItemCollection = new SelectedListViewItemCollection(this);
        }
        return this.selectedListViewItemCollection;
    

    So I'm inclined to think that you're getting an out-of-date selectedListViewItemCollection.

    I would try instead of changing the Selected property at the Item level, try instead adding the selected index to the .SelectedIndices property of the ListView and see if that works. That way the ListView isn't relying on picking up a ListViewItem change.

  • I believe you also have to call ListView.Select() in order to fire the SelectedIndexChanged event.

    lvPept.SelectedItems.Clear()
    lvPept.Items(6).Selected = True
    lvPept.Select()
    Dim newLen As Integer = lvPept.SelectedItems.Count
    
    Peter Mortensen : I have now tried to add lsPept.Select(). It did not make any difference.
    scottm : Oops! typo, it was supposed to be lvPept.Select()!

CATIA-CAA CATKeyboardEvent

I know there are only a few CAA Programmers in the world but I try it anyway...

I can't get keyboard events to work. I found this code which looks reasonable but the Notification doesn't fire.

AddAnalyseNotificationCB(CATFrmLayout::GetCurrentLayout()->GetCurrentWindow()->GetViewer(),
      CATKeyboardEvent::ClassName(),
      (CATCommandMethod)&PROTrvTreeView::OnKeyboardEvent, NULL);

void PROTrvTreeView::OnKeyboardEvent(CATCommand * ipCmd, CATNotification * ipEvt, CATCommandClientData iobjData) {
    cout<< "KeyboardEvent" <<endl;
}

Anyone any idea?

From stackoverflow
  • There is a much denser group of developers for CAA at:

    http://www.3ds.com/alliances/c-java-developers/forum/

    The same question came up, with several people mentioning that this API was unauthorized, and therefore you can't rely on it, even if it works.

    The other samples there are essentially the same code as yours, but the only one that purports to work doesn't use CATKeyboardEvent::ClassName, but instead uses "CATKeybdEvent". Might be worth a try.

    Alexander Stolz : I know about that forum and I hate it, its closed(login required) and you never really get an answer in time. I've read the Questions there and they didn't help, I though i could bring some CAA developers here.
  • Did "CATKeybdEvent" work?

    Alexander Stolz : Nope I didn't get it to work
  • try http://www.linkedin.com/groups?about=&gid=142356&trk=anet_ug_grppro

LINQ Join On Between Clause

Hello All,

I am having some issues throwing together a LINQ query that will join a table based on a zip code. I need to join the table based on whether the customer's zip code lies with in a range of zip codes that is determined by ZIPBEG and ZIPEND columns.

The T-SQL would look something like this:

JOIN [ZipCodeTable] [zips] 
    ON [customer].[zipcode] BETWEEN [zips].[ZIPBEG] AND [zips].[ZIPEND]

-- or

JOIN [ZipCodeTable] [zips] 
    ON [zips].[ZIPBEG] <= [customer].[zipcode] 
        AND [zips].[ZIPEND] >= [customer].[zipcode]
From stackoverflow
  • You can't specifically join on this condition, the only kind of join that is offically supported is one based on equality, which your condition in T-SQL doesn't conform to.

    Instead, you will have to perform a cartesian product and then filter on the appropriate conditions:

    from c in customers
    from z in zips
    where
      z.ZipBeg <= c.ZipCode && c.ZipCode <= z.ZipEnd
    select
      c
    

Rendering SSRS reports from VB.Net

We have a lot of reports on the Intranet that take parameters. All reports are going to be re-built in SSRS. Our goal is to pass all the parameters to the report from the .net application. What would be the easiest and the fastes way to render reports from .NET application?

From stackoverflow
  • If you are using VisualStudio 2008, you should be able to add the MicrosoftReportViewer control to your toolbox and add it to your form designer that way.

    If not, you can add a reference to your project to Microsoft.ReportViewer.WinForms (or .WebForms).

    More information is http://msdn.microsoft.com/en-us/library/ms252073(VS.80).aspx under the section marked To add the ReportViewer control to your form