Harsh J

Memoirs of a QWERTY Keyboard

Archive for the ‘Programming’ tag

Scratching my itch

2 comments

If you like open source software, you end up doing that someday sooner or later – you scratch your itch and make a contribution. That’s how it rolls. Well unless you’re sponsored to do so, of course.

I did the same for KDE, having had an on/off relationship with it since 3.x, and finally settling onto 4.3, I managed to get into writing code for it. Although not a fan of the entire desktop, it is what I use on a daily basis and I do feel the lack of a few things sometimes. There’s already too much to customize; and am sure I don’t know the half of it yet.

I read a lot of comic books in my free time, on the PC. While I do have my collections named and arranged neatly, it has always been hard finding a particular file since there were no previews of its covers on KDE 4. Since Okular, KDE’s magnificent all-in-one document reader, reads the files (.cbr, .cbz type) why not also preview it. That became my itch, my want. And I scratched it with copious amounts of help provided by its development community. However, I’d be glad if some artist came along and gave the format an Oxygen-style icon as well – since it still lacks one.

In KDE 4.4, you will have comic book previews which would show you the comic book covers in its file manager’s preview mode. This should make your life easier. However, for .cbr thumbnails to work, you’d need the non-free version of unrar cause the free ones don’t do version 3+ files well. It isn’t a hard dependency, and .cbz ZIP files would work just fine without unrar. I’d also written support for .cbt, but it’d have to wait until KDE 4.5 cause of their ‘feature freeze’.

Since I made it this far, I also fixed certain minor annoyances – some reported by other people as well. A small list:

I’ll be more than glad to hammer more bugs, once the feature freeze melts. Go here to read about what’s new in KDE 4.4.

Written by Harsh

December 8th, 2009 at 12:04 am

Randomize: Some Programming Quotes

4 comments

Scripts vs. Programs

Couldn’t be put more simpler than this.

A script is what you give the actors. A program is what you give the audience.
– Larry Wall, the creator of Perl

So, do you know what programs written in scripting languages really are? :P

Recurring Recursions

You’re on Step 2, which asks you to do Step 1?

In order to understand recursion, one must first understand recursion.
– Unknown, multiple sources

Stack overflow.

Smart Debugging

Damn!

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
– Brian W. Kernighan, the K in K&R C Book and AWK

Where would you draw the line?

Deficit Obviousness

There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies and the other way is to make it so complicated that there are no obvious deficiencies.
– C.A.R. Hoare, the inventor of Quicksort

Obviously no deficiencies in understanding which way to choose.

Add your favorites in the comments, if you wish to.

Written by Harsh

November 6th, 2009 at 10:55 pm

Posted in Fun

Tagged with , ,

Sorting entries in a QStringList Case-insensitively

4 comments

This post is simply a snippet-post for the users of Nokia’s Qt C++ cross-platform toolkit.

While writing some C++ code (after 2 long years since I last wrote them for academic reasons), I had this simple issue of sorting a QStringList in a case-insensitive manner. Normally, there exists a QStringList::sort() function that does the sorting of the strings stored in it in a case-sensitive manner, and is very fast at it. But Qt does not provide a way to perform the sort in a non case-sensitive manner, although it has hints on how to in the class’ documentation.

Being mostly a PyQt/PySide user who uses inbuilt Python lists to do all list-work, here’s how its apparently done in Qt/C++, using a QtCore class called QMap:

#include <QtCore/QStringList>
#include <QtCore/QMap>

void sortNonCaseSensitive( QStringList &sList ) {
    ///  Sorts the passed sList non-case-sensitively.
    ///  (Preserves the cases! Just doesn't use them
    ///  while sorting.)
    QMap<QString, QString> strMap;
    foreach ( QString str, sList ) {
        strMap.insert( str.toLower(), str );
    }
    sList = strMap.values();
}

That’s it.

Written by Harsh

October 24th, 2009 at 10:54 pm

Color Hot-Tracking in Smooth Tasks Plasmoid

3 comments

Polishing your K Desktop never seems to stop. First its the Desktop appearances, the plethora of widgets available to choose and use from for the desktop and the taskbar, the hilighting schemes in Kate/KWrite, it keeps going on. Maybe a bad thing – you never settle.

I was trying out the kde-extragear-plasmoids AUR package yesterday on my ArchLinux’s plain KDE installation and I came across this wonderful plasmoid known as Smooth Tasks. While nothing innovative in itself, its a simple plasmoid that apes the Windows 7 taskbar. Provides icon views of the applications running and allows peeking into them when hovered upon, and if grouped – lets you switch using the previews. I’ll leave the screenshots to do the rest of explanation.

What I liked most about Windows 7 is its ability to color the hover-glow on the icons in the taskbar based on the average computed color of the icon itself. This feature, as explained by Long Zheng, “delivers some sentimental value by making it easy to identify applications by color.” I completely agree with that point. However, Smooth Tasks missed this feature, and the built in light feature didn’t move entirely with the mouse pointer as well.

I cloned the code today to add, at least an initial working version, the color hot-tracking to Smooth Tasks and it was done by the afternoon. I’ve pushed the changes to the Smooth Tasks fork over at Bitbucket (which is a great site, by the way) and the image below describes how the initial work looks like. Notice the soft color glow. Here are some more pictures, with other icons.

Color Hot-tracking in Smooth Tasks on KDE

Color Hot-tracking in Smooth Tasks on KDE

Now all I’ve to figure out is a way to enhance the glow or another component of the effect to give it a more polished look. Windows 7 also colors the border of the taskbar item with the average color but that’s not possible with the way the KDE’s glow around items work, as far as I know. Please let me know if am wrong.

You need to a flashplayer enabled browser to view this YouTube video

Written by Harsh

October 10th, 2009 at 1:25 pm

Install Python Packages locally

8 comments

There’s a great feature in Python versions 2.6 and up that I hardly see being used; it’s the ability to install modules and packages in a per-user local directory. I like this feature since it doesn’t have any super-user power requirements and lets me install packages, modules and even scripts in my own Home directory and use it just as normally as the other global files.

To do so, one must first create the local site-packages directory, and then place the required package or module file or folder under it. The following commands are all for UNIX. ~/ expands to the user’s $HOME automatically.

# To create the required directory
mkdir -p ~/.local/lib/python2.6/site-packages

Now place the module or package folder under this directory, or link to it for achieving the same installation effect as you would with a global site-packages directory. For example, for my django copy from svn I’d do:

ln -s ~/.django-svn/django-trunk/django ~/.local/lib/python2.6/site-packages/django

Running the Python interpreter (in the same user account) will show this working:

Python 2.6.2 (release26-maint, Apr 19 2009, 01:56:41)
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> 

So there you have it, when you want a package just for your user account while developing just put it under the local site-packages directory. Python automatically adds this to its path (PYTHONPATH).

References: PEP 370 (Has notes for OS X and Windows users)

Written by Harsh

May 21st, 2009 at 11:00 am

Posted in Linux, Software

Tagged with ,