Thursday, November 26, 2009

Automatic builds with some inotify magic

The inotify feature in the linux kernel allows you to receive events about changed files. Using pyinotify, here is a simple script to watch for changes to source code and run "make". Everything is hard coded right now, and since I was using CMake with out-of-source builds, the directory structure is that way. It also uses the command line notify-send tool to display notifications. Perhaps some day I will make it configurable and more useful.

Cheers.



# Notification tool
# Run with the directory to watch
# currently hardcoded to use
#
# +
# |- src - contains source code and is monitored
# |- build - assumes build to be here
#
# (c) 2009, Nikhil Marathe
# Licensed under the MIT License

import sys
import os
import subprocess
import re
from pyinotify import WatchManager, Notifier, ProcessEvent, IN_MODIFY

wm = WatchManager()

class Compile( ProcessEvent ):
def process_IN_MODIFY( self, event ):
print event.path, event.name, event.mask & IN_MODIFY

if re.match( '[a-zA-Z]*.cpp', event.name ):
os.chdir( event.path.replace( 'src', 'build' ) )
ex = subprocess.call( 'make' )
subprocess.call( ['notify-send', "Build output", "%s" % ( ex == 0 and "Success" or "Error" )] )

c = Compile()
notifier = Notifier( wm, c )
wm.add_watch( sys.argv[1], IN_MODIFY, rec=True )

notifier.loop()


Saturday, November 21, 2009

Worse is Better

Code Hale shows that sometimes performance needs to be sacrificed for security. Premature optimisation is the root of evil :p

Saturday, November 07, 2009

Chrome: Little UI touches

I forgot to mention that I made a life changing decision change of browser about 2 weeks ago. I've been exclusively on Chrome ever since. I love the minimalist look, the great search features for downloads and the best feature is perhaps Ctrl+PgUp/Dn to switch tabs. Its also very fast on shutdown and startup compared to my firefox, almost Firebug like Developer Tools, really awesome view-source: component ( inspired by kio? ). I love the fact that I can kill some flash/java applet without crashing the browser. So fellow archers go and grab the PKGBUILD

But the really interesting thing I noticed today is this:

Hide the bookmarks toolbar. Open a new tab. In SpeedDial, notice how the bookmarks are shown at the top. Now show the bookmarks toolbar. Voila, bookmarks are hidden.

As for the firefox plugins, well I don't miss any of them yet, except for the Delicious plugin, which I try to compensate for using the bookmarklet.

Monday, November 02, 2009

Macros for Observers

Here are two little macros too make implementing the Observer design pattern less repetitive. This is C++

File: observermacros.h




#ifndef DDM_OBSERVERMACRO_H
#define DDM_OBSERVERMACRO_H

#define MAKE_OBSERVABLE( obscls ) \
private:\
std::list< obscls *> m_observers;\
public:\
void addObserver( obscls *obs ) {\
m_observers.push_back( obs );\
}\
void delObserver( obscls *obs ) {\
m_observers.remove( obs );\
}

#define NOTIFY( obscls, obsmethod, argument ) \
for( std::list::const_iterator it = m_observers.begin();\
it != m_observers.end(); it++ )\
(*it)->obsmethod( argument )

#endif




Now if you want a class to be observable do



#include "observermacros.h"

class NeedsObserving
{
MAKE_OBSERVABLE( Observes );
};



Observes is the name of the class which will observe NeedsObserving.



// add/del observers
NeedsObserving no;
Observes o = new Observes;
no.addObserver( o );
no.delObserver( o );

// To notify observers of changes

void NeedsObserving::didSomething()
{
// CoolThing *coolThing is modified/used here
// ...
NOTIFY( Observes, coolThingDone, coolThing );
// Calls Observes::coolThingDone( CoolThing * );
}


The code is pretty naive, but it might help. Cheers

Saturday, October 24, 2009

Spectacular failure ( success? ) at IEEEXtreme

Solved 2/12 problems in the first set successfully. Tried to solve 2 more, but not accepted. Can't take the straight concentration anymore. I'm hungry, dropping the contest. This was more appropriate for twitter, but I don't have an account. :o

Thursday, October 22, 2009

Non-trivium

When you don't post for a long time, it usually means you have nothing interesting to do. But for me it usually means that I have a lot of things to do. And the last month have been horrible in terms of free time.

We had a really great one day trip to Diu, but from then on, it was all underhill :)

You might want to check out the Synapse website which was crafted from scratch with a little help from these guys. This was done under constant pressure of the not so great marks I received in the first midsem exam and the looming second insem, so I applaud myself.

This was accompanied by Concours 09, the first time DA-IICT ever held an inter-college sports fest. We reached the finals and lost! (in football). But now the exams were just a week away.

This exam week was the worst of my short stint in DA. Never before have I skipped football for 5 days straight. And the woozy feeling in the head when I soaked up about 1024Kb worth of signals and systems and put more than half out on the paper. This followed by Algebraic Structures meant that I was with tics for the whole day. Whoo what a semester this is turning out to be...

Thankfully I've been home for almost a week now, enjoying great food after quite some time. But my football holiday is now up to 15 days! I have hacked on the Synapse registration, read 3 chapters of Programming Scala, watched the first part of A curious course on Concurrency and Coroutines, submitted a first code review of kwin-tiling, and procrastinated on some other things. Through all this I also read a few books, and watched the first 5 episodes of Heroes Season 4. That was a lot of stuff in retrospect. Meanwhile FOSS.in is starting to pick up steam and I'm looking forward to when the registration for simple attendance begins.

I'm also on the look-out for an internship.

In the next 48 hours, its back to DA, and time to get cracking on IEEEXtreme, at which I am going to fail miserably, since I don't get time to do pure algorithm practice.

And I thought I was on a holiday :(

PS: I wish some one would sponsor me to go to Camp KDE or atleast Akademy.

Saturday, September 26, 2009

KDE introductory talk

The Open Source Initiative in DA-IICT is our effort to get more students interested in open source, and get them to start contributing to projects. As part of that I evangelized KDE, showed off our cool apps, and demonstrated how Krunner + Kwin + Plasma come together to improve productivity a LOT. Here are the slides, Unfortunately my notes were handwritten, so you can't glean much from here. But someone else might be able to use it ( please attribute it to me though, thanks ).

Download the slides ( pdf, 461k )