Pages

Tuesday, 27 November 2012

My Unused Yahoo Account Got Compromised

My unused Yahoo account got compromised yesterday (Sun, Nov 25, 2012 at 2:22 PM). Someone logged in from Vietnam. Or most likely that someone relayed through a server located in Vietnam with the IP address 123.22.191.25. pfft..
I got notified to my another email account that the Yahoo account's password got changed. Well there was two emails, one at 2:22 PM and the other at 2:23 PM. When I entered the password, Yahoo mail asked the security question, but I opted for verification code to be sent to my another email account.
Anyway, I got hold of the account, but who needs a Yahoo account anyway. I just initialized account termination.
Relayed login IP address screenshot | Relayed login Country Info screenshot

Monday, 19 November 2012

Open Links In Background Tab

A snippet to open links in a background tab. The idea is to trigger a mouse click event with control key pressed set as true, to open the clicked link in a background tab.
<!-- html -->
<div>class="bgLink" href="http://www.qlambda.com">qlambda​</div>
<div>class="bgLink" href="http://www.google.com">Google​</div>
//js
window.onload = function () {
    //event listeners
    var a = document.querySelectorAll(".bgLink");
    if (a != null) {
        var len = a.length, i=0;
        if (len > 0) {
            for (i = 0; i < len; i++) {
                a[i].addEventListener("click", openNewBackgroundTab, false);
            }
        }
    }

    // event handlers
    // open links in background tabs
    function openNewBackgroundTab(e){
        var a = document.createElement("a"), evt;
        a.href = this.getAttribute('href');
        evt = document.createEvent("MouseEvents");    
        evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, true, false, false, false, 0, null);
        a.dispatchEvent(evt);
        e.preventDefault();
    }
};
Reference: initMouseEvent
Update: Stopped working with Google Chrome dev release 41.0.2224.0 after 2014-11-20.

Sunday, 18 November 2012

Install Java SDK in Nokia N900

Nokia N900 with Maemo Operating System is one true computer rather than a smartphone or an internet tablet. One of the judging criteria is whether we can develop applications right on the phone. With Nokia N900, we surely can.

Java platform is an amazing environment. We have the JRE with the JVM and the libraries, and of course with Java and a whole bunch of JVM languages like Clojure, Groovy, Scala etc. To develop applications in Java we need the Java Standard Development Kit (JDK) which contains the compiler and the supporting files. The cool thing about Maemo is that we can install JDK compiled for the ARM architecture.

The easiest way is to install the IceTea6 version of the OpenJDK preset at the maemo repository.

To manually install, follow the steps below.
1. Get OpenJDK for ARM. Cambridge Software Labs (link down) provides optimized version of OpenJDK for ARM. Download OpenJDK v1.6.0_0. (Mirror).
2. Copy the archive to /opt directory of the phone. Say you have downloaded or copied the file to MyDocs/tmp, then run the below command to copy it to /opt. We need to be root to preform the following operations. Install rootsh from the maemo-extras repository to get root privilege, if not done already.
cd  #home dir
sudo cp MyDocs/tmp/OpenJDK-camswl.tar.gz /opt  #copy file
3. Extract the archive.
cd /opt
sudo tar zxvf OpenJDK-camswl.tar.gz #extract the archive
sudo rm OpenJDK-camswl.tar.gz #delete the archive
4. Add /opt/OpenJDK-camswl/bin to PATH.
cd /etc
sudo vim profile  #open the file
Add the line to the file after the already present export path statement, save and exit vim (:wq). The file will look like:
# ...
export PATH="/usr/bin:/bin"
#JDK
export PATH=$PATH:/opt/OpenJDK-camswl/bin
# ...
5. Exit and relaunch the terminal.
6. Test the installation by typing in the following commands.
java -version  #prints java version "1.6.0_0"
javac -version  #prints javac 1.6.0_0
javap java.util.Date  #lists all methods in Date class
Happy hacking !

Friday, 9 November 2012

BeanShell: The Java Interpreter (JSR-274)

BeanShell is a pure Java interpreter. BeanShell uses BeanShell Scripting Language which is a Java syntax compatible scripting language for the Java platform (JSR-274). BeanShell supports dynamic execution of the full Java grammar and semantics with transparent access to Java objects and APIs. It also provides additional scripting features which is a strict superset of the Java language syntax.

Setting up BeanShell
1. Download latest BeanShell jar file. The current one is bsh-2.0b4.jar.
2. Place the jar file in a directory say D:\env\javaLibs\.
3. Set CLASSPATH environment variable pointing to BeanShell jar file. It will look like .;D:\env\javaLibs\bsh-2.0b4.jar; under Windows. The . is to look for classes in the current directory. If the variable is already present, append the path at the end separating the paths with a semi-colon.
4. Open command prompt and run java bsh.Interpreter (assuming that JDK or JRE is present in the path).

Now we have a fully working Java interpreter which we can use to quickly prototype ideas. The interpreter is similar to what we see in other dynamic languages like Python or Groovy.

Friday, 2 November 2012

Get HTML5 Canvas Click Co-ordinates

Click co-ordinates for HTML5 canvas element can be obtained using both layerX, layerY property or offsetX, offsetY of the click event.
Firefox does not support offsetX, offsetY so we have to use layerX, layerY amd opera does not support layerX, layerY, so we have to use offsetX, offsetY.
<html>
<head>
    <meta charset="utf-8">
    <script src="script.js"></script>
</head>
<body>
    <canvas id="myCanvas"></canvas>
</body>
</html>
//script.js
window.onload = function () {
    var canvas = document.querySelector('#myCanvas'),
        ctx = canvas.getContext("2d");

    //draw something
    ctx.fillStyle = "#000000";
    ctx.strokeStyle = "#000000";

    ctx.beginPath();
    ctx.rect(100, 100, 300, 100);    //x, y, width, height
    ctx.fill();
    ctx.stroke();
    ctx.closePath();
    
    //listen for click event
    canvas.addEventListener("click", function (e) {
        var cX,    //will contain clicked x co-ordinate
            cY;    //will contain clicked y y co-ordinate
        if (e.offsetX == null) { //in case of Firefox
            cX = e.layerX;
            cY = e.layerY;
        } else { //in case of Opera layerX does not work, use offsetX instead
            cX = e.offsetX;
            cY = e.offsetY;
        }
        console.log("clicked at: " + cX + " " + cY);
    }, true);
}