Tuesday, September 28, 2010

GNU Autotools - Autoconf, Automake tutorial

The GNU build system, also known as the Autotools, is a suite of programming tools designed to assist in making source-code packages portable to many Unix-like systems.

Here is a sample step by step example to build a standard GNU project from scratch:

1. README contains some very limited documentation for our little package.
[onkar@gnutools queue]$ cat README
This is a demonstration package for GNU Automake.
Type `info Automake' to read the Automake manual.



2. Makefile.am and src/Makefile.am contain Automake instructions for these two directories.
[onkar@gnutools queue]$ cat src/Makefile.am
bin_PROGRAMS = queue
queue_SOURCES = main.cpp Queue.cpp
noinst_HEADERS = Queue.h

[onkar@gnutools queue]$ cat Makefile.am
SUBDIRS = src
docdir = ${datadir}/doc/${PACKAGE}
dist_doc_DATA = README




3. configure.ac contains Autoconf instructions to create the configure script.

[onkar@gnutools queue]$ cat configure.ac
AC_INIT([queue], [1.0], [bug-automake@gnu.org])
AC_PROG_CXX
AM_INIT_AUTOMAKE([-Wall -Werror foreign])
AC_PROG_CC
AC_CONFIG_HEADERS([config.h])
AC_CONFIG_FILES([
 Makefile
 src/Makefile
])
AC_OUTPUT



4. autoreconf: Once you have these five files, it is time to run the Autotools to instantiate the build system. Do this using the autoreconf command as follows:
[onkar@gnutools queue]$ autoreconf --install



5. configure: You can see that autoreconf created four other files: configure, config.h.in, Makefile.in, and src/Makefile.in. The latter three files are templates that will be adapted to the system by configure under the names config.h, Makefile, and src/Makefile. Let's do this:
[onkar@gnutools queue]$ ./configure
checking for g++... g++
checking for C++ compiler default output file name... a.out
checking whether the C++ compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for style of include used by make... GNU
checking dependency style of g++... gcc3
checking for gcc... gcc
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ANSI C... none needed
checking dependency style of gcc... gcc3
configure: creating ./config.status
config.status: creating Makefile
config.status: creating src/Makefile
config.status: creating config.h
config.status: config.h is unchanged
config.status: executing depfiles commands


6. make, make clean, make distcheck: You can see Makefile, src/Makefile, and config.h being created at the end after configure has probed the system. It is now possible to run all the targets we wish. For instance:
[onkar@gnutools queue]$ make
make  all-recursive
make[1]: Entering directory `/home/onkar/practice/cc/queue'
Making all in src
make[2]: Entering directory `/home/onkar/practice/cc/queue/src'
if g++ -DHAVE_CONFIG_H -I. -I. -I..     -g -O2 -MT main.o -MD -MP -MF ".deps/main.Tpo" -c -o main.o main.cpp; \
then mv -f ".deps/main.Tpo" ".deps/main.Po"; else rm -f ".deps/main.Tpo"; exit 1; fi
if g++ -DHAVE_CONFIG_H -I. -I. -I..     -g -O2 -MT Queue.o -MD -MP -MF ".deps/Queue.Tpo" -c -o Queue.o Queue.cpp; \
then mv -f ".deps/Queue.Tpo" ".deps/Queue.Po"; else rm -f ".deps/Queue.Tpo"; exit 1; fi
g++  -g -O2   -o queue  main.o Queue.o
make[2]: Leaving directory `/home/onkar/practice/cc/queue/src'
make[2]: Entering directory `/home/onkar/practice/cc/queue'
make[2]: Leaving directory `/home/onkar/practice/cc/queue'
make[1]: Leaving directory `/home/onkar/practice/cc/queue'


[onkar@gnutools queue]$ make distcheck
..................
===========================================
queue-1.0 archives ready for distribution:
queue-1.0.tar.gz
===========================================


[onkar@gnutools queue]$ make clean
Making clean in src
make[1]: Entering directory `/home/onkar/practice/cc/queue/src'
test -z "queue" || rm -f queue
rm -f *.o
make[1]: Leaving directory `/home/onkar/practice/cc/queue/src'
Making clean in .
make[1]: Entering directory `/home/onkar/practice/cc/queue'
make[1]: Nothing to be done for `clean-am'.
make[1]: Leaving directory `/home/onkar/practice/cc/queue'


Done!

Monday, May 31, 2010

Firefox: Essential Add Ons

WOT – We all know about the threats which surfers suffer like viruses, spywares, adware, malicious spam, phishing etc., but here Web of Trust comes to rescue. WOT warns you about risky websites that try to scam surfers before they enter in them using a safety rating of 21 million websites, WOT combines evidence collected from multiple sources. Not only does it help surfers but also sets a protection level for children by blocking inappropriate content.

Ghostery – It keeps an eye on the websites that are keeping an eye on you i.e. it finds out that which web sites which are tracking you and would alert you about the same.

Interclue - Ever wanted to know what was behind the link before you clicked? Interclue tells you everything you need to know before you open yet another tab.


Colorful Tabs – Colors every tab in a different color and makes them easy to distinguish while beautifying the overall appeal of the interface.

Separe – Helps you keeping tabs tidy by introducing a new kind of tab.

Permatabs – turn tabs of your choice into permanent tabs that can’t be closed, and stick around between sessions.

Flashblock – blocks all Flash content from loading on a webpage.

Adblock Plus – is an enhanced version of Adblock. Block ads, applets, flash, embedded-media etc.


Download Youtube Videos+  -  Video and audio download toolbar for tube sites and flv movies

Google Toolbar for Firefox

Fastest Search: Text search on page/in all tabs. Contains many features such as search Count/regex/visualize & list result/find-as-you-type.


Friday, May 28, 2010

Basics of Delegation



1. Some Benefits:
  1. Change the management philosophy.
  2. Enhance management style
  3. Enhance your productivity
  4. Reduce your workload
  5. Increased availability


2. How delegation impacts you?
  1. Delegation is vital for effective management
  2. Reduce workload
Delegate non-critical work like:
  Researching
  Data entry
  Clerical duties
  Organizing docs
  1. Alleviate time constraints

3. How delegation impacts your employees?
1.      Increase motivation
2.      Challenge your employees
3.      Results in positive career development.

4. How delegation impacts your organization?
  1. Positive work atmosphere
  2. Efficient employees, high productivity, low turn over rates
  3. Retain skilled employees

5. Preparing you to delegate:
  Benefits:
1.      More confidence in your delegating ability
2.      Quicker task completion
3.      More time to focus on managerial tasks

6. Why managers hesitate to delegate?
  1. Managers want to be viewed as superior workers
    1. They may overextend themselves and get exhausted
    2. Employees may resent
    3. They may become inferior workers

  1. Perfectionist tendencies
    1. If you want something done right, do it yourself
Solutions:
1.      Prioritize tasks and realize that perfection is not always attainable or necessary.
2.      Redirect energy by turning mistakes/errors into positive learning experiences
3.      Hone delegation skills.

  1. Fear of being replaced

7. Delegating style:
  1. Controlling => limited experience, substantial managerial input needed  => limits responsibility, decreased stress and motivation levels
  2. Coaching => close supervision, moderately experienced employee => more responsibility
  3. Consulting => previous experience with similar tasks, manager is available for any questions, etc.
  4. Coordinating => Full responsibility to assignee, minimal feedback => results in a highly motivated workforce


8. Develop your delegating attitude:
  1. Confidence in delegating abilities
  2. willingness to take risks
  3. trust
  4. task oriented
  5. patience

9. Delegation Skills:
  1. Technical
    1. Mid to lower level employees
  2. interpersonal
  3. conceptual
              - Knowing the organizational structure
10. Attributes of a delegated task: (SMART)
  1. Pertinent to employee’s job description
  2. Possible to achieve
  3. Measurable
  4. As detailed as possible

11. Deciding What Tasks to Delegate
  1. Easily completed
  2. Suited to employee’s skills
  3. Challenging
12. Elements of a Delegated Task
1.      Mental
2.      Physical
3.      Interpersonal





Presentation Skills


1. COMPONENTS OF PRESENTATION:
  1. skills of presenter
  2. audience
  3. venue
  4. message


2. TYPES OF PRESENTATION:
1) motivate - acknowledge audience's -ve feelings and communicate vision of the future in positive way
2) inform - sequence information in logical order and ask questions to check audience's understanding
3) persuade - sell the benefits, support them with facts, appreciate audience's point of view
4) discussion - present set of options, listen to audience's views, answer audience's questions
5) entertain - amusing anecdotes, avoid telling jokes


3. WHAT MAKES A SUCCESSFUL PRESENTER?

  1) behave confidently but not arrogant - eye contact, normal voice, natural gestures/movements
  2) interact with the audience but not too much - ask and encourage to ask questions
  3) demonstrate physical skills of presenting - know your equipments


4. AUDIENCE CONCENTRATION
  External factors:
    1) Size of venue and audience
    2) How well equipped the venue is
    3) The time of day


5. PREPARING FOR PRESENTATION:
 i) objective
        write what is the expected outcome of your presentation?

 ii)  select presentation content
          - choose quickly which helps ideas to flow and saves time
          - identify main points and then connected sub-points - SINGLE WORDS, NOT SENTENCES
       Options:
         i) brainstorm  - preferred due to flexibility and imaginative approach
        ii) linear list

 iii) organize presentation content
           arrange in logical order. eg: chronological order
           group your main points.
           choose powerful sub-points


6. ORGANIZING YOUR PRESENTATION NOTES:
    usually main headings with sub point bullets - complicated or new presentation
    sometimes main headings alone    - simple content or already given the presentation before
    occasionally read presentation as a speech - eg: in case of legal liability


7. ANXIETY
Rational Reasons for anxiety
    - less experience
    - on your own
    - pressure - imp. presentation

Irrational Reasons for anxiety
    - They won't like me
    - Run out of material
    - Completely forget what I want to say

Controlling anxiety
    - hours before presentation - do normal work, relax, exercise
    - be calm just before the presentation - sit/stand comfortably, get rid of irrational thoughts, control your breathing


8. REHEARSAL
    rehearse straight after u have finished preparing your presentation
    rehearse sevaral times
    rehearse in a condition as realistic as possible

  Full rehearsal
    deliver in the correct amt of time
    Include your slides and other equipment
    Use a space similar to the size of your actual venue
    record the presentation
    rehearse in front of audience

  Partial rehearsal
    Focus on difficult parts - start and end of presentation, introduction to a section
    Practice movements and gestures
   

9. PRESENTATION ENVIRONMENT
    seating arrangement - horse shoe/classroom style
    equipment position - easy to access
    shape and size of the room - comfortable for audience, be able to see the audience
    come at the venue 1 hr before

Wednesday, May 12, 2010

Tips on Google Search

Google has become very much an indispensable tool for carrying out many of our day to day tasks. But, chances are, unless you are a technology geek, you probably still use Google in its simplest form.  If your current use of Google is limited to typing a few words in and changing your query until you find what you’re looking for, then here’s a better way – and it’s not hard to learn.

Monday, May 03, 2010

Agile software development

Agile software development contains specific tools and techniques such as continuous integration, automated or xUnit test, pair programming, test driven development, design patterns, domain-driven design, code re-factoring and other techniques which are often used to improve quality and enhance project agility.

I'll cover some of the most important agile methodologies that I found very useful in executing projects.

1. Test-driven development (TDD):
It is a software development technique that relies on the repetition of a very short development cycle: First the developer writes a failing automated test case that defines a desired improvement or new function, then produces code to pass that test and finally refactors the new code to acceptable standards.

Benefits
1. Using TDD meant writing more tests and, in turn, programmers that wrote more tests tended to be more productive.
2. Used in conjunction with a version control system, when tests fail unexpectedly, reverting the code to the last version that passed all tests may often be    more productive than debugging
3. Test-driven development offers more than just simple validation of correctness, but can also drive the design of a program.
4. It allows a programmer to focus on the task at hand as the first goal is to make the test pass. Exceptional cases and error handling are not considered       initially.
5. Eliminating defects early in the process usually avoids lengthy and tedious debugging later in the project.
6. TDD can lead to more modularized, flexible, and extensible code
7. TDD can lead to more modularized, flexible, and extensible code. See: Mock Object design pattern
8. Because no more code is written than necessary to pass a failing test case, automated tests tend to cover every code path.

Criticisms
1. The tests themselves become part of the maintenance overhead of a project.
2. The high number of passing unit tests may bring a false sense of security
3. Unexpected gaps in test coverage may exist or occur.


2. Mock Objects:

Mock objects allow you to set up predictable behavior to help you test your production code by emulating some functionality your code depends on. This might for example be a huge database which is too difficult and time consuming to maintain just for testing purposes.

Referances:
http://mockpp.sourceforge.net/ - a platform independent generic unit testing framework for C++
http://code.google.com/p/googlemock/



3. Pair programming:
It is a software development technique in which two programmers work together at one work station. One types in code while the other reviews each line of code as it is typed in.


Benefits:
* Design quality: Shorter programs, better designs, fewer bugs.
* Reduced cost of development: With bugs being a particularly expensive part of software development, especially if they're caught late in the development process, the large reduction in defect rate due to pair programming can significantly reduce software development costs.
* Learning and training: Knowledge passes easily between pair programmers: they share knowledge of the specifics of the system, and they pick up programming techniques from each other as they work.New hires quickly pick up the practices of the team through pairing.
* Overcoming difficult problems: Pairs often find that seemingly "impossible" problems become easy or even quick, or at least possible, to solve when they work together.
* Improved morale: Programmers report greater joy in their work and greater confidence that their work is correct.
* Decreased management risk: Since knowledge of the system is shared among programmers, there is less risk to management if one programmer leaves the team.
* Increased discipline and better time management: Programmers are less likely to skip writing unit tests, spend time web-surfing or on personal email,[8] or other violations of discipline, when they are working with a pair partner. The pair partner "keeps them honest".
* Resilient flow. Pairing leads to a different kind of flow than programming alone, but it does lead to flow.[citation needed] Pairing flow happens more quickly: one programmer asks the other, "What were we working on?" Pairing flow is also more resilient to interruptions: one programmer deals with the interruption while the other keeps working.
* Fewer interruptions: People are more reluctant to interrupt a pair than they are to interrupt someone working alone.
* Decreased risk of RSI: The risk of repetitive stress injury is significantly reduced, since each programmer is using a keyboard and mouse approximately half the time they were before.




4. Extreme Programming (XP):
It is a software development methodology which is intended to improve software quality and responsiveness to changing customer requirements. As a type of agile software development, it advocates frequent "releases" in short development cycles (timeboxing), which is intended to improve productivity and introduce checkpoints where new customer requirements can be adopted.

Other elements of Extreme Programming include:
1. programming in pairs or doing extensive code review,
2. unit testing of all code,
3. avoiding programming of features until they are actually needed,
4. a flat management structure,
5. simplicity and clarity in code,
6. expecting changes in the customer's requirements as time passes and the problem is better understood, and
7. frequent communication with the customer and among programmers.

XP attempts to reduce the cost of change by having multiple short development cycles, rather than one long one.

Criticism:
    * A methodology is only as effective as the people involved, Agile does not solve this
    * Often used as a means to bleed money from customers through lack of defining a deliverable
    * Lack of structure and necessary documentation
    * Only works with senior-level developers
    * Incorporates insufficient software design
    * Requires meetings at frequent intervals at enormous expense to customers
    * Requires too much cultural change to adopt
    * Can lead to more difficult contractual negotiations
    * Can be very inefficient — if the requirements for one area of code change through various iterations, the same programming may need to be done several       times over. Whereas if a plan were there to be followed, a single area of code is expected to be written once.
    * Impossible to develop realistic estimates of work effort needed to provide a quote, because at the beginning of the project no one knows the entire           scope/requirements
    * Can increase the risk of scope creep due to the lack of detailed requirements documentation
    * Agile is feature driven; non-functional quality attributes are hard to be placed as user stories



5. Scrum 

Scrum is an iterative, incremental  framework for project management and agile software development.

The main roles in Scrum are:
   1. the “ScrumMaster”, who maintains the processes (typically in lieu of a project manager)
   2. the “Product Owner”, who represents the stakeholders, represents the business
   3. the “Team”, a cross-functional group of about 7 people who do the actual analysis, design, implementation, testing, etc.

During each “sprint”, typically a two to four week period (with the length being decided by the team), the team creates a potentially shippable product increment (for example, working and tested software). The set of features that go into a sprint come from the product “backlog,” which is a prioritized set of high level requirements of work to be done. Which backlog items go into the sprint is determined during the sprint planning meeting. During this meeting, the Product Owner informs the team of the items in the product backlog that he or she wants completed. The team then determines how much of this they can commit to complete during the next sprint.[1] During a sprint, no one is allowed to change the sprint backlog, which means that the requirements are frozen for that sprint. After a sprint is completed, the team demonstrates the use of the software.



Daily Scrum Meetings

Each day during the sprint, a project status meeting occurs. This is called a “daily scrum”, or “the daily standup”. This meeting has specific guidelines:
        * The meeting starts precisely on time.
        * All are welcome, but only “pigs” (i.e. the ones committed to the project in the Scrum process) may speak
        * The meeting is timeboxed to 15 minutes
        * The meeting should happen at the same location and same time every day

During the meeting, each team member answers three questions:

        * What have you done since yesterday?
        * What are you planning to do today?
        * Do you have any problems preventing you from accomplishing your goal? (It is the role of the ScrumMaster to facilitate resolution of these impediments. Typically this should occur outside the context of the Daily Scrum so that it may stay under 15 minutes.)




Wednesday, March 17, 2010

Power of UNIX

UNIX/Linux is a very powerful operating system with a lot of simple commands for small tasks. Power of UNIX lies in its ability to handle very complex, huge data requirements which would bring other operating systems to a screeching halt.


For example from my personal experience, simple utilities like grep, gzip, gunzip, split are able to handle data varying from 1 KB to GBs with the same elegance and accuracy.

Say we have a file of size around 36 GB.

Follwing operations are performed on that file:
1. gzip   : size comes down to 4.2 GB.
2. gunzip : size grows back to 36 GB.
3. grep   : Search a pattern in this file and create a new file of size around 32 GBs => happens in around half an hour!
4. gzip   : compress it back and file size becomes 4.1 GB.

Alternately, you can use split command between step 2 and 3 to split the big file in no. of small chunks and then perform the remaining operations.



The operations we performed above are quite simple. However, the huge data set on which they are applied is what makes the problem hard. That's where power of UNIX comes...




Tuesday, March 09, 2010

Vim Tips

Very useful  Vi Tips:

* # g* g#        find word under cursor (forwards/backwards) or word completion in insert mode
guu                  lowercase line
gUU                uppercase line
~                     invert case (upper->lower; lower->upper) of current character
'.                      jump to last modification line
`.                     jump to exact spot in last modification line
:reg                 display contents of all registers
:"1p                 paste from register 1
gf                    Open the file under cursor
ctrl+w f          Open the file under cursor and split screen horizontally.
vim -O file1 file2    open file1 and file2 side by side
:command              runs named command
Ctrl+w {left,right,up,down}    move to window
''                        move to previous position
Ctrl+o  move to previous position (recursively, in history)
CTRL-I jump to next location (recursively, in history)

Jumping to diffs:
[c  Jump backwards to the previous start of a change.
]c  Jump forwards to the next start of a change.


Wednesday, March 03, 2010

The Duct Tape Programmer


My Summary:

1. Duct tape programmers are pragmatic. They know that shipping is a feature. A really important feature. Your product must have it. :-)

2. It’s great to rewrite your code and make it cleaner and by the third time it’ll actually be pretty. But that’s not the point—you’re not here to write code; you’re here to ship products.

3. "One principle duct tape programmers understand well is that any kind of coding technique that's even slightly complicated is going to doom your project."

4. If there’s no unit test the customer isn’t going to complain about that.

5. One principle duct tape programmers understand well is that any kind of coding technique that’s even slightly complicated is going to doom your project.

6. Duct tape programmers have to have a lot of talent to pull off this shtick. They have to be good enough programmers to ship code, and we’ll forgive them if they never write a unit test, or if they xor the “next” and “prev” pointers of their linked list into a single DWORD to save 32 bits, because they’re pretty enough, and smart enough, to pull it off.

Its not necessary to apply everything mentioned in the article in letter and spirit. But you get the point.

Thursday, February 25, 2010

Sample vimrc file

The vimrc file contains optional runtime configuration settings to initialize Vim when it starts. On Unix based systems, the file is named .vimrc

Here is a sample .vimrc file I use.


"set smarttab       " When on, a in front of a line inserts blanks according to shiftwidth
set showmode        " Show the current mode
set showcmd         " display incomplete commands
set showmatch       " show matching braces,
set hlsearch        " highlight searches
"set title          " show title in console title bar
set laststatus=2    " always show status line
set ic              " case insensitive search : use set noic to turn it off

set nocompatible    " This setting prevents vim from emulating the original vi's bugs and limitations.

set autoindent
set smartindent
"   The first setting tells vim to use autoindent (that is, use the current line's indent level to set the indent level of new lines). The second makes vim attempt to intelligently guess the indent level of any new line based on the previous line, assuming the source file is in a C-like language. Combined, they are very useful in writing well-formatted source code.

set tabstop=2

set shiftwidth=2
"  The first setting sets up 2-space tabs, and the second tells vi to use 2 spaces when text is indented (auto or with the manual indent adjustmenters.)

set showmatch
"    This setting will cause the cursor to very briefly jump to a brace/parenthese/bracket's match whenever you type a closing or opening brace/parenthese/bracket. I've had almost no mismatched-punctuation errors since I started using this setting.

set vb t_vb=
"This setting prevents vi from making its annoying beeps when a command doesn't work. Instead, it briefly flashes the screen -- much less annoying.

set ruler
"    This setting ensures that each window contains a statusline that displays the current cursor position.


set incsearch
"    With this nifty option, vim will search for text as you enter it. For instance, if you type /bob to search for bob, vi will go to the first b after you type the b, to the first bo after you type the o, and so on. It makes searching much faster, since if you pay attention you never have to enter more than the minimum number of characters to find your target location. Make sure that you press Enter to accept the match after vim finds the location you want.

"set virtualedit=all
"    By default, vim doesn't let the cursor stray beyond the defined text. This setting allows the cursor to freely roam anywhere it likes in command mode. It feels weird at first but is quite useful.


set tags=/tags,./tags

set showfulltag         " Get function usage help automatically

""""""""""""" Highlight following in all files """"""""""""""""""""""
hi TODO ctermfg=red ctermbg=blue term=bold
syntax match TODO /TODO/




""""""""""""""""""""""""""""""""""""""""""
"        Use Cscope within Vi                        "

""""""""""""""""""""""""""""""""""""""""""" Refer http://vim.wikia.com/wiki/Cscope for more details

if has('cscope')
  set cscopetag cscopeverbose

  if has('quickfix')
    set cscopequickfix=s-,c-,d-,i-,t-,e-
  endif

  cnoreabbrev csa cs add
  cnoreabbrev csf cs find
  cnoreabbrev csk cs kill
  cnoreabbrev csr cs reset
  cnoreabbrev css cs show
  cnoreabbrev csh cs help

  command -nargs=0 Cscope cs add $VIMSRC/src/cscope.out $VIMSRC/src
endif
""""""""""""""""""""""""""""""""""""""""""

""""""""""""""""""""""""""""""""""""""""""
"               Mappings                 "
""""""""""""""""""""""""""""""""""""""""""
" Keyboard mappings
map :previous  " map F1 to open previous buffer
map :next      " map F2 to open next buffer
map :setl noai nocin nosi inde= " Disabling auto indent for the current file