Monday, December 31, 2007

make_linux_look_like_a_mac

http://www.howtoforge.com/mac4lin_make_linux_look_like_a_mac

Wednesday, December 26, 2007

Perl Guidelines

I also like the idea of having all PODs at the bottom
of the file. The idea is that hopefully the code is self documenting enough
that the POD is provided as an extra reference. It also makes scanning
through pages of code much easier.

Here are the proposed guidelines:

Perl Guidelines

Tuesday, December 25, 2007

Prototype for Javascript

Prototype is a JavaScript Framework that aims to ease development of dynamic web applications.

To get into : prototypejs

Example code using prototype :
--------------------------------
1) Download prototypejs from : Download
2) Create a 'prototype_test.html' file from the prototype.js downloaded directory.
3) Paste the below code and save it.
<html>
<head><title>Prototype JS</title></head>
<body>
Alert using Prototype js
<script type="text/javascript" src="prototype.js"></script>
<script type="text/javascript" charset="utf-8">
Event.observe(window,"load",init,false);
function init() {
alert('Welcome to gubs! by prototype world');
}
</script>
</body>
</html>
4. Open the html file through browser.
5. You can see the alert which is triggered using prototype.js.

Template Toolkit

The Template Toolkit is a collection of Perl modules which implement a fast, flexible, powerful and extensible template processing system. It is most often used for generating dynamic web content, although it can be used equally well for processing any kind of text documents......

To get into Intro: Template Toolkit

To Start with template toolkit:
cpan> install Template

Instructions :

tt- template toolkit

1) Don't set "INTERPOLATE" constructor, while creating template new object.

2) All directives in TT should be in caps

eg:
[% BLOCK %]
------
------
[% END %]

3) To process a tt file include the filename in '<file_name.tt>'
[% PROCESS 'file.tt' %]

4) To process a block call it by block name
[%PROCESS %]

5) We can pass scalar, hash and array only through CGI to tt. :-) (Not to pass code reference or objects).

5) use SET to declare a variable in tt.

[% SET foo = 100 %]
[% foo %]

6) COMMENTS :
To give multi line comments, give # without giving space after [%

[%# sdjfkdnf
sdfkldjfkj
%]

To give a single comment
[% SET foo = 10 #Declaring the variable
%]

7)Ternary Operator allowed.

8) Use 'IN' instead of '=', while using for each syntax

9) Use 'FILTER' instead of '|'

Example Program with 'foo.tt' file:
--------------------------------
1. Create a 'foo.tt' file.

Dear [% name %],

It has come to our attention that your account is in
arrears to the sum of [% debt %].

Please settle your account before [% deadline %] or we
will be forced to revoke your Licence to Thrill.

The Management.

2. Paste the above text. Save & close 'foo.tt' file.
3. create a 'template_toolkit.pl' file from the same directory.
#!/usr/local/bin/perl
use strict;
use warnings;
use Template;

# To get more details
#http://template-toolkit.org/

my $tt = Template->new({
INCLUDE_PATH => '',
}) || die "$Template::ERROR\n";

my $vars = { name => 'Operative',
debt => '1 billion dollars',
deadline => 'next month',
};
$tt->process('foo.tt', $vars) || die $tt->error();

4. Paste the above code. Save & close 'template_toolkit.pl' file.
5. Run the Perl file. (perl template_toolkit.pl).

Output : Name substituted by 'Operative' and follows....

Linux Commands

Linux commands which is necessary to knew :
man, ls, locate, find, grep, tail, less, tar, scp, dpkg, which, crontab

To read the detail about commands :
man <command>

To view installed linux version in local system:
cat /etc/issue

About Crontab:
crontab - Schedule a command to run at a later time

Each line in the cron table follows the following format: 7 fields left to right
Field Meaning
1 Minute (0-59)
2 Hour (2-24)
3 Day of month (1-31)
4 Month (1-12, Jan, Feb, ...)
5 Day of week (0-6) 0=Sunday, 1=Monday ...or Sun, Mon, Tue, Wed, Thur, Fri
6 User that the command will run as
7 Command to execute

Example

Run /usr/bin/somecommand at 12.59 every day and supress the output (redirect to null)

59 12 * * * simon /usr/bin/somecommand >> /dev/null 2>&1

Fix bad sector problem in linux  '
http://www.howtogeek.com/howto/37659/the-beginners-guide-to-linux-disk-utilities/

List the partitions in your linux box using command below 
fdisk -l

diagnose the health of our hard disk (S.M.A.R.T System GUI tool does fsck task)

fsck (Before you run fsck do unmount on the paritition) 

sudo umount /dev/sdb (Replace /dev/sdb1 with your paritition)

This command checks an ext4 file system (/dev/sdb) for inconsistencies
sudo fsck -t ext4 /dev/sdb (Replace /dev/sdb1 with your paritition)

Bad blocks:
Badblock will give us the number of bad sectors in our hard disk.

sudo badblocks -v /dev/sdb1 (Replace /dev/sdb1 with your paritition)

Once you found bad blocks you have 2 options :
1. Buy a new hard disk
2. mark these bad blocks as unusable hard disk sectors

First we have to write the location of the bad sectors into a flat file.
sudo badblocks /dev/sdb > /home/zainul/bad-blocks

After that, we need to feed the flat file into the FSCK command to mark these bad sectors as ‘unusable’ sectors.
sudo fsck -l bad-blocks /dev/sdb 

Add-ons Firefox

Firefox Add-ons plugin:
Add-ons are small pieces of software that can add new features or tiny tweaks to your Firefox.

Firebug:
Firebug integrates with Firefox to put a wealth of development tools at your fingertips while you browse. You can edit, debug, and monitor CSS, HTML, and JavaScript live in any web page...

GreaseMonkey:
A User Script Manager for Firefox.

Selenium IDE:
Record, edit and play Selenium tests

Web Developer:
Adds a menu and toolbar with various web developer tools.

YSlow:
Make your pages faster with yahoo!'s performance lint tool

Useful stuffs in Perl

perltidy - Perl script indenter and reformatter.

pod2html - Convert .pod files to .html files

pod2text - Convert POD data to formatted ASCII text

podchecker - check the syntax of POD format documentation files

CPAN - We can download Perl modules from Comprehensive Perl Archive Network site.CPAN

Get and share your Perl knowledge from Perl Monks

To get more ideas about Perl from linux : man perl

To get into perl documentation : Perl Documentation

Perl Books
----------

Modules Used in our Application

To Get more detail : perldoc perldoc
To Get more detail about module : perldoc

Frequently Used Modules :

HTML::Template:
We used this module in each and every methods (runmode) of our CGI files. Our html designs will be in template format and named as .tmpl Using this module we parse the template file and substitute the data fetched from the db and returns html output to the view(Browser).

Mostly used special variables : filename, die_on_bad_params, loop_context_vars.
Tags used : <TMPL_VAR NAME="PARAMETER_NAME">, <TMPL_LOOP NAME="LOOP_NAME"> ... </TMPL_LOOP>, <TMPL_INCLUDE NAME="filename.tmpl">, <TMPL_IF NAME="PARAMETER_NAME"> ... </TMPL_IF>

CGI::Application:
This module is framework for Web-application. We used this module through out our CGI files to get the data from the browser etc...

Class::MethodMaker:
For the accessors and mutators(get and set), we used this module.

DBI:
To access the database(fetch and store) through our application, we used DBI module.

Data::Dumper:
To view the data structure of a particular variable, we used this module.

Time::Piece:
This module is used to get and set the time, and to get the time in user format we used Time::Piece.

Time::HiRes:
To get the time interval, we used this module.

Carp:
Die of errors, we used this module.

POSIX qw(ceil floor):
To get the ceil value and floor value.

Number::Format qw(:subs):
Format the numbering Number::Format we used.

File::Spec::Functions:
To perform portable operations on files we used this module.

Log::Log4perl:
This module is mainly for logging purpose. We have method (debug, info, warn, error, fatal).

HTML::Pager:
For CGI HTML paging this module will be very useful. We customized more in this module and you can find now in our application located path at "Denali::CGI::HTMLPager".

Denali::Message:
This module will be available only in our spark application. Module for generating user-visible messages.

Test::More:
This is another framework for writing test scripts. The rules which we were writing under business module and methods under the model scripts we need to validate and test using this module Test::More.

Functions mostly used : use_ok, require_ok, ok, is, isa_ok

Modules which used but not frequent :

Storable qw(nfreeze thaw):
To store an object in a table, instead to get a portable image we used this method nfreeze. To retrieve an object back from image we used the method thaw.

Getopt::Long:
Extended processing of command line options. Using this we can pass argument in command line, and we can fetch and use the arguments in our program.

UNIVERSAL qw( isa can ):
Base class for ALL classes. To check the given model name exists in the object we used 'isa', and to check given method name exists in the object we used 'can'.

Pod::Usage:
print a usage message from embedded pod documentation

XML::Simple:
To parse an XML and to get data structure of the XML.

MIME::Lite:
To send an email through SMTP. We customized and it will be now "Denali::Mail".

Time::Piece::Month:
To get next month and some other month details.

Time::Seconds:
To get the time in seconds.

DataTime:
To compare given dates.

HTTP::Request & HTTP::Response:
For the HTTP style request and response, we used this.

LWP::UserAgent:
For the dispatching of web request and response we used LWP::UserAgent. Constructors we used are cookie_jar, timeout.

URI::Escape:
Escape and unescape unsafe characters in the request and response. Function which used uri_escape().

XML::LibXML:
To validate XML data.

Friday, December 21, 2007

MVC

MVC - Model View Controller.
This is the architecture we used before SOA in our web application.

CPAN Modules which helps more to implement : CGI::Application and HTML::Template

View :
To view the html output page in our web application, we used to design our html designs in .tmpl extension. Javascript functions also includes with in this .tmpl. We included .css files also with in this .tmpl.

CGI :
Through CGI runmodes this HTML::Template .tmpl file will be parsed and corresponding data will fetch from the DB, using Model and pass the values to template and the html output will be return from this runmode.

Model :
This will contain methods having db operations. Like save(), find(), delete().

For assessor(getter) and mutator(setter) we used Class::MethodMaker module.
Denali::Model::Factory:

Denali::Model::Factory a generic base class for the existing Model class.
The existing model class a constant called TABLE_NAME will be declared,
so that can be used by the Denali::Model::Factory to build the getter and setter
method based upon all the fields for the given TABLE_NAME and the save,
delete and find method will make a call to Denali::DB and Denali::Find.

SOA

SOA - Service Oriented Architecture
In our Web Application, we implement Service Oriented Architecture. Service will be available to provide objects for the CGI Interface to get and display in view.

Below example SOA in CGI :
CGI:
If user enter text in the UI, get the inputs using CGI, Need to call the service by passing the parameter.

Service:
Service will get the parameter from any applications and if validation needs to do, then it call business method by passing parameters. If the validation returns true from business method then, this will proceed by finding object using model and set the attribute and save the data's into the table using model.

We can call service method to fetch the data too. This method will intern call model to fetch data from table and this get_service will return data to any application.

Business:
This will be call from service. This will get the input as parameter and based on the code written, validation or rules or logic it performs its action and it return the output.

Model:
This will be called under service or business. This will perform only fetching and saving operations into the table.

Direct query method will comes under the model.

Rules :
* CGI run modes can call only Service methods.
* CGI run modes can call many services methods.
* Even it's an single business rule, CGI run modes not allow to call. It should call via Service method.
* Service methods can call both Business methods and Model methods.
* Business methods can call only Model methods.
* Even business necessity to call service, it should not. Instead business method can call many business methods.

vim Editor Cusomization

.vimrc and customization

vim is extremely customizable. It will read the file .vimrc in your home directory before it starts. This file can contain settings and even scripts. The below settings are ones I've found helpful -- give them a try!

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=4
set shiftwidth=4

I prefer 4-space tabs to 8-space tabs. The first setting sets up 4-space tabs, and the second tells vi to use 4 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 guioptions-=T

I find the toolbar in the GUI version of vim (gvim) to be somewhat useless visual clutter. This option gets rid of the toolbar.
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 nohls

By default, search matches are highlighted. I find this annoying most of the time. This option turns off search highlighting. You can always turn it back on with :set hls.
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 syntax on
This will be useful while programming. It will show the correct syntax.

set paste
This will paste in the usual .vimrc mode.

Type :help options within vim to get a complete list of options.
// Below script tag for SyntaxHighLighter