Thursday, April 7, 2011

Seeing strange behavior on IE6 - I'm clueless

I use the following to implant a script into random websites: (added by webmasters just before /body )

<script type="text/javascript">
var xHost = (("https:" == document.location.protocol) ? "https://" : "http://");
document.write(unescape("%3Cscript src='" + xHost + "domain/script.js.php?u="+encodeURIComponent(window.location.host)+"' type='text/javascript'%3E%3C/script%3E"));
</script>

It is an extension of the way google analytics works. I have it installed on a specific website in which the html above it is not perfectly formed.

It works great on all browsers besides IE6. On IE6 the script never runs. Unless I run fiddler2 in which case it runs perfectly.

Question: How can I make it run on IE6. Any idea why it behaves well when fiddler is in the way and not so well when fiddler isn't?

Notes: I have no control over the web sites that have already integrated this code. When I copied the website page code to my server and run it from there it did run OK.

From stackoverflow
  • Have you tried putting the script tag in the end of the document just before the finishing body element? Usually that's were you put the Google Analytics-code.

    Nir : yes. thats where it is
  • How do you know its not running? Does sticking a simple

    alert('hello!');
    

    in the script tag run?

    what about above/below the other js code?

    Whats "invalid" about the html on the page with problems?

    Nir : I have no control over the script above. it is already attached at a customer site. I don't want to get the customer involved
  • Ah, I see you're using https here. When fiddler gets in the middle of your code when running https, fiddler uses its OWN certificate to talk to your browser. Maybe your copy of IE6 trusts Fiddler's certificate, but for some reason does not trust the certificate of the site you're referencing?

  • It turns out an add on named activationmanager.dll was causing the problem. Its a spyware. (IE6 is on my 5.5 years old boy computer). Thanks for the help!

    Ovesh : select your answer as the accepted answer
    Nir : SO makes me wait 48 hours before selecting my own answer.

jQuery UI put items into other containers

I search a good way to put <li> entrys into other <ul> container. The clue is, that when the <li> element is dropped into it's origin <ul> it should be reverted to it's origin place. I do not want them to be sortable. When it is droppen on an other list, it should be added to that <ul>.

I am using the sortable plugin with the "connectWith:" option, but it does not work how I want.

Do you have some ideas, how it could work? Or whitch plugin is better for that idea.

From stackoverflow
  • You might need to maintain some metadata about original positioning using attrs on your li or the jquery .data() method and then resort the list "manually" when the drop event fires:

    $('.selector').droppable({
       drop: function(event, ui) { ... }
    });
    
  • Couldn't you just use the draggable and droppable utilities instead of the sortable?

Setting a timeout on ifstream in C++?

Hi!

We're trying to read data from 2 usb mice connected to a linux box (this data is used for odometry/localization on a robot). So we need to continuously read from each mouse how much it moved. The problem is that when a mouse is not moving, it doesn't send any data, so the file stream from which we get the data blocks execution and therefore the program can't do the odometry calculations (which involve time measurement for speed).

Is there a way to set a timeout on the input stream (we're using ifstream in C++ and read from /dev/input/mouse), so that we're able to know when the mouse doesn't move, instead of waiting for an event to be received? Or do we need to mess up with threads (arggh...)? Any other suggestions are welcome!

Thanks in advance!

From stackoverflow
  • No, there is no such method. You'll have to wait for an event, or create a custom Timer class and wait for a timeout to repoll, or use threads.

  • What you're looking for would be an asynchronous way to read from ifstream, like socket communication. The only thing that could help would be the readsome function, perhaps it returns if no data is available, but I doubt this helps.

    Using threads would be the best way to handle this.

  • Clearly, the right way to go here is to use blocking calls to retrieve data from both mice. Use threads to synchronize the whole thing. I believe there is a pretty simple way to do that.

    Use one thread for each blocking input call. When receiving data from either one, add a corresponding item in a thread-safe queue. That's all these threads should be used for.

    Use one thread to deal with received data. It will essentially be a blocking call to "pop" the first available item in the queue. Now you can do whatever you want to do when receiving data from one mouse !

  • A common way to read from multiple file descriptors in linux is to use select(). I suggest starting with the manpage. The basic system flow is as follows:

    1) Initialize devices
    2) Obtain list of device file descriptors
    3) Setup the time out
    4) Call select with file descriptors and timeout as parameters - it will block until there is data on one of the file descriptors or the time out is reached
    5) Determine why select returned and act accordingly (i.e. call read() on the file descriptor that has data). You may need to internally buffer the result of read until an entire data gram is obtained.
    6) loop back to 4.

    This can become your programs main loop. If you already have a different main loop you, can run the above without looping, but your will need to insure that the function is called frequently enough such that you do not lose data on the serial ports. You should also insure that your update rate (i.e. 1/timeout) is fast enough for your primary task.

    Select can operate on any file descriptor such network sockets and anything else that exposes an interface through a file descriptor.

    Adam Rosenfield : +1, select() is the way to go since it avoids the headaches caused by multithreading.
  • Take a look at the boost Asio library. This might help you deal with the threading suggested by schnaeder.

How does Google determine to send the Virus page?

When I was a Windows user, I received many times the Virus page in Google. I thought things change in Mac. I received today my first Virus page in Google. I am flabbergasted. The experience raises a question:

How can Google know that there is a virus? How does such a "virus" act? How does it determine to send the Virus page?

From stackoverflow
  • I believe Google shows their "virus page" if either you, or in rare cases your ISP, perform far more queries than normal over a certain period of time. I once wrote a little test app to perform certain keyword searches, and after a few thousand searches (within minutes) I began to receive the message. Luckily it went away after a few days.

  • From the official Google blog:

    We maintain a list of such sites through both manual and automated methods. We work with a non-profit called StopBadware.org to come up with criteria for maintaining this list, and to provide simple processes for webmasters to remove their site from the list.

    Assuming you mean the "This website may harm your computer"-warning.

    Cerebrus : Right... that is an assumption all right, since the OP's "virus page" assertion is far from clear. Good answer, in any case. +1
  • Please note that it's not necessarily a 'virus page'. Google also shows that warning if a site is involved with phishing (a fake PayPal or bank login page, for example). It's merely a warning that the contents of the site may be misleading or dangerous.

    Having a Mac protects you against almost all viruses in the wild today, but you will still receive that message from Google on bad sites - they display it to everyone, even if you can't get infected.

    Masi : I did only a search from Firefox. I did not entered any site. Perhaps, the odd event has something to with the servers of Scroogle.org.
  • Simon's answer is generally right.

    You can get some more information about methods in Google security blog, e.g.: http://googleonlinesecurity.blogspot.com/2008/02/all-your-iframe-are-point-to-us.html

How to split-output sounds to speaker and earphone?

OS: win xp
motherboard: ASUS A8N-E (with sound card built-in)
I have a speaker and an earphone.
When using mp3 player and media player at the same time, all of the sounds will output to all sound output devices(speaker and earphone).

Is it possible to let the mp3 only output in speaker while the media player only output in earphone?

From stackoverflow
  • No, not without a second sound card

  • Which operating system?

    If you're running Windows and your PC has an HDAudio solution, then the speakers and headphones may appear as two separate output devices (it depends - for instance, on my laptop the headphones and speakers appear as the same output device and there's an electrical switch that switches between the two when the headphones are plugged in).

    If the headphones and speakers appear as separate audio devices, then hopefully your media player has configuration options that allow you to select the output device it uses.

    If you're running an AC'97 audio solution (and I suspect you are because your audio solution appears to support hardware loopback), you are likely to be out of luck - it all depends on how the manufacturer of your audio solution wired it up.

    If you're running Windows 7, if you launch the audio Playback controls control panel (mmsys.cpl), select "Properties" for the device the where the MP3 player is plugged in and navigate to the "Listen" tab, you can ask Windows to play the contents of any input onto any output device.

How to solve TPTP Monitor error ( IWAT0435E ) in Eclipse, on Debian-based Linux?

After installing Test & Performance Tools Platform in Eclipse Ganymede on, whenever I tried to profile a Java application, I was confronted by the launch configuration dialogue which contained an error along the lines of:

Error IWAT0435E could not connect to host

How is this problem fixed?

From stackoverflow
  • After searching for a while I found the solution in a couple of blogs, so thanks to Pablo and Shimi. These contain a more detailed background if you're interested.

    The problem related to something called the Agent Controller being linked to an old version of libstdc++. To solve it you can run the following two commands:

    wget mirrors.kernel.org/ubuntu/pool/universe/g/gcc-2.95/libstdc++2.10-glibc2.2_2.95.4-24_i386.deb
    sudo dpkg --install libstdc++2.10-glibc2.2_2.95.4-24_i386.deb
    

    Though your mileage may vary depending on distro version etc.

    You should then be able to profile successfully in Eclipse, I found that I didn't even need to restart Eclipse.

  • Problem: you need to have libstdc++-libc6.2-2.so.3 installed. To solve this problem on openSUSE install package "compat".

  • Use the following if you're using Ubuntu 9.10 Karmic Koala 64 bit

    wget http://mirrors.kernel.org/ubuntu/pool/universe/g/gcc-3.3/libstdc++5_3.3.6-17ubuntu1_amd64.deb
    sudo dpkg -i libstdc++5_3.3.6-17ubuntu1_amd64.deb
    

    Launch eclipse and viola...you're in business :)

    joelpet : Worked fine even on Ubuntu 10.04 Lucid Lynx 64-bit with TPTP-4.6.2 on Eclipse from repositories.

Powershell's Invoke-Expression missing param

I thought that I had the latest CTP of Powershell 2 but when I try the command: invoke-expression –computername Server01 –command 'get-process powershell'

I get an error message: A parameter cannot be found that matches parameter name 'computername'.

So the question is: How can I tell which version of PowerShell I have installed? And what the latest version is?

From stackoverflow
  • $host.version.tostring() will return the version number.

    RTM of v1 is 1.0.0.0

    Couldn't honestly tell you what the latest version of the previews are because I haven't had a chance to play yet.

    HTH

  • Thanks - just ran that and got 2.0

    Just found the CTP and see that it was published on 11/5/2007 so I now know that I have the latest.

    It's a mystery to me why that param is not recognized.

  • The latest CTP is CTP2 released on 05/02/08 and can be found here. Remoting requires WinRM to be installed on both the calling machine and the target machine. Included in the CTP is a script to configure WS-Management called Configure-WSMan.ps1.

    This command should get you the version number of PowerShell that you have installed. Get-Command "$PSHome\powershell.exe" | Format-List FileVersionInfo V1.0 is 6.0.5430.0 CTP2 is 6.1.6585.1

    I don't have the version number for the first CTP on hand, but I can find it if you really need it.

  • I'm guessing that this is a change to the cmdlet made during the configuration process Configure-Wsman.ps1. I don't have an environment setup to test right now, but I'm guessing something went wrong with the configuration. I can verify that on XP the parameter is not available (duh). I'd assume that you will find the same on Vista/08 without the configuration completed.

  • The problem is that from CTP 1 to CTP2, they switched up the Invoke stuff, all the remoting stuff is done through Invoke-Command now, and Invoke-Expression is solely for turning a string into a script ;)

    P.S.: If you're on v2 you can run $PSVersionTable to see a list of versions including the CLR and Build versions.

  • From last night's build (which means you might have this in CTP3 but if not, you'll get it in the next public drop):

    [4120:0]PS> $psversiontable
    Name                           Value
    ----                           -----
    CLRVersion                     2.0.50727.3521
    BuildVersion                   6.1.7047.0
    PSVersion                      2.0
    WSManStackVersion              2.0
    PSCompatibleVersions           {1.0, 2.0}
    SerializationVersion           1.1.0.1
    PSRemotingProtocolVersion      2.0
    

    Experiment! Enjoy! Engage!

    Jeffrey Snover [MSFT] Windows Management Partner Architect

  • If the $PSVersionTable variable doesn't exist, then you are running V1.

    If it exists, then the version will be available as $PSVersionTable.PSVersion.

    function Get-PSVersion {
    if (test-path variable:psversiontable) {$psversiontable.psversion} else {[version]"1.0.0.0"}
    }