Viewing contents of an rpm package

16 08 2009

rpm2cpio [package.rpm] |cpio -dvim

it should extract the archive in the current directory





Control LCD brightness in Fedora8

16 08 2009

xbacklight is an useful command to change the brightness of your monitor backlight provided you have a supported driver.

xbacklight -get
to retrieve to get present brightness level in %

xbacklight -set value

to set the brightness to desired value in %





Working from home

1 10 2008

Most of the time I need to login to my linux box in my office from home. The obvious choice is to ssh using putty or cygwin (in case i need some X windows). Normally in cygwin – you will run

ssh -l xyz@yourserver.com ………(1)

to login to your account “xyz” in yourserver.com . This would ask for password and if you provide the correct password you would be able to login to the server.

SSH optionally uses public-key encryption – where a  public and private key pair can be used to automate the login process. If you are using cygwin( or in fact any other client running ssh) you can do the following to generate your public and private key pair

ssh-keygen…………………………..(2)

It will prompt for a few input – but you can just press ‘enter’ in all the cases. The keys will be created in $HOME/.ssh/as id_rsa(private key) and id_rsa.pub(public key). Now you can copy the id_rsa.pub to the server -yourserver.com’s ‘xyz’s ~/.ssh/ as ‘authorized_keys’ – and you are done. Try running (1) and you should be able to login without the prompt for password.

In case you are using putty – you can use puttygen to generate the public  & private key pair. Then you will do the same step – copy the public key to the desired account’s .ssh/authorized_keys and use the private key to login. There are tutorials that explains this with nice diagrams .





Rescued by cscope

17 06 2008

I have been working on mozilla codebase quite sometime. Its a huge codebase with millions of lines of code. A simple counting on the numbers of lines in *.cpp files for 3.0b2 release accounts 1778818 lines of code[1]. Most of the time I need to search for function definitions – I used grep -r xyz * as that was the only option I know until recently I have started using cscope which came as a rescue. cscope maintains its own database of symbol definition of the code. You can find the symbol, find a symbol definition, a file , a text within source code. Configuration of the cscope database is simple.

Step 1 . Make a directory to store the cscope db say $HOME/mycscope/mozilla

Step 2. cd /

Step 3. say $HOME/mozilla is the home directory of the project that contains the source files(*.c,*.cpp,*.h)

run find $HOME/mozilla -name “*.cpp” >> $HOME/mycscope/mozilla/cscope.files

run find $HOME/mozilla -name “*.h” >> $HOME/mycscope/mozilla/cscope.files etc.

It will simply populate the cscope.files used by cscope to create the data with the desired filenames.

Step 4. run in $HOME/mycscope cscope -b -q -k which will create the database cscope.out

Step 5. run cscope -d from $HOME/myscope and start searching and browsing code.

In case you want to invoke it from vim add the following lines to your .vimrc

set nocsverb ; supress cscope logging messages
cscope add $HOME/mycscope/cscope.out

You should be able to invoke cscope from vim window now . eg try :cs find 1 XYZ

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

1. sum=0;for i in `find . -name “*.cpp” -exec wc -l {} \; |cut -d ‘ ‘ -f 1` ; do sum=`expr $sum + $i`; done; echo $sum





Copyright Vs Community w/ Richard Stallman

26 03 2008

Just got a chance to attend a seminar on Copyright Vs Community by Richard Stallman
I hope most of you are aware of this guy who pioneered the free software movement .
coined the term GNU is not UNIX , developed the most popular gcc compiler and emacs editors .

Stallman

Free software movement started in early eighties and by now its just as a dominant
race as the non-free softwares . Freedom is our right and proprietary softwares just
donot respect individual freedom . People are entitled to use only the way developer
design that software – there is no freedom to customize it to their need because the
source codes were not available. Stallman defined four degrees of freedom for a software
to be called a free software -
0 – they should be available freely for use \
1 – source code should be available for customized by the user
2 – user can distribute the custom software freely
3 – user can make as many copy of the software as he wants freely .

After this brief introduction he moved to the constraints that hinders the freedom of the users
Here comes the theme of the lecture . He mentioned how the copyright laws came into existence and how they
are helping the corporates to make money and comprising on the freedom of individual in a democratic society.
Example ranging from books to digital music got mention in his talk .
One example that worth mentioning is the music CDs prepared by Sony . Sony hides a copyright management
software in their music disks that runs automatically and and modifies some of the system parameters permanently so that
the software remains hidden from the user and prevent user from making copy of the music.
This caused a permanent security loophole in the system and computers became vulnerable to attacks.
Sony was finally forced to recall million of its CDs .

I personally feel that copyright should be there – but I believe this should not be the same way as they
are today . And when it comes to different category of copyright able subjects they
should be treated differently.He mentioned some innovative way publishers are making money
without sharing much of the revenue with the author or the composer. Stallman mentioned that books , musics
etc are subjected to a limited copyright. In case of softwares , he insisted that their non commercial use
should be free and the above four freedom should exists in the software world to help maintaining a democratic society.

He finally urge everyone to stand against the wave and support the freedom of software .
If you would like to participate in the movement here is a good point to start .





My .vimrc

18 01 2008

For those who are writing codes in C/C++ using Vim should find this .vimrc configuration file useful . The script should be self explanatory . If you have any question, I will try to answer. or :help should help you out. Put the following lines to your .vimrc and save .

set incsearch “when you start searching ESC /[string] it will start matching as soon as you type

set scrolloff=3 ” there would be atleast 3 lines from the top/bottom of the screen as you edit

set wildmode=longest,list ” ESC :![filename] TAB should give you a list of matched files

set ts=2 ” TAB would be of two char length

set expandtab “expand TAB char to spaces

set ai ” set auto indent

set cindent shiftwidth=4 “enable C style indent

set ignorecase

set smartcase ” together they help you search string ignoring case if you type in lower case

colo evening ” if you like a colorful editing experience





One Laptop Per Child

9 10 2007

xo11.jpg

A $100 laptop – with a tablet screen, video camera, microphone, a graphics tablet, game-pad controllers, and a memory-card slot ? Yes, this is the dream of One Laptop Per Child to develop a very low-cost, high-potential, extremely rugged computer for the two billion educationally underserved children in poor countries. And the dream comes true OLPC unveiled their dream machine XO in October.

 

xo2.jpg

XO provides regular wireless Internet connectivity as well as mesh networking, and its system software takes up one-fifth of its 1 GB of flash memory storage. The majority of the laptop’s programs can be shared on the mesh network it supports. The XO comes close to the initiative’s original vision of a $100 laptop (it currently costs $200 ) and in November the computer will be offered for sale to the public in industrialized countries for two weeks through OLPC’s “Get 1, Give 1″ program. Under the program, a consumer pays $400, which covers the cost of one XO laptop–complete with tax deduction–for the consumer and one for a student in an impoverished country. One more reason to be happy – XO is built from free and open-source software.

Configuration : (Details can be found here )

  • Approximate dimensions: 242mm×228mm×32mm;
  • Approximate weight: 1.45KG with LiFeP battery; 1.58KG with NiMH battery;
  • Configuration: Convertible laptop with pivoting, reversible display; dirt- and moisture-resistant system enclosure; no fan.
  • CPU: 433 Mhz AMD Geode LX-700@0.8W CPU
  • Memory: 256 MiB DRAM
  • Storage: 1 GB SLC NAND flash ;MMC/SD Card slot available
  • Battery: : 2 or 4 cells LiFePO4; or 5 cells NiMH .
  • Average Power Consumption : 2 watts, compared with 60 or more on a typical business laptop. That’s one reason it gets such great battery life. A small yo-yo-like pull-cord charger is available (one minute of pulling provides 10 minutes of power); so is a $12 solar panel that, although only one foot square, provides enough power to recharge or power the machine.

 





Open Source North East – An Initiative

5 10 2007

“Open Source Northeast” is one more initiative from Prag Foundation. This is supposed to be the first magazine from NE india promoting Open Source for development of North Eastern States. The theme is very novel. The founders are very much motivated to share the benefits of Free and Open Source Software (FOSS) in building Information Communication Technology (ICT) capability for development and success in today’s emerging Knowledge Society.

Open Source NorthEast
Volume-I of the magazine covers a few interesting topics such as  Open Access and Open Course Ware. You will find links to various organization, especially the universities,  that houses various courses online and free for all. In India ,a similar kind of initiative is taking place in IIT Bombay (http://www.dep.iitb.ac.in/). I think there will be much more information about open course ware in the coming issues of the magazine.

If you want to buy a PC for yourself here are the tips for you in the Know How section. A good review of OpenOffice is also in place as per the software reviewed in this issue.

I feel Open Source Northeast is a good start. Contents are good and well written except for some occasional typos. There are lot more scope to improve the current layout  to create better look and feel experience.

For all those interested to read out the mag should find a soft copy here. And please dont forget to leave your comments to editor. !





Feature Oriented Programming -II

2 10 2007

AHEAD, as discussed in the previous article defines the following tasks for generating complete software from features. .

A. define numbers of features

B. semantics to create an algebraic equation from features (feature refinement)

C. define a composer to compose the final feature out of the equation and produce the final software (assuming composer performs the final compilation)

This approach requires the selection of different features available to be specified in compile time. Every new refinement would require step B and C to be repeated.

The purpose of this short article is to show a different FOP approach where feature selection happens in runtime. In this approach – all the features are loaded at compile time and the selection of features is deferred till we run the application. The user is provided with a configuration that is read by the program to activate only those features specified in the configuration. By this we can complete the requirement of different feature selection by providing different configuration with the same executable. This ensures that we reduce the time spent in compilation for different combinations of features.

Sample Implementation

The implementation I am currently using is inspired by the “registry of singleton” mentioned in Design Patterns – Elements of Reusable Object-Oriented Software (GOF).

All features are derived from a base class – Feature. Every feature (Feature1, Feature2), in this example, assigns a different value to printStr. The features are registered with a FeatureManager that acts as a store house for features. The user specifies the features he wants to use as a command line input to the test program.

You may download the source and makefile from this link.

Base class – Feature.h

 

#ifndef _F_H_

#define _F_H_

#include<iostream>

class Feature

{

public:

virtual void print()

{

std::cout << printStr << std::endl;

}

protected:

std::string printStr;

};

#endif

File: Feature1.h

#ifndef _F1_H_

#define _F1_H_

#include<iostream>

#include “FeatureManager.h”

#include “Feature.h”

class Feature1 : public Feature

{

public:

Feature1()

{

printStr = “1″;

FeatureManager::Register(printStr ,this);

}

 

};

#endif

 

File:Feature1.cpp

#include “Feature1.h”

static Feature1 f1;

 

File: Feature2.h

#ifndef _F2_H_

#define _F2_H_

#include<iostream>

#include “FeatureManager.h”

#include “Feature.h”

class Feature2 : public Feature

{

public:

Feature2()

{

printStr = “2″;

FeatureManager::Register(printStr,this);

}

 

};

#endif

File: Feature2.cpp

 

#include “Feature2.h”

static Feature2 f2;

 

File: FeatureManager.h

#ifndef _FM_H_

 

#define _FM_H_

#include<iostream>

#include<map>

#include “Feature.h”

 

class FeatureManager

{

public:

static void Register(const std::string& name, Feature* f);

static FeatureManager* GetInstance();

static Feature* Lookup(const std::string& name);

private:

static FeatureManager* _instance;

static std::map<std::string, Feature*> _registry;

};

#endif

 

File: FeatureManager.cpp

#include “FeatureManager.h”

FeatureManager* FeatureManager::_instance = NULL;

std::map<std::string,Feature*> FeatureManager::_registry;

 

FeatureManager* FeatureManager::GetInstance()

{

if(_instance == NULL)

{

return (_instance = new FeatureManager());

 

}

else

return _instance;

}

 

void FeatureManager::Register(const std::string& name, Feature* f)

{

_registry[name] = f;

}

Feature* FeatureManager::Lookup(const std::string& name)

{

std::map<std::string,Feature*>::iterator it = _registry.find(name);

if( it != _registry.end())

{

return (*it).second;

}

else

{

return NULL;

}

}

 

File: test.cpp

#include <iostream>

#include “FeatureManager.h”

#include “Feature.h”

int main(int argc, char **argv)

{

FeatureManager * mgr = FeatureManager::GetInstance();

//loop through the features provided

for(int i = 1; i<argc; i++) {

Feature *f = mgr->Lookup(argv[i]);

if(f)

f->print();

}

}

 

Test run

$ ./test 1 2

1

2

$ ./test 2

2

 





Feature Oriented Programming – I

16 09 2007

Introduction

Few questions that have always drawn attention of the Software Engineering community

1. Is there any simpler way to explain the functionality of software to a layman? -Simpler then UML diagrams?

2. Can we start with a single representation and use it to generate the program as well as generate the test cases and documentation? – Can the representation x applied to a function f i.e. f(x) produce the desired program, generate the documents, and test cases?

3. Can we produce an optimized version by working on the original representation of software? Can O (n^2) explicit complexity of the representation x be reduced to O (n)?

4. My mom doesn’t know programming; can she still be able to write software? Can she just say -”I need a calculator to multiply two integers” and the calculator is before her screen?

Everyone in the IT industry would be happy to have all these in place. The main reason would be a huge reduction in the software development cost. And yes, recent research in Software Engineering is just focusing on them. Some major research in this area is going on product-line architecture in Department of Computer Science in UT Austin. They are working on feature-refinement techniques and almost covering all of the challenges 1-4 .

What is a feature?

A feature is a unit of functionality provided by a program. e.g. let’s take an example of calculator. The normal features of the calculator are addition, subtraction, multiplication and division of integers. Features can be added and removed and replaced just like different software to and from an OS. Product line architecture mainly deals with developing software by incrementally adding features to a product. The paradigm of software development using features as building block is called feature oriented programming.

FOP implementation

AHEAD or Algebraic Hierarchical Equations for Application Design is one of the pioneering work in FOP by the product line architecture group. It represents a program or a set of programs using a nested set of equations. It uses constants (a feature), a function (a feature refinement) and a few operators to write the equations. The equations are ideal for code generators and can be interpreted by different generators to produce codes, as well as documentations and test cases etc (2). They are simple enough to explain. Since they are based on algebraic equations, they are susceptible to optimization (3)

The main operator is called composition and it’s represented by a solid dot (•). Lets take an example of the use of this operator – let f is a program with features bf ,af ,cf and h with features bh ah and dh.

Then the composition of f and h is given by

f•h = { bf ,af ,cf }•{ bh, ah , dh}

= { bf• bh , af• ah , cf , dh }

Note that the constants with same name but different subscription are recursively composed to produce the final product f•h. The operator • is polymorphic so you are free to implement the operator as you like and produce your own implementation. E.g. it can be javac to produce the java codes from the equations, may be javadoc to produce the html pages.

I would include the other operators in my next post.

AHEAD Tool Set

ATS is the software kit that can be used to develop software in a feature oriented way.

You can download the latest version of AHEAD tool set from this link. AHEAD is developed in Java, so you will need JAVA. It is also preferable to download ANT as well. ATS comes with a composer. I have used it for refinement of Jak features. Jak features are written in a Java like languages that conforms to Jakarta Tool Set. Typically you pass the Algebraic equation to composer and the composer produces the desired product for you. Let’s try out your first programming in AHEAD using the FOP concepts.

 

Hello World in AHEAD

Aim : To generate a program that writes “Hello World” in three languages English, Hindi and Assamese.

Features –

  1. Base : that writes “Hello World” – English
  2. Hindi : That writes “Namaste India” – Hindi
  3. Assamese : That Writes “Namaskar Axom” – Assamese

 

Toolset version:

Runs in Linux

ahead-v2007.08.28

 

Steps:

1. Create the following hierarchy of directory in your $HOME

Hierarchy

 

2. Copy the following files to the appropriate directories

a. HelloWorld/Base/hello.jak

 

public class hello

{

String str = “Hello World”;

public void print()

{

System.out.println(str);

}

}

 

b. HelloWorld/Hindi/hello.jak

 

refines class hello

{

public void print()

{

str += “\n Namaste India.” ;

Super().print();

}

}

Note that we are using Super().print() to refer to the definition of the print() of the super class in the hierarchy. In this case Base->Hindi->Assamese

 

c.HelloWorld/Assamese/hello.jak

refines class hello

{

public void print()

{

str +=”\n Namaskar Axom”;

Super().print();

}

}

 

3. Create a file called composer.properties to set the following property –

unit.file.jak: JamPackFileUnit

It says when composing Jak files use the tool “jampack”. jampack is shipped with ATS.

4. Now in our case we want a composition comp = Base • Hindi • Assamese so that we can print something like

 

Hello World

Namaskar Axom

Namaste India.

 

So we run the composer inside HelloWorld as follows

$ composer –target=comp Base Hindi Assamese

 

5 . The composer creates a directory called comp in the same level.

The resulting composition will be the same “hello.jak” with the following modification –

 

layer comp;

public class hello

{

String str = “Hello World”;

public final void print$$Base()

{

System.out.println(str);

}

public final void print$$Hindi()

{

str += “\n Namaste India.” ;

print$$Base();

}

public void print()

{

str +=”\n Namaskar Axom”;

print$$Hindi();

}

}

 

You can see the tool is very intelligent to replace every Super().print() is replaced by a function with name as print$$[base class] . So finally when we call hello.print it should print the desired result .

 

6. The java code for the corresponding jak code is generated by jak2java tool comes with ATS.

 

So

$ jak2java hello.jak

will result in hello.java with

 

package comp;

public class hello

{

String str = “Hello World”;

public final void print$$Base()

{

System.out.println(str);

}

public final void print$$Hindi()

{

str += “\n Namaste India.” ;

print$$Base();

}

public void print()

{

str +=”\n Namaskar Axom”;

print$$Hindi();

}

}

7. Just write a test program to test it . I am using the following test program to do so .

 

import i3.*;

class test

{

public static void main(String args[])

{

hello c = new hello();

c.print();

}

}

~

 

And you should see something like

Hello World

Namaskar Axom

Namaste India.

 

On the screen.

A FEW MORE POINTS

If you want to install AHEAD from the source code – you must used the latest versions of Jdk and Ant , javaCC.

I am using the following version

JavaCC 4.0

jdk1.6.0_02

apache-ant-1.7.0

Be sure to set the env variable JAVA_HOME, ANT_HOME, AHEAD_HOME, PATH and LD_LIBRARY_PATH. I am still having some issues with compiling “reform” so I am using the executables instead.

In any case feel free to drop me your thoughts, queries. I would happy to discuss.

In my next post I would try to describe one more approach of FOP that I have used recently.

 

Just a point to ponder – “Compositor is polymorphic. What kind of polymorphism it supports? Dynamic or Static?”