Friday, May 6, 2011

Why do my accelerometers respond so slowly?

I'm asking them at 50Hz / 50 times per second for data. When I suddenly flip the device on the x-axis by 90 degrees while the device was flat on a table with display facing up bevore, the values move pretty slowly to the "target" value for that position.

Now the weird thing is: If I increase the measurement-rate, the value will move faster to that new value upon suddenly flipping the device by 90 degrees. But if I just ask once per second for the new value, it take's very long until the value reaches the target. What can be the reason for this?

I don't do any kind of data aggregation, and don't accumulate anything. I just do some simple filtering to get rid of the noise. My method looks like this:

- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {
    // Use a basic low-pass filter to only keep the gravity in the accelerometer values for the X and Y axes
    // accelerationX is an instance variable
    accelerationX = acceleration.x * 0.05 + accelerationX * (1.0 - 0.05);

    // round
    int i = accelerationX * 100;
    float clippedAccelerationValue = i;
    clippedAccelerationValue /= 100;

    [self moveViews:clippedAccelerationValue];
}

later on, in my -moveViews: method, I do this:

-(IBAction)moveSceneForPseudo3D:(float)accelerationValue {
    if(fabs(lastAccelerationValue - accelerationValue) > 0.02) { // some little treshold to prevent flickering when it lays on a table
     float viewAccelerationOffset = accelerationValue * 19 * -1;

     newXPos = initialViewOrigin + viewAccelerationOffset;
     myView.frame = CGRectMake(newXPos, myView.frame.origin.y, myView.frame.size.width, myView.frame.size.height);

     lastAccelerationValue = accelerationValue;
    }
}

As a result, of the device gets turned 90 degrees on the x-achsis, or 180 degrees, the view just moves pretty slowly to it's target position. I don't know if that's because of the physics of the accelerometers, or if it's a bug in my filtering code. I only know that there are fast paced games where the accelerometers are used for steering, so I almost can't imagine that's a hardware problem.

From stackoverflow
  • This line:

    accelerationX = acceleration.x * 0.05 + accelerationX * (1.0 - 0.05);
    

    is a low-pass filter, which works by computing a moving average of the x acceleration. In other words, each time that callback is called, you're only moving the accelerationX by 5% towards the new accelerometer value. That's why it takes many iterations before accelerationX reflects the new orientation.

    What you should do is increase the 0.05 value, to say 0.2. I'd make a global #define and play around with different values along with different refresh rates.

    Thanks : Thanks!! That was exactly the solution to the problem.
    Johannes Rudolph : It should be added that the phase shift created by a RC LowPass filter (which this code implements) is significant. Other implementations of a low pass filter (such as one implemented using FFT) are a little better and that regard. They're much harder to implement though.

What is the best way to 'ping' a database via JDBC?

I'm trying to determine the best way to ping a database via JDBC. By 'best' I mean fast and low overhead. For example, I've considered executing this:

"SELECT 1 FROM DUAL"

but I believe the DUAL table is Oracle-specific, and I need something more generic.

Note that Connection has an isClosed() method, but the javadoc states that this cannot be used to test the validity of the connection.

From stackoverflow
  • Yes, that would be Oracle-only, but there is no generic way to do this in JDBC.

    Most connection pool implementations have a configuration parameter where you can specify the SQL that will be used for ping, thus pushing the responsiblity to figure out how to do it to the user.

    That seems like the best approach unless someone comes up with a little helper tool for this (of course, it precludes using potentially even faster non-SQL-based methods like Oracle's internal ping function)

    Joset : SELECT 1 FROM DUAL works with MySQL also.
  • I may be out to lunch on this one, but could you simply execute some non-sense query, such as:

    SELECT * FROM donkey_giraffe_87
    

    I don't know very much about JDBC's error handling, but perhaps you could check to see if the database is at least telling you that the table does not exist. If JDBC's error codes are vendor-specific, the Spring Framework has some utilities for mapping these codes to more meaningful exceptions.

    Thilo : It could be expensive to try to query a non-exisiting table. Dictionary cache misses and error handling code.
  • I'm not aware of a generic solution, either. For IBM's UDB on iSeries (and perhaps other DB2 systems) it would be

    select 1 from SYSIBM.SYSDUMMY1;
    
  • Simply issuing the following query should be sufficient

    SELECT 1
    
    Thilo : that will not work with Oracle...
    Thilo : ORA-00923: FROM keyword not found where expected
  • Can you not simply execute

    SELECT 1
    

    without a FROM clause against most databases?

    Thilo : Not with Oracle: ORA-00923: FROM keyword not found where expected

Custom dropdown box using javascript ?

Can we write custom dropdown box using javascript,html,css. and also placing backgroung-image for that.

any sample example

From stackoverflow
  • Yes we can!

    Yuval A : Edited the question :)
    AnthonyWJones : +1 Shouldn't up vote really but since I was about to answer the same I guess it would be hypocritical not to ;)
    Chad Grant : I can't :(
  • Yes. Yahoo! managed it, should you want evidence.

  • Yes, and we can too =)

  • Yes you can create a custom dropdown box like element.

    You can use a div for this purpose and set the background-image property for that div.

    You can add ul as menu items. Nut you have to write code for event like mouseclick, mouseover, mouseout, keydown etc

  • yes you can. with css it goes like this.

    add couple of class to your css page, like this:

    .cmdUnbelievable
    {
        width:200px;
        font-family:Trebuchet MS;
        background-color:#0b5925;
        color:#d4d5d4; 
        border:dashed 2px #f2f2f2;
    }
    .cmdUnbelievable option
    {
        color:#f2f2f2;
        border-bottom:solid 0px white;
        border:dashed 2px #f2f2f2;
        margin-left:15px;
    }
    

    then give a class to your select box :

        <select class="cmdUnbelievable">
            <option>We are</option>
            <option>the knights</option>
            <option>who say Ni.</option>
        </select>
    
    scunliffe : @kumar mentions setting a background image... FYI if you try to set one on the option elements it won't work in IE.

Integrated Windows Authentication in FireFox

Hello

If my ASP.NET app is set up for ADFS using Windows Integrated Authentication, I know this will work in IE, but will it work in Firefox?

I've seen some things on the web that indicate that there are problems, and you need to put a workaround in each client browser - http://codebetter.com/blogs/eric.wise/archive/2006/11/16/Note-to-self_3A00_-Firefox-Windows-Authentication.aspx

Thanks Duncan

From stackoverflow
  • It's not a workaround. Firefox will not send your Windows Integrated Credentials to a website by default. You have to tell it to "trust" the website.

    You could display those instructions on a page you direct unauthenticated users to.

    Duncan : Thanks, in retrospect "workaround" wasn't the right terminology - I just meant that each user would have to make changes to their browser.

Filtering solr facet counts

Given the following scenario:

<field name="product_id" type="text" indexed="true" stored="true" multivalued="true"/>
<field name="product_type" type="text" indexed="true" stored="true" multivalued="true"/>

i want to get facet counts for the facet field product_id filtered by specific product_type given a resultset (to get this i use fylter query etc ...)

Note that what i want is to filter facet counts so:

  • Facet query does'nt help due to it introduce a list with the results, of the specific facet queries. (nor filter query does)

    2921

  • Facet.prefix does the kind of filter that i want, but i don't know how to use it in this scenario.

Remark that i want to filter counting off productID that matches specific category

<lst name="facet_fields">
<lst name="productID">
<int name="xHidyhuVZIUVVMfUJM8zd6">209</int>
<int name="34YFQf0F9kqP29SQgrmqI1">206</int>
<int name="m3wp9GS9Iweai0ftKLSlG">195</int>
<int name="aAwN5QFjQLxcrDWFiirjY2">169</int>
<int name="k405yG1RwRndI5T19dMO8">169</int>
</lst>
</lst>

Thx

From stackoverflow
  • As far as I know you can't filter a facet count using another field. facet.prefix only operates on the same field that you're faceting.

    I would issue another query that filters the product type, just to get the facet count you want, something like: select?q=product_type:somecategory&rows=0&facet=true&facet.field=product_id

Google Maps using Marker CLusterer - map hangs !!! Why!

This is weird. I'm using the marker clusterer to bunch all my markers however the first time when the map renders and when I try to drag it or pan it - it hangs and firefox tells me the script is slowing it down so I have to stop the script. But if I zoom it out - it zooms normally and panning it from then on causes no issues - I have no idea whats going wrong here. Here is my code am I missing something here - must be something wrong with my initialisation:

var map = null;

function initializeGMaps() { 



  if (GBrowserIsCompatible())
  {
    map = new GMap2(document.getElementById("map_canvas"));


    {
      var side_bar_html = "";
      var gmarkers = [];
      var htmls = [];
      var i = 0;
     iconBlue = new GIcon();
      // A function to create the marker and set up the event window
      function createMarker(point,name,html) {


     iconBlue.image = 'http://labs.google.com/ridefinder/images/mm_20_yellow.png';
        iconBlue.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';
        iconBlue.iconSize = new GSize(12, 20);
        iconBlue.shadowSize = new GSize(22, 20);
        iconBlue.iconAnchor = new GPoint(6, 20);
        iconBlue.infoWindowAnchor = new GPoint(5, 1);

        var marker = new GMarker(point,{ icon:iconBlue, });
        GEvent.addListener(marker, "click", function() {
          marker.openInfoWindowHtml(html);
        });
        gmarkers[i] = marker;
        htmls[i] = html;
        side_bar_html += '<a href="javascript:myclick(' + i + ')">' + name + '<\/a><br>';
        i++;
        return marker;
      }


      // This function picks up the click and opens the corresponding info window
      function myclick(i) {
        gmarkers[i].openInfoWindowHtml(htmls[i]);
      }


      // create the map
      map = new GMap2(document.getElementById("map_canvas"));
      map.setCenter(new GLatLng( 43.907787, -50.359741), 5);

     var customUI = map.getDefaultUI();
     customUI.controls.maptypecontrol = false;
     customUI.controls.menumaptypecontrol = true; 
     map.setUI(customUI);

      // A function to read the data
      function readMap() {
        var url='get-map-markers.php';
        var request = GXmlHttp.create();
        request.open("GET", url, true);
        request.onreadystatechange = function() {
          if (request.readyState == 4) {
            var xmlDoc = request.responseXML;
            // obtain the array of markers and loop through it
            var markers = xmlDoc.documentElement.getElementsByTagName("marker");

            // hide the info window, otherwise it still stays open where the removed marker used to be
            map.getInfoWindow().hide();

            map.clearOverlays();

            // empty the array
            allmarkers = [];
      //var clusterer = new Clusterer( map );

            for (var i = 0; i < markers.length; i++) {
              // obtain the attribues of each marker
              var lat = parseFloat(markers[i].getAttribute("lat"));
              var lng = parseFloat(markers[i].getAttribute("lng"));
              var point = new GLatLng(lat,lng);
              var html = markers[i].getAttribute("html");
              var label = markers[i].getAttribute("label");
              // create the marker

              var marker = createMarker(point,label,html);
              //map.addOverlay(marker);
        allmarkers.push(marker);
        //clusterer.AddMarker( marker, html );
            }
      var markerCluster = new MarkerClusterer(map, allmarkers);
            // put the assembled side_bar_html contents into the side_bar div


          }
        }
        request.send(null);
      }

      readMap();

    }




  }
}

$(document).ready(function() { initializeGMaps(); } );
$('body').unload( function () { GUnload(); } );


UPDATE: I just noticed that the script at google.com is causing the page to be slow :( how do I fix this? WHat have I done in my code to bring this behavior.

From stackoverflow

Thursday, May 5, 2011

Nested Maven properties evaluated in refering POM rather than defining POM

I'm defining a report configuration in my parent pom which will be run in each child and grandchild project.

Like so:

<reporting>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>findbugs-maven-plugin</artifactId>
            <version>1.2</version>
            <configuration>
                <xmlOutput>true</xmlOutput>
                <threshold>Low</threshold>
                <effort>Min</effort>
                <includeFilterFile>${basedir}/findbugsFilter.xml</includeFilterFile>
            </configuration>
        </plugin>
    </plugins>
</reporting>

The trouble is that each child inserts its basedir rather than the defining POM. I suppose I'm looking for the equivalent to ANT's <property name="name" location="${basedir}"/>. Any ideas?

From stackoverflow
  • Hi,

    I am not sure if this can solve your problem, but I have two ideas that you can try:

    1st idea

    Define a property in the parent pom, and use it in the report configuration:

    <properties>
        <parent-basedir>${basedir}</parent-basedir>
    </properties>
    ...
    <reporting>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>findbugs-maven-plugin</artifactId>
                <version>1.2</version>
                <configuration>
                    <xmlOutput>true</xmlOutput>
                    <threshold>Low</threshold>
                    <effort>Min</effort>
                    <includeFilterFile>${parent-basedir}/findbugsFilter.xml</includeFilterFile>
                </configuration>
            </plugin>
        </plugins>
    </reporting>
    

    2nd idea

    Another idea is to use ${project.parent.basedir}:

    ...
    <includeFilterFile>${project.parent.basedir}/findbugsFilter.xml</includeFilterFile>
    ...
    
    sblundy : I've tried the first. It didn't work either. The second, doesn't work in the grandchild projects.
  • This is related to your other question.

    Have you given up the idea of deploying the filter file in a separate artifact? Why?

    The problem with an absolute path is that you don't have any guarantee that the parent project's sources will be present on the machine when you build a child project. That's the whole point of having a repository mechanism.

    Have you tried my suggestion to your other question?

  • The short version: The solution to your problem is described in the documentation of the findbugs-maven-plugin. You simply have to create a separate (top-level) project for the build configuration that contains your findbugsFilter.xml and reference that project as a dependency.

    The long version: Accessing recources from parent or sibling projects in Maven is a bit complicated unfortunately. The reason for this: When building a child project Maven can't assume that the parent module is one level up or a sibling project is on the same level in the file system. In fact, it can't assume any of these projects are even checked out somewhere! It's perfectly legal to only check out a single child project and build that as is. Thus, when building with Maven everything (with very few exceptions) is loaded from your local repository. And this is why you have to create separate projects for resources you want to use in multiple modules. The separate project can then be added as a dependency and be used by a bunch of different Maven plugins. Examples are: The checkstyle and findbugs plugins to read config files, the maven-dependency-plugin to copy external files into your artifacts or the properties-maven-plugin to load external properties files.

  • I had a similar problem where I wanted the child POM's to have the same properties file as the parent, but I could not get the ${project.parent.basedir} variable to work.

    However what I did was create a variable in the parent, and overwrote the same variable in each of the child Pom's (this should work for grand-poms too... although I didn't have any).

    For example:

    Parent POM:
        <properties>
            <my_basedir>${basedir}</my_basedir>
        </properties>
    
    
    Child POMs:
        <properties>
            <my_basedir>${basedir}/../</my_basedir>
        </properties>
    

    Now I just list the filter once in the parent, and everyone else gets it. If you move the child, you just change the relative path.

       <filters>
           <filter>${my_basedir}/myfile.properties</filter>
       </filters>