Sunday, June 17, 2007

Ubuntu 7.04 (Feisty Fawn) - Initial Impressions

Plenty to explore and talk about but, I think these were the first few things that caught my attention.

1. Disk usage analyzer: A Linux user's conditioned reflex when asked to look up disk usage - du and df. Well stumbled upon 2 new interesting ways to view disk usage (Applications -> Accessories -> Disk Usage Analyzer).



for the graphical usage map (right click on a folder name on the left pane).



2. How interesting can a battery applet get? It's just supposed to show you how much juice is left in your batteries. Well... click on the battery icon. You are greeted with a fair amount of info about your batteries. Then, right click and view the power history. It shows how much power your laptop has been sucking up in watts plotted against time since the system started.



The graph above told me some interesting things about my machine:
  • consumption between an idle CPU and 100% CPU utilization is about 20W!. The >35W on the graph is my CPU on ~100% (Used BOINC to run seti@home jobs to fill up the idle times).
  • And the display takes about 5W between off and full brightness.
3. And then there is Beryl........

Saturday, June 16, 2007

Dual booting Ubuntu (Feisty Fawn) and Windows Vista



Smooth and easy way (obviously apply common sense where ever necessary):
  • Make your Vista recovery disks and take backup of all important files before proceeding.
  • Install Vista first. Don't waste your time trying to partition your system using the utilities provided in Vista - Disk Manager and the Defrag utility. They just don't cut it. I was not able to shrink the Vista partition to my desired 30 Gigs. Wasted quite some time trying to delete/move system files so that a defrag could move them to the beginning of the partition. Instead try GParted (the next step)
  • Boot from the Ubuntu CD. Use GParted (System > Administration > GNOME Partition Editor). Yes, it recognizes NTFS and it did an excellent job resizing my Vista partition. After resizing restart the system and boot into Vista. Make sure to let Checkdisk run during boot. Verify your Vista installation is okay.
  • Boot from the Ubuntu CD again and this time you click on install. When asked for partitioning choose to manually partition your drive. Ubuntu rightly recognizes the service and the Vista partitions and makes suitable entries in the /boot/grub/menu.lst. (I just edited the label for the /dev/sda1 - the service partition). These are the entries in the menu.lst on my system

    # This entry automatically added by the Debian installer for a non-linux OS
    # on /dev/sda2
    title Windows Vista/Longhorn (loader)
    root (hd0,1)
    savedefault
    makeactive
    chainloader +1

    # This entry automatically added by the Debian installer for a non-linux OS
    # on /dev/sda1
    title Lenovo Recovery Partition (loader)
    root (hd0,0)
    savedefault
    makeactive
    chainloader +1

  • Install Ubuntu following the instructions.
  • Reboot - You will automagically see the options to boot into the various partitions during startup. Only caveat the thinkvantage button no longer works during startup. And yes if you choose the Recovery partition to boot it does start the recovery program

Friday, June 15, 2007

A program that prints itself

Update 17th July 2007: Rummaging through my notes I found this - This is a corollary of the Recursion Theorem. This is the way a virus can get a description of itself and print it to a file and do other "wonderfull" stuff to itself like - mutate. Check out this interesting article that talks in detail about the Recursion Theorem - Link

I had been told that any Turing Machine can be made to print itself. Programs are Turing Machines, so they should be able to print themselves. I never actually tried to write such a program myself.

Getting into an argument with some colleagues, I got cornered into defending my statement with a (at the moment) running program or retract my statement. So, with trembling hands, a vague memory of description of such a machine during one of the lectures I attended once and copious amounts of faith in the professor, I gave it a shot. And by golly I got it right ...

Let me lay the ground first.

The program
#include<stdio.h>
main() { printf("Hello, world");}

Prints:
Hello, world
Should print:
#include<stdio.h>
main() { printf("Hello, world");}

To make a program print itself one can attempt:

The program
#include<stdio.h>
main() { printf("#include<stdio.h>\nmain() { printf(\"#include<stdio.h>\n main() { ...\") } ");}

Prints:
#include<stdio.h>
main() { printf("#include<stdio.h>
main() { ...") }

Should Print:
#include<stdio.h>
main() { printf("#include<stdio.h>\nmain() { printf(\"#include<stdio.h>\n main() { ...\") } ");}

So, one gets into a mirror reflecting a mirror kind of a situation.

A program to print its own description:
#include<stdio.h>
main(){ char *str="printf(\"#include<stdio.h>%cmain\(){char *str=%c%str%c; \",10,str,34,34); printf(\"%s\",str); printf(\"}\");"; printf("#include<stdio.h>%cmain\(){char *str=%c%str%c; ",10,34,str,34); printf("%s",str); printf("}"); }

Prints:
#include<stdio.h>
main(){char *str="printf("#include<stdio.h>%cmain(){char *str=%c%str%c; ",10,str,34,34); printf("%s",str); printf("}");tr"; printf("#include<stdio.h>%cmain(){char *str=%c%str%c; ",10,str,34,34); printf("%s",str); printf("}");}

The general idea is like this:

[PartXBegin] = main() { char *str=[PartY];
[PartY] = <Print [PartXBegin]> <Print str> <Print [PartXEnd]>
[PartXEnd] = }

Any program can print a description of itself (obviously,only if it can at least perform the basic turing operations).