Tuesday, June 30, 2009

Install VMWare in Ubuntu

I did this a couple of times already and there seems to be no repository with .debs for Ubuntu as today. So here is how to install it with (some) package and dependency support:

  1. First download from here. Pick the RPM file, in my case it was named like this: VMware-Player-2.5.2-156735.i386.rpm
  2. Convert the RPM to a friendly DEB:
    $ sudo alien VMware-Player-2.5.2-156735.i386.rpm --scripts
    vmware-player_2.5.2-156736_i386.deb generated

  3. Install the DEB. Note I had a few warnings:
    $ sudo dpkg -i vmware-player_2.5.2-156736_i386.deb
    Selecting previously deselected package vmware-player.
    (Reading database ... 276046 files and directories currently installed.)
    Unpacking vmware-player (from vmware-player_2.5.2-156736_i386.deb) ...
    Setting up vmware-player (2.5.2-156736) ...
    Extracting VMware Installer...done.
    Installing VMware Installer 1.0
    Copying files...
    Configuring...
    Installing VMware Player 2.5.2
    Copying files...
    Configuring...
    Installing VMware Player 2.5.2
    Copying files...
    Configuring...

    Traceback (most recent call last):
    File "/tmp/vmis.c32339/install/vmware-installer/python/lib/logging/handlers.py", line 73, in emit
    if self.shouldRollover(record):
    File "/tmp/vmis.c32339/install/vmware-installer/python/lib/logging/handlers.py", line 146, in shouldRollover
    msg = "%s\n" % self.format(record)
    File "/tmp/vmis.c32339/install/vmware-installer/python/lib/logging/__init__.py", line 630, in format
    return fmt.format(record)
    File "/tmp/vmis.c32339/install/vmware-installer/python/lib/logging/__init__.py", line 421, in format
    s = self._fmt % record.__dict__
    UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 62: ordinal not in range(128)
    Installation was successful

I admit I don't know if these errors are critical or not -- let me know if you do. But after installing it this way I am able to use it perfectly (it's been a few days of usage already and I think everything works) .

(The advantage of this method over just downloading a .bin and installing it is that this gets registered in your package manager, and therefore you can uninstall it or cleanly update it later)

Thursday, June 25, 2009

Drawing coordinates from a Twitter feed in Google Maps

A friend of mine is in vacations and he started posting coordinates of the places he was visiting on Twitter. It would be nice to show this path on a map, I thought, and that is what I did in one hour last night.

I used the "write less, do more" Javascript library jQuery, along with jTwitter, a utility on twitter that works as a jQuery plugin, in a mashup with google maps.

You can see the result here. Type in the twitter username of someone that is posting coordinates (strings like "(-23.748504,-65.500402)" will be parsed out from any tweet text), and that's it!



Following is most of the code for this. I added a couple of lines to jTwitter to allow to (a) call a custom function after each tweet is rendered, and (b) call another function when everything is done. Then we do this when pressing the Go! button:

var matches, u = $("input#user").val(), a = [], s = [];
var fitem = function() { // Called on each tweet. "this" is the tweet object
if (matches = this.text.match(/\(-?[0-9]+\.[0-9]+,-?[0-9]+\.[0-9]+\)/g)) {
for (var i=0; i<matches.length; i++) {
a.push(matches[i]);
s.push(this.text);
}
}
};
var fload = function() { // Called when all tweets were read and written to html
draw(a, s);
}
$("#target").jTwitter({ username: u, onitem: fitem, onload: fload });


And this for drawing the coordinates we just parsed:

function draw(coords, texts) {
// All coords are texts -- Map them into GLatLng objects
var points = [];
for (var i=0; i<coords.length; i++) {
var m = coords[i].substr(1, coords[i].length-2).split(",");
points.push(new GLatLng(parseFloat(m[0]), parseFloat(m[1])));
}
// Create a map, and the GPolyLine from the points
var line = new GPolyline(points, "#FF0000", 2.0, 0.8);
var map = new GMap2(document.getElementById("map"));
// Center map and set zoom level to show our points
var bounds = line.getBounds();
var zoom = map.getBoundsZoomLevel(bounds);
if (bounds) map.setCenter(bounds.getCenter(), zoom);
// Render each point as a separate marker (to get a tooltip), and draw the polyline
for(var i=0;i<points.length;i++) {
map.addOverlay(new GMarker(points[i], {
title: texts[i]
}));
}
map.addOverlay(line);

// More mapping stuff
map.addControl(new GMapTypeControl());
map.addControl(new GScaleControl());
map.addControl(new GLargeMapControl());
map.addMapType(G_PHYSICAL_MAP);


It is a toy and with very limited functionality... but it was a nice exercise. I am planning to add features, I think it is a cool idea. I would love to hear if anyone has ideas around this.

Monday, June 22, 2009

Obtain a Yamaha saxophone's birth date, from its serial number

Note to programmers: This is WAY offtopic!

Anyone owning a musical instrument may wonder which is its manufacturing date. I own a saxophone, and sax players over the web seem to be proud of knowing when their instruments were born!

Mine is a Yamaha YTS-25, and as with any Yamaha sax, there is no way to know the manufacturing date given the serial number. They are not sequential. People made some tables of known numbers.... but I found one interesting and suggestion in the web: Just ask customer service for it! So I wrote them (imail1 /at/ yamaha /dot/ com) last Thursday, and got a very kind letter on Monday telling me the month and year it was manufactured.

Now I can say I am happy to play a 16 year old saxophone :) Thanks Yamaha!

Wednesday, June 10, 2009

Badware report! Hacked?

My blog is about the little hacks I do every day. Like wikipedia's definition #5 of the verb hacking:
  • #5. (computing) To accomplish a difficult programming task. He can hack like no one else and make the program work as expected.
Yes, that's my hacking. But today I think I was hacked, sadly with the definition #4 of this term:
  • #4. (slang, computing) To hack into; to gain unauthorized access to a computer system (e.g. website) or network by manipulating code; a crack.
I received an hour ago an email starting like:

Dear site owner or webmaster of (mysite),

We recently discovered that some of your pages can cause users to be infected with malicious software. We have begun showing a warning page to users who visit these pages by clicking a search result on Google.com.

...

In fact, if I do a google search that lists my site, it says below "This site can harm your computer". And if you are brave and click the result, an awful page with a big and red Warning! message stops you explaining my site is going to harm you...
It turned out that somehow, I got injected a couple of script tags in some pages. They were an obfuscated javascript code, starting like this:

FBE38="parseI";FBE38+="n";FBE38+="t";DD6EDCFB9FEE="St";
DD6EDCFB9FEE+="rin";DD6EDCFB9FEE+="g.";DD6EDCFB9FEE+="fro";
DD6EDCFB9FEE+="mC";DD6EDCFB9FEE+="harCode";
function F5304B9279(C5F40D2E4C)
....
Well, a fun hacking (definition #5, for us good hackers) exercise is to decode that. I am not going to post the entire code here. It did some wrapping around parseInt(_,16) and String.fromCharCode to build a kind of evaluator of a piece of javascript code, encoded as a very long hexadecimal string. Then, when evaluated, it inserted an iframe linking to a place hosted in hostsads.cn domain. I don't know what they inserted in my page. It might be invisible, it might be harmful and exploit some browser vulnerability.

Scripts removed, passwords reset, a form filled into google for my site to be reviewed and the warning removed.

But.... Did anyone have the same problem? Do you know what they do exactly with the injected iframe? I could find this problem by googling around -- I would love to hear if anyone have seen it.

Friday, June 5, 2009

NO_PUBKEY? During apt-get update

This happens to me pretty frequently, as I jump over different repositories to get ubuntu packages:

W: GPG error: http://ppa.launchpad.net jaunty Release: The following
signatures couldn't be verified because the public key is not
available: NO_PUBKEY 2836CB0A8AC93F7A
W: You may want to run apt-get update to correct these problems


Note this happens during apt-get update, so running it is not the solution!

Assuming this is a repository you trust on, let us just add this key to your ubuntu so you can download updates from there:

  1. $ gpg --keyserver keyserver.ubuntu.com --recv 2836CB0A8AC93F7A
    gpg: requesting key 8AC93F7A from hkp server keyserver.ubuntu.com
    gpg: key 8AC93F7A: public key "Launchpad Kubuntu Updates" imported
    gpg: Total number processed: 1
    gpg: imported: 1 (RSA: 1)
    (The number 2836CB0A8AC93F7A is the key listed as missing in the error message)

  2. $ gpg --export --armor 2836CB0A8AC93F7A | sudo apt-key add -
    OK
    (Again, replace that value by your key)



Voila. Run apt-get update again and you should be able to receive that repositories' packages.

Update: palo points out you can do the same with just this line:
sudo apt-key adv --recv-key --keyserver keyserver.ubuntu.com 2836CB0A8AC93F7A
And that's even shorter -- thanks!