The New Internet Explorer 9 rc

Internet Explorer 9I have been quite busy for the past weeks. However yesterday I found some time to try out the new Internet Explorer 9 rc. I must say I am impressed. I was expecting a browser that was similar to IE 8 where no HTML 5 code really worked and CSS rules were translated to something only will work in IE. However it turns out that Microsoft did its homework.

The first thing I did was to see how my sites looked in IE 9. I was happy with the result. No out of place div’s or unknown CSS to IE 9 rc. And the second thing I did was to test the browser with the standard test ACID3 test.

Continue reading

Fork me on GitHub

Image Capturing from WebCAM using OpenCV and Pygame in Python

I know there a lot of examples of WebCAM image capturing on the net. Mine is one of that but the main difference is that this little script here simply captures frames in a certain fps and simply saves those images. There a numerous usages fro such a thing. One usage could be a script that uploads this image to a certain ftp site so you can display it in your web page. I needed this little script to follow a moving object. I did not write the whole script. You may think this as a little upgrade from the one on the internet. The script uses OpenCV and Pygame libs. Without further ado the script :

import pygame
import Image
from pygame.locals import *
import sys

import opencv
import cv

#this is important for capturing/displaying images
from opencv import highgui

camera = highgui.cvCreateCameraCapture(0)
i=0
def get_image():
    im = highgui.cvQueryFrame(camera)
    # Add the line below if you need it (Ubuntu 8.04+)
    #im = opencv.cvGetMat(im)
    #convert Ipl image to PIL image
    return opencv.adaptors.Ipl2PIL(im)

fps = 25.0
pygame.init()
window = pygame.display.set_mode((640,480))
pygame.display.set_caption("WebCAM Demo")
screen = pygame.display.get_surface()

while True:
    events = pygame.event.get()
    for event in events:
        if event.type == QUIT or event.type == KEYDOWN:
            sys.exit(0)
    im = get_image()
    if i>100:
	#allowing the camera to focus
	#auto focus is really annoying
        im.save("image_"+str(i)+"", "JPEG")
    i=i+1
    pg_img = pygame.image.frombuffer(im.tostring(), im.size, im.mode)

    screen.blit(pg_img, (0,0))
    pygame.display.flip()
    pygame.time.delay(int(1000 * 1.0/fps))

Why mysql_real_escape_string() isn’t enough to stop SQL injection attacks!

We have all been there writing PHP code and trusting mysql_real_escape_string(). Alas it seems it is not enough, let us look at the example below ;

$id = “0; DELETE FROM users”;
$id = mysql_real_escape_string($id); // 0; DELETE FROM users
mysql_query(“SELECT * FROM users WHERE id={$id}”);

As you can see above simply using mysql_real_escape_string is not enough because the new output is in the end “0; Delete from users”.

However don’t fret dear reader because there is a solution! Make sure the $id is indeed only a number! This can be done by simply using the code below;

$id = “123; DELETE FROM users”;
$id = (int) $id; // 123
This way any string elements will simply won’t be added the system. Now a question may arise on how to make sure you don’t get injected with attack if the parameter is in fact a string. My answer is simply : USE THE FRICKEN SQL QUOTES! Like below;
$username = "DELETE FROM users";
$username = mysql_real_escape_string($username);
mysql_query(“SELECT * FROM users WHERE username='{$username}' ”);
The quotes will allow some protection.
I hope this helps you all! And please don’t tell newbies that mysql_real_escape_string() is enough! IT IS NOT!

Getting raw data from a USB mouse in Linux using Python

If you are geek your mouth should be watering by now. I will like to thank Oscar Lindberg and his cool Linux friend for this code! I was trying to get multiple-mice movement data. This is the code that got me started. Once I beautify my multiple-mouse code I will be posting it here as well. Without further ado :

mouse = file('/dev/input/mouse0')
while True:
    status, dx, dy = tuple(ord(c) for c in mouse.read(3))

    def to_signed(n):
        return n - ((0x80 & n) << 1)

    dx = to_signed(dx)
    dy = to_signed(dy)
    print "%#02x %d %d" % (status, dx, dy)

I hope this just made your day!

America – Allen Ginsberg

It really isn’t my views but just like the poem itself. This is read by Allen Ginsberg himself.

America

Allen Ginsberg

America I’ve given you all and now I’m nothing.
America two dollars and twenty-seven cents January 17, 1956.
I can’t stand my own mind.
America when will we end the human war?

Continue reading