Saturday, September 12, 2009

How I became Great (On DC++).

5 comments
Well, If you study in my college you'll know that our LAN is as important an commodity as water or air in our lives. Consequently is DC++.

Well, the status of a person is, to a great extent, determined by what his share size is on the DC hubs (some DC gods have over 1.5 Tb's.). Another criterion is how high the person's rank is on the Anagrams Hall of Fame (HoF).

Well, one night ( 5 days before my 1st In-Sem exams ) I had this strong desire to play Anagrams on the NightHalters Hub. So I tried. And after one hour was depressed enough to outsource the work onto my brain-extension. My computer, that is. So I wrote this cute little anagram solver.

First I got a huge english word dictionary - if you use a debian system, the command

sudo apt-get install wamerican-huge

downloads and places a huge (6.4 MB, 6,38,669 words) text file at /usr/share/dict called american-english-huge.
It contains almost every single word commonly/uncommonly used, including vulgar slang (yeah, i searched). It also contains my name!

Now, the original dumb brute-force approach - comparing each permutation with all the crazy words in a dictionary - would be O(n!), but really, even a third-grade third grader would be smart enough to figure out a better method. So I did this - just calculated the hash of every string in my dictionary using a certain hash array of length 26 ( the number of english alphabets ). I also did not use any modular arithmetic - to reduce hash collisions, of course, and also because memory was not exactly a scarcity ( so i could afford having huge hashes) in a case such a simple english dictionary.

Why use a hash ?
Because every permutation of a string will have the same index-independent hash.

For example, consider the two words, tastier and artiste. They are both permutations of each other. They are also permutations of the jumbled input aeittsr.

Suppose the hash I select is :
a = 1
e = 3
i = 5
t = 9
s = 17
r = 23
(In reality the values should be much bigger odd numbers for best results - shake well before consumption.)

Then, the index-independent hash of aeittsr (the input string) is 1+3+5+9+9+17+23 = 67.
Call this h(aeittsr) = 67.
And since in this particular method of calculating hashes uses a commutative operation ( Addition on integers ), we have :
h(artistes) = 67
h(tastier) = 67
Therefore, we saw that given an input string, we just have to calculate the hash and compare it with the (precomputed) hashes of other dictionary strings.

Now note that the choice of the hash key is important. I used really large hash values for every character - this minimizes the number of hash collisions, greatly improving the search time - at the expense of more memory used. But as I said, hard disk space is not really scarce for an english dictionary.

Also, for generating the hash-table, I organised the words into files that contained words of the same size. In these files, I printed the words and their hashes beside them, one word-hash pair on every line.

Now the realtime heavy stuff was complete.

So now the unjumbler works as follows : the hash and length of the input is calculated. Now the program dives directly into the file which contains words of that size. After this, it does a linear search for the hash and only if a match is found, checks if the string beside the hash is a permutation of the input ( The function for that is quite easy ), and if it is, it gets printed to the console.

And the result of this was that after 3 hours of playing Anagrams (with the aid of my brain extension), I was the #1 guy in the HoF!!!

Well, the code is here.
Have fun!

Read more...

Saturday, July 4, 2009

My Experience with Dropbox on Ubuntu 9.04

3 comments
Well. Since I have yet to receive my UbuntuOne invitation, i decided to have a look at Dropbox. Dropbox is an online Storage space where you can sync your files with your computers. It allows for seamless integration with your online storage space and your native file manager. Though Currently only nautilus is supported for linux, it has command-line support and stuff, so custom extensions for your favourite file manager can be made, such a dolphin plugin.

The default, free plan gives you 2 GB of storage space, and the non-free(as in beer) plans give 50 and 100 Gigs. Oh, by the way, if you are reading this, please sign up on dropbox using the link I have provided above.... I get 250 MB more for every user that signs up through this link yay!

Well, I downloaded the .deb for jaunty and installed it. Upon the first run, It said it would download a "proprietary daemon" to handle all the syncing. Proprietary. Well, i thought, what the hell, and clicked OK.
It then showed a progressbar indicating the download. I'm estimating the size to be around 20 MB.
Anyway, It then showed me a dialog for signing up. I filled in my details and then finished.

The daemon then placed an icon in my tray :


It works wonderfully. Clicking on the icon opens the new $HOME/dropbox directory. The daemon will download a few files and photos for the user to play with. The photos are placed in the dropbox/photos folder. And there is another folder : public. Any file you drop/copy to this folder will be uploaded to your online storage.


And the best part - you can right-click on any file in the public folder and select "copy public link". This gives a read-for-all link that you can share with others!!! And no, it does NOT redirect to some premium download crap page. It is a direct, clean link.

As an example, this is the link to Katkit

I'm looking forward to having fun with this!!!
Read more...

Monday, June 29, 2009

Installing Arch Linux on my Acer Aspire 4530

0 comments
Awww.
This is the hardiest distro i've ever used, after so much distro-hopping. Even slackware was... well... easier...?

I decided to completely remove the existing system (kubuntu, which sucked big time), to make way for Arch.

So this is what i did :

1. I downloaded the 357~MB iso, which contained the core packages ( kernel, package manager, and some other little things ... obviously no X ).

2. I looked around for a CD... but couldnt find one. I didnt have a USB drive lying around either. So i burnt it to a precious expensive DVD. :P

3. Upon inserting the CD, i was greeted by a nice cheesy-looking grub screen. Oh, and one of the grub options was.... guess what? A SPACE INVADERS game!

4. I chose the Core install. Then I was sent back to the main menu. Then I chose the usual options like Clock settings and stuff.

5. Then I got the main menu with ... well, have a look :



I chose prepare hard-drive and told it to format the entire disk... what the hell, i had taken backups... didnt matter.

I gave a 32 megs size to the /boot partition, 15 gigs to /, and the rest to /home.... lol my HDD is 160 gigs...:P

Then i was told to select packages from the disc. I chose all, including the devel packs.
And then, well... i installed 'em. What else?

6. Then i was asked if i wished to change settings. Well, this is not a next-door distro, so dont skip this step. You HAVE to change the default settings. And no, arch wont hold your hand. So this is all I did... I just added eth0 (dhcp) in the interfaces section of the /etc/rc.conf file.In arch linux, this file is the mecca of system settings.
Thus, I effectively told my system to request an IP address at the eth0 interface at startup using
dhcpcd eth0

7. I didnt have to change things anymore. So I rebooted and lo! My ethernet was working. So i first did pacman -Syu to update my system. This is always a good idea in any distro, since you get the latest kernel this way, and if you update later, it would always be a pain in the ass to persuade old kernel modules to love the new kernel.

More next time!! C ya.
Read more...

Sunday, June 21, 2009

svn-compiled Kaffeine for KDE4

0 comments
This one has been my favourite video player ever since I started actively using linux as my main system. I've been missing it ever since KDE4 came out. So I decided I should give svn a shot.

I got it from "svn://anonsvn.kde.org/home/kde/trunk/extragear/multimedia".

You need the parent directory "multimedia" to build it. Since you only want to test kaffeine, you can use the following commands to download the least possible:

svn co -N svn://anonsvn.kde.org/home/kde/trunk/extragear/multimedia
cd multimedia
svn up kaffeine

and build from the multimedia directory.

Well, the code is nicely written and easy to understand. But I did not see much on-the-surface difference from the KDE version, except for the obvious switch to phonon.

On the first view, it looks very much like the old kaffeine. There aren't many new features, it seems. Looks like just a port from old to new.



The video playing view looks like this :



which looks simple with no frills, but with many features packed inside.

Below is a shot of the playlist section :



It aint bad... the lower left frame is a kde file chooser, the upper left shows a list of playlist (note that I couldn't find any obvious way to rename the playlist...). The upper right listview shows the files in the selected playlist, and the lower right is a video player widget showing the currently playing video.

As I said, its just a port. Not much new.
One thing that's badly needed is software sound amplification...

And, of course, some eye-candy in accordance with the KDE4 style !!!
Read more...

Wednesday, June 10, 2009

Gooey stuff

2 comments
Well, since most of the core work is done, i thought i would give some effort to the GUI. In the First screenshot, the toolbar's default actions have been limited to four, and each is separated from the others by category. By the way, note the word "default". There's more you can add to this toolbar, all you have to do is create a QList of QActions and read these actions from a config file created specially for plugins. These new actions will be appended after the last separator.

The icon theme is oxygen, of course, except for the main application icon, which i use as the mainwindow's icon and the tray icon. It has been borrowed from ... well... i cant remember. Will change it to a more original icon. But thats for later.
Note that the multicast and send buttons get highlighted only if someone is on the wire. Which is why they are grayed out in the snap.



This is a snap of the first tab of the settings dialog. Next to the group label is an editable combobox, so in case you want to make a new group, you can just write it in the field.

Status hasn't been implemented yet, which is obvious from the snap, but in a few days everything should be finished.

Also, I might consider using a list view widget instead of the tabbed style, along the KDE lines... each element in the list view should have a 32*32 or 64*64 icon with a bold text like "Appearance"
below it.

And talking of some non-gooey stuff, im thinking of launching the file receive dialogs in separate processes... I already have ideas on how to implement it... :P looks like this will be in beta stage for a long, long time...

By the way, MVC programming sure is fun... yo.
Read more...

Tuesday, June 9, 2009

KatKit 1.0 alpha (as of now)

1 comments
Well i should say most of the required functionality is there, file transfer, text message sending all works though there are some minor crashes ( though far lesser than in qommunicate 1.0, due to some hacks i did to nikhil's code).
The GUI is still very immature and clumsy, so now that will be a bigger priority. I'll create some custom widgets to pimp up my qt learning experience.

TODO:
1. Beautify things.
2. Use a few custom widgets (just for experience).
3. Hack up the code a bit more to clear out the crashes. Adding qdebug() lines everywhere now should be a big help.
4. Plugins!!! Possible ways to implement them would include reading a plugin database file and registering them with the main application. The plugin maker person should include his/her own little program to configure his plugin. Though how to implement it, im not sure... that reminds me... i'm still IRC-starved!!! no help at all!!
4. Try for some more modularity... but then it would become too abstract for my liking...
5. Implement separate processes for separate tasks... like launch file transfers by passing params to a special file transfer program - or maybe let it be done by a plugin!!! NOTE: avoid race conditions!!!
6. Try making a KDE plasmoid for this program. I've intentionally kept the name of this program KatKit ( starts with a K ) so that maybe someday i can make a version of it using KDE libraries!!!
Read more...

IRC Blocked? what the hell ?!!?

0 comments
Yo.
I was working on KatKit, and needed some help regarding how to implement my much-desired plugin system. So I fired up my new IRC client, and awww hell... the connection timeouted. The same problem happened with other channels... eg #kubuntu . So i changed the port to a different value, and got the same problem.

Finally i decided to complain.
This was what i wrote to the sysadmin :

Dear Sysadmin,
It seems as if the IRC protocol chat (Internet Relay Chat) has been
blocked in the university campus. This is extremely restricting and
inconvenient as most programmers/developers communicate to each other
via IRC chatrooms. This has greatly slowed down my work on a particular
software project I am doing. I have to rely on some websites' forums and
email for help and guidance from other developers and this is a very
slow process as replies can be delayed by hours and days. Even changing
the port number from 6667 to some other value does not work. It is NOT
something like yahoo messenger or gtalk, so I see no reason for it to be
blocked.

Thus, I request that you take the necessary steps to remove this
unnecessary nuisance quickly, so that my work can be done faster.
Please reply to this mail ASAP

Yours Sincerely,
Aditya Bhatt (B.Tech 2008)


It pretty much says it all about my frustration... XD
No wonder sysadmins are the most hated folk on all acad campuses..^_^ All they seem to do is block stuff...
Read more...