Archive for July, 2011

Canvas in HTML 5

Posted: July 31, 2011 in Fun Stuff
Tags:

The HTML5 specification has been out for quite some time. Recently in this year, major browsers such as Firefox 4+, Internet Explorer 9 and Google Chrome has added support for the new HTML5 specification. For the novice end-users like most of us, we have not felt any difference with the new browsers. One reason is that it takes time for the web sites to make use of the newly introduced features in HTML5.

One of the new feature is the canvas element. It supports for dynamic, scriptable 2D drawing onto the web page itself. The canvas element also boasts hardware-acceleration – using your graphics card to help make the 2D rendering smoother and faster.

Enough for the introduction, here are some demos using the canvas element. These demos are different than those of Adobe Flash or Java Applets that we are used to during those days behind. Your browser supports the canvas natively without any plugins installed. That’s the greatness of HTML5!

End note: There are already many javascript-based game engines being actively developed. These game engines utilize the capabilities of current browsers, for instance, the canvas element, css3, AJAX, etc. Here is one of my favorite introduction of the Aves game engine.

Advertisements

Everything can be hacked, except for perhaps, this!

It is about the unidirectional networks. According to Wikipedia:

A unidirectional network (also referred to as a unidirectional security gateway or data diode) is a network appliance or device allowing data to travel only in one direction, used in guaranteeing information security.

Here’s a video from the manufacturer explaining it all.

Optimize Your PC and Save a Tree!

Posted: July 12, 2011 in Fun Stuff
Tags:

Have you ever wondered how much energy your computer consumes?

  • A typical desktop computer consumes around 65-250 watts.
  • The attached monitor adds another 80 watts surplus if you use an old-school 17″ CRT; but significantly less (15-70 watts) if you are using an LCD monitor.
  • A notebook seldom consumes more that 60 watts.
  • Don’t overlook your wireless router because it’s going to cost you 10-15 watts.
  • During standby, most devices use around 1-6 watts. However, there is this ‘One Watt Initiative’ that aims to cap device’s power usage at 1 watt when in standby mode.

Recently I started using Granola – a free power management software. The company that develops it, Miserware, claims that the software brings about 35% reduction in CPU power consumption without sacrificing performance. Personally, I like to use it to extend my laptop’s battery life and I would recommend this software to every PC users. The official website is grano.la. Granola

Here is fast method to compute the inverse of the square root of a number, implemented in the famous Quake3 engine.

float InvSqrt(float x)
{
    float xhalf = 0.5f * x;
    int i = *(int*)&x;
    i = 0x5f3759df - (i >> 1);
    x = *(float*)&i;
    x = x * (1.5f - xhalf * x * x);
    return x;
}

What’s behind it? Newton-Raphson method and bitwise manipulation of floating point numbers. Here goes a little explanation.

Back then, floating-point computation was a resource-intensive operation. However, with graphics cards that peaks at the TFLOPS level, computational power has increased by orders of magnitude, and you will rarely need or find this kind of tricks nowadays.

Image-to-text Converter

Posted: July 4, 2011 in Fun Stuff
Tags:

I had been using lynx to browse the web from the linux console and I was searching for a tool that would display image on the terminal.

Instead of getting what I need initially, I found a really interesting site. The site is TEXT-IMAGE.com and it allows you to convert an image into colorful text.

The picture below shows a capture of my result. Try it out!

I’ve kept a Ubuntu Server installed on my laptop for almost a year. Only until recently that I have tried to connect the server through the wireless networking card. Indeed, I’ve been through some hard times, searching and trying desperately to get the wireless card to work. The server doesn’t have a desktop manager, i.e no GUI, so everything has to be done in the terminal. So here I am to explain the whole process to ease others who would also wish to configure their networks using the command line.

  1. The first step is to check that you have the appropriate tools installed. In the command line, type in the following.
    sudo apt-get install wireless-tools

    This will install the Wireless Tool package containing the following tools:
    iwconfig
    iwlist
    iwspy
    iwpriv
    ifrename

  2. Next find out the chipset of your wireless card. To do this, type in
    lspci | grep Network

    or

    lsusb | grep Network

    depending on whether you use a pci or usb card. The output will be like

    02:00.0 Network controller: Broadcom Corporation BCM4312 802.11b/g (rev 01)
  3. Now you know your chipset. Some wireless chipsets work out of the box. In my case, it’s a Broadcom chipset and it’s not supported by default. For this step try google for the appropriate drivers, or you may use ndiswrapper if your Wifi card comes with a Windows driver.
  4. After installing the driver, make sure the card can be detected.
    iwconfig

    The command will list your wireless card. For example:

    lo        no wireless extensions.
    
    eth0      no wireless extensions.
    
    eth1      unassociated  ESSID:off/any
              Mode:Managed  Channel=0  Access Point: 00:00:00:00:00:00
              Bit Rate=0 kb/s   Tx-Power:off
              Retry:on   RTS thr:off   Fragment thr:off
              Power Management:off
              Link Quality:0  Signal level:0  Noise level:0
              Rx invalid nwid:0  Rx invalid crypt:0  Rx invalid frag:0
              Tx excessive retries:0  Invalid misc:0   Missed beacon:0
    
    virbr0    no wireless extensions.
    
    pan0      no wireless extensions.

    Sometimes, the wireless card is disabled so you get “no wireless extensions” for every device.
    You can activate your card by typing

    sudo ifconfig eth1 up

    Then re-execute iwconfig to make sure it is okay.

  5. Issue the following command to scan for wireless network.
    sudo iwlist eth1 scan

    and the output:

    eth1      Scan completed :
              Cell 01 - Address: 00:22:6B:6A:3E:85
                        ESSID:"FKMWifi"
                        Mode:Managed
                        Frequency:2.437 GHz (Channel 6)
                        Quality:5/5  Signal level:-50 dBm  Noise level:-90 dBm
                        Encryption key:off
                        Bit Rates:1 Mb/s; 2 Mb/s; 5.5 Mb/s; 11 Mb/s; 18 Mb/s
                                  24 Mb/s; 36 Mb/s; 54 Mb/s; 6 Mb/s; 9 Mb/s
                                  12 Mb/s; 48 Mb/s
  6. Connect to the access point of your own choice. The ESSID is the identification name given to an access point. Identify the ESSID you wish to connect.
    sudo iwconfig eth1 essid "FKMWifi"
    sudo iwconfig eth1 mode managed
    sudo iwconfig eth1 commit
  7. For WEP or WPA encrypted network, you need to input the key. For WEP encrypted networks, the following two commands applies. Use the first command if you have an ASCII key and it will translate the key to its hexadecimal form.
    sudo iwconfig eth1 key s:password
    sudo iwconfig eth1 key 70617373776f7264

    For WPA encrypted network, you have to generate the WPA-PSK key using the essid and your password.

    wpa_passphrase <your_essid> <your_ascii_key>

    And the output will be something like

    network={
    	ssid="FKMWifi"
    	#psk="secretpass"
    	psk=b51f838d5e7ea198d2dc141350687f6ea7b1995215c9b40b302dc6ca96c94537
    }

    Notice the last line of hex gibberish. Use that as your WPA-PSK key and issue the command

    sudo iwconfig eth1 key b51f838d5e7ea198d2dc141350687f6ea7b1995215c9b40b302dc6ca96c94537
  8. Obtain an IP address from the DHCP server by issuing the command
    sudo dhclient eth1

    The output similar to the below will be printed.

    Listening on LPF/eth1/00:21:00:b7:db:2d
    Sending on   LPF/eth1/00:21:00:b7:db:2d
    Sending on   Socket/fallback
    DHCPREQUEST of 172.16.4.19 on eth1 to 255.255.255.255 port 67
    DHCPACK of 172.16.4.19 from 172.16.0.1
    bound to 172.16.4.19 -- renewal in 240 seconds.
  9. Ping an publicly known address to check that everything works.
    ping www.google.com
  10. Additionally, you might want to save the hassle by configuring your network to connect automatically once your computer starts. Modify /etc/network/interfaces by adding the following lines.
    sudo vim /etc/network/interfaces

    For WEP encrypted network:

    auto wlan0
    iface wlan0 inet dhcp
    wireless-essid   <your_essid>
    wireless-key     <your_password>

    For WPA encrypted network:

    auto wlan0
    iface wlan0 inet dhcp
    wpa-ssid <your_essid>
    wpa-psk <your_wpa_psk_key>

Other resources:
WifiDocs – Ubuntu Official Documentation
Configuring encrypted wireless network