Sunday, September 30, 2007

Compiz - Debian ; Up and running!

This is just a plain simple way to have Compiz installed on your system ( i use Debian Etch ).

install compiz:

$ sudo apt-get install compiz

now edit the xorg.conf file: /etc/X11/xorg.conf, add the following lines at the bottom
Section "Extensions"
Option "Composite" "Enable"

create a .xinitrc in your home directoy i.e. ~/.xinitrc with following lines:
gnome-terminal &
exec compiz

Now, kill your current X server session by pressing Ctrl-Alt-BackSpace .

login onto a ( virtual ) terminal using your username and password, then just fire the following command:

$ startx

And here you go! All the nice effects of wobble etc. at your desk and a terminal window on your screen.

this is really a light way, without putting too much of memory on useless applications running along with GNOME/KDE.

Whatever you really need to use, just start from the terminal.


Tuesday, September 4, 2007

Ruby - The Programming Language

Here a few links that are good as a first look while learning Ruby.


:symbols in Ruby

writing daemons

more to come...

Finding duplicate files on your system?!

I ( and many others ) have a lot media files ( mp3, jpg, avi, etc. ) lying around in the system. I wondered that how shall I get the list of all the duplicate files lying in my computer. Writing a script in Ruby which identifies the duplicate files using the MD5 hash values of the files contents, was no difficult a task. Here is the script.


## This file finds all the duplicate files form a directory given
## at the command line.
## Released under the GPLv2
## Copyright (C) tuxdna(at)gmail(dot)com

require 'digest/md5'

## novice use of exceptions
throw nil if ARGV.length == 0
print "Usage: ", $0, " \n"
exit 1

directory = ARGV[0]
print "Name of directory given is :", directory, "\n"

## do not proceed if it is not a directory
exit 1 if File.file?(directory)

puts "Getting the list recursively, for all the files and sub-directories."
filelist = Dir[directory+"/**/*"]

puts "Now scanning the files: "
puts "Determining file size and Filtering the directories:"

sizehash = { |h,k| h[k] = [] }
filelist.each do |filename|
if File.file?(filename)

## prune those entries which do not have same size
sizehash.delete_if { |k,v| v.length<=1 }
duplicates_md5 = { |h,k| h[k] = [] }
sizehash.each do | size, files |
files.each do |filename|
md5sum = )
## Necessary to do this because md5sum is an object of class Digest::MD5
## and we need a string for a key!!
md5sum = md5sum.to_s

## prune those entries which do not have same md5 hash value
duplicates_md5.delete_if { |k, v| v.length <= 1 }
## print the files if we find duplicates now!
duplicates_md5.each do |h, files|
puts "Following files match: "
files.each { |f| puts f }
exit 0