In pursuit of simplicity

The Spirals Algorithm Applet

Interesting. I’ve build few Mathematics Applets 10 years ago. Yet, I can still discover their links on internet. I’ve just found my Spirals Applet being featured at comPADRE – a Physics and Astronomy community site.

Applet is http://www.roussev.org/applets/spiral/spiral.html.

And the Spirals Algorithm is as simple as:

import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;

public class HelloSpirals extends Applet {
   int max = 100;
   int centerPosition = 150;
   double angle = 22 / (double) 128;

   public void paint( Graphics g){
      setBackground(Color.black);
      g.setColor(Color.red);

      for (int i = 0; i < max; i++) {
         int[] coordEnd = getCoordinates(i);
         int[] coordStart = getCoordinates(i - 1);
         g.drawLine(centerPosition + coordStart[0],
                         centerPosition + coordStart[1],
                         centerPosition + coordEnd[0],
                         centerPosition + coordEnd[1]);
      }
   }

   private double getAngle( int inx){
      return (inx - 1) * angle;
   }

   private int[] getCoordinates( int inx){
      double angle = getAngle(inx - 1);
      int x = (int) Math.round(inx * Math.cos(angle));
      int y = (int) Math.round(inx * Math.sin(angle));

      return new int[] { x, y };
   }
}

Canada – Russia 7 : 3

What a game … Reminds me so much of Nagano ‘98 finals Czech against Russia. Go Canada for the gold!

First Git Repository

Just opened my first Git account.

http://github.com/atanasroussev

An interesting project. Looks sexy, feels unix.

Olympic torch came home

Finally had a chance to post the picture of the torch relay. The Olympic fire passed few block from my house. It was such a touching moment.

Vancouver Olympics – World came home

Go Canada!

Go Bulgaria!

Object Oriented Ruby

Remember your first cup of Object Oriented Java? Shape, Triangle, Circle polymorphism?

Here it’s the kewl Ruby equivalent:

class Shape
  def info
    // prints abstract method name and area. Confusing eh?
    puts "#{name} area: #{area}"
  end
end
class Triangle < Shape
  attr_reader :base, :height

  def initialize(base, height)
    super()
    @base = base
    @height = height
  end 

  def area
    return ((base * height).to_f./ 2)
  end

  def name
    return "Triangle"
  end
end
class Square < Shape
  attr_reader :height

  def initialize(height)
    super()
    @height = height
  end 

  def area
    return (height * height).to_f
  end

  def name
    return "Square"
  end
end
class Circle < Shape
  attr_reader :r
  PI = 22.to_f./7
  def initialize(r)
    super()
    @r = r
  end 

  def area
    return (PI * r * r)
  end

  def name
    return "Circle"
  end
end
if __FILE__ == $0
  g = Triangle.new(7, 7)
  g.info

  g = Square.new(7)
  g.info

  g = Circle.new(7)
  g.info
end

Result is:
Triangle area: 24.5
Square area: 49.0
Circle area: 154.0

Google never cease to surprise me. They’ve recorded the ski slopes at Whistler. http://bit.ly/9W7Xra

Go Canada!

Go Bulgaria!

Digging into WebDriver today an interesting question popped up.  How does WebDriver interact with browser?! Only thing I knew that it was using JNI to connect to native DLL’s.
So I decided to attach my Eclipse debugger to WebDriver sources and execute a WebDriver Hello World test. The first thing I noticed was this interesting packet being sent:
{
   "response": "Unable to locate element: {"method":"id","selector":"q"}",
   "context": "{711c552c-4fac-473c-83ce-dc767ff37ff2} ",
   "commandName": "findElement",
   "isError": true
}
Which is nothing else but JSON. This increased even more my curiosity. Well, JSON being used by WebDriver to sent messages to browser, then who is the server and who is the client? What is the protocol? I ended up finding the answer here JsonWireProtocol.
And the FirefoxDriver source class too:
public class FirefoxDriver implements WebDriver ... {
   protected Object executeCommand(Class<RuntimeException> throwOnFailure,
                             Command command) {
      Response response = extension.sendMessageAndWaitForResponse(
                     throwOnFailure, command);
      context = response.getContext();
      response.ifNecessaryThrow(throwOnFailure);
......
So what is actually happening is:
1. When a WebDriver test is being created and executed.
2. This test makes an HTTP call to Firefox (or any browser) using JNI (I am still puzzled here how this exactly works)
2. And the listener (the server) is the actual browser. Quite confusing eh?
3. The listener(the browser) receives the HTTP request from WebDriver and responds back with a JSON HTTP packet.
4. WebDriver digest the response packet and either calls back the command OR fails the execution.

I am constantly experiencing this bug since I got my Vaio for more than 3 years already. Whenever I quickly move images, copy/paste fast enough over the folders (and I am very quick typer), Windows Explorer crashes and ask me to report to Windows. Well, this problem is a know issue for years. 1.3 million people are screaming for help. Odd enough seems Windows 7 is plaged by the same problem?! Anyone at Microsoft paying attention? And what is the purpose of reporting this problem when when it never gets fixed.

Anyhow, being frustrated with the Windows experience I looked for my favorite Ubuntu file manager called Dolphin. After installing KDE I am happy camper with:

  • NON crashing Dolphin
  • More logical folder structure.
  • Bookmarking

Thank you Windows. Next time try better. Meanwhile I am switching to Mac OS.