Monday, February 27, 2012

Which employee type are you ?

I cam across a nice article and loved to share it with you..

Employee "A" in a company walked up to his manager and asked what my job is for the day? The manager took "A" to the bank of a river and asked him to cross the river and reach the other side of the bank. "A" completed this task successfully and reported back to the manager about the completion of the task assigned. The manager smiled and said "GOOD JOB"

Next day Employee "B" reported to the same manager and asked him the job for the day. The manager assigned the same task as above to this person also. The Employee "B' before starting the task saw Employee "C" struggling in the river to reach the other side of the bank. He realized "C" has the same task. Now "B" not only crossed the river but also helped "C" to cross the river. "B" reported back to the manager and the manager smiled and said "VERY GOOD JOB"

The following day Employee "Q" reported to the same manager and asked him the job for the day. The manager assigned the same task again. Employee "Q" before starting the work did some home work and realized "A", "B" & "C" all has done this task before. He met them and understood how they performed. He realized that there is a need for a guide and training for doing this task. He sat first and wrote down the procedure for crossing the river, he documented the common mistakes people made, and tricks to do the task efficiently and effortlessly. Using the methodology he had written down he crossed the river and reported back to the manager along with documented procedure and training material. The manger said "Q" you have done an "EXCELLENT JOB".

The following day Employee "O' reported to the manager and asked him the job for the day. The manager assigned the same task again. "O" studied the procedure written down by "Q" and sat and thought about the whole task. He realized company is spending lot of money in getting this task completed. He decided not to cross the river, but sat and designed and implemented a bridge across the river and went back to his manager and said, "You no longer need to assign this task to any one". The manager smiled and said "Outstanding job 'O'. I am very proud of you."

What is the difference between A, B, Q & O? Many a times in life we get tasks to be done at home, at office, at play.,
Most of us end up doing what is expected out of us. Do we feel happy? Most probably yes. We would be often disappointed when the recognition is not meeting our expectation. Let us compare ourselves with "B". Helping someone else the problem often improves our own skills. There is an old proverb (I do not know the author) "learn to teach and teach to learn". From a company point of view "B" has demonstrated much better skills than "A" since one more task for the company is completed.

"Q" created knowledge base for the team. More often than not, we do the task assigned to us without checking history. Learning from other's mistake is the best way to improve efficiency. This knowledge creation for the team is of immense help. Re-usability reduces cost there by increases productivity of the team. "Q" demonstrated good "team-player" skills,

Now to the outstanding person, "O" made the task irrelevant; he created a Permanent Asset to the team.
If you notice B, Q and O all have demonstrated "team performance" over and above individual performance; they have also demonstrated a very invaluable characteristic known as "INITIATIVE".

Initiative pays of everywhere whether at work or at personal life. If you have initiative you will succeed. Initiative is a continual process and it never ends. This is because this year's achievement is next year's task. You cannot use the same success story every year. The story provides an instance of performance, where as measurement needs to be spread across at least 6-12 months. Consequently performance should be consistent and evenly spread. Out-of-Box thinkers are always premium and that is what everyone constantly looks out for. Initiative, Out-of-Box thinking and commitment are the stepping stone to success.

Initiative should be lifelong. Think of out of the box…..Happy Working

http://paradigmwisdom.blogspot.com/

Wednesday, November 23, 2011

Tips to optimize MySQL for better performance

I ave been working on my project www.edugoog.com and try to optimise queries. To do so I came through many articles. I gathered basic points from the same. Please find my finding below and feel free to add more in comments if missed.
  1. Don’t query columns you don’t need, avoid using SELECT * FROM
  2. Use caching to reduce database load
  3. Normalize tables to ensure data consistency
  4. Use persistent connections
  5. Proper use of indexes improve performance
  6. Do not perform calculations on an index (eg: if you have an index for a column called salary, do not perform calculation such as salary * 2 > 10000)
  7. “LOAD DATA INFILE” is the fastest way to insert data into MySQL database (20 times faster than normal inserts)
  8. Use INSERT LOW PRIORITY or INSERT DELAYED if you want to delay inserts from happening until the table is free
  9. Use TRUNCATE TABLE rather than DELETE FROM if you are deleting an entire table (DELETE FROM delete row by row, whereas TRUNCATE TABLE deletes all at once)
  10. Always use EXPLAIN to examine if your select query is inefficient
  11. Use OPTIMIZE TABLE to reclaim unused space (Note: Table will be locked during optimisation, so only do it during low traffic time)
  12. Better to have 10 quick queries than 1 slow one
  13. MySQL can search on prefix of indexes (ie: If you have index INDEX (a,b), you don’t need an index on (a))
  14. Don’t use HAVING when you can use WHERE
  15. Use numeric values (rather than alphabetical values) when performing a join
Thanks

Monday, August 8, 2011

Integrate and customize fckeditor with symfony

Till date, I always preferred tinymce rich text editor with symfony. But noticing that it does not provide inbuilt functionality for file uploading with browse.


After getting my hands burns on with plug-ins, I than moved to remove the tinymce and go with FCKEditor. Believe me it was worth opting for the later. Though it was not an easy task to get it work with symfony 1.4 but neither it was too hard if followed the basic steps.

Below are steps which provide me with perfect integration of fckEditor.

I am assuming, you already have fckeditor symfony plug-in and fckeditor js lib in your source code.

1: Copy and paste fckeditor_php5.php
           copy from projectName/web/js/fckeditor/fckeditor_php5.php TO projectName/lib/fckeditor_php5.php
2. save fckconfig.js as customconfig.js
           copy from projectName/web/js/fckeditor/fckconfig.js TO projectName/web/js/fckeditor/customconfig.js


Basically, you would have to make all your changes to customconfig.js and no change to fckconfig.js
Though it seems typical, I tried changing directly fckconfig.js but to no avail. It did not had any changes affected. :(


In customconfig.js
 1. to change the skin theme, FCKConfig.SkinPath = FCKConfig.BasePath + 'skins/silver/' ;
// there are 3 skins available. Default, silver and office2003
 2. To provide only required ToolbarSets, change appropriate changes to FCKConfig.ToolbarSets["Default"]
Mine is as below:

FCKConfig.ToolbarSets["Default"] = [
    ['Source','DocProps', 'Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'],
    ['Bold','Italic','Underline','StrikeThrough','-','Subscript','Superscript'],
    ['OrderedList','UnorderedList','-','Outdent','Indent','Blockquote','CreateDiv'],
    ['JustifyLeft','JustifyCenter','JustifyRight','JustifyFull'],
    ['Link','Unlink','Anchor'],
    ['Image','Flash','Table','Rule','Smiley','SpecialChar'],
    '/',
    ['Style','FontFormat','FontName','FontSize'],
    ['TextColor','BGColor'],
    ['FitWindow','ShowBlocks','-','About']        // No comma for the last row.
] ;
3. to allow fckeditor to submit data to the form set below config to false. If its set to true than no change in data would be send to serve.
FCKConfig.MsWebBrowserControlCompat = false ;
FCKConfig.PreventSubmitHandler = false ;


Now the final change:

Since we have change the config file from fckconfig.js to customconfig.js, we need to load the same js.
To change so, open fckeditor.html at     /js/fckeditor/editor/fckeditor.html
Change LoadScript( '../fckconfig.js' )  to LoadScript( '../customconfig.js' ) ;

For Symfony changes
Get the sfFCKEditorPlugin from here
install the plugin
Enable plugin from your config/ProjectConfiguration.class.php
$this->enablePlugins('sfFCKEditorPlugin');

Make the change in settings.yml in your modules directroy
all:
  .settings:
    rich_text_fck_js_dir: js/fckeditor

In the form.class, do the following for widget you need fckeditor:
$oFCKEditor = new sfWidgetFormFCKEditor(array('rows'=>50));
$this->setWidgets(array('Text'  =>  $oFCKEditor,));

This is it. Hope it helps.

For any concerns, feel free to mail me or post comments





Monday, July 18, 2011

How to set batch / cron jobs in symfony.

I cam across an instance, where i needed to set up the batch job for certain API which were getting information from 3rd party vendors on certain time intervals.
So I started to look for doing same with symfony 1.4 and doctrine.
Below are some of my findings and better ways to create the batch / cron jobs.

I will walk you through the steps in order to get it working properly.

Batch Instead of Web

Symfony has already set up to make it easy to create small controllers that will be run from the command line.

The “/batch” directory is where you will be putting your special controller file, instead of the “/web” directory.  This batch file is looks pretty much like the front controllers that go in the “web” directory. The only thing you will be leaving out is the dispatch method which starts running the controller and action. We are going to be replacing it with a line that still fires up the sfContext instance so that we have access to our database, etc.

Batch File:

  1. <?php
  2. // this file is saved as SF_PROJECT/batch/cron_example.php
  3. define('SF_ROOT_DIR', realpath(dirname(__FILE__).'/..'));
  4. define('SF_APP', 'frontend');
  5. define('SF_ENVIRONMENT', 'prod');
  6. define('SF_DEBUG', true);
  7. require_once(SF_ROOT_DIR.DIRECTORY_SEPARATOR.'apps'.DIRECTORY_SEPARATOR.SF_APP.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php');
  8. // get the application instance
  9. sfContext::getInstance();
  10. // put whatever code you need here…
  11. echo "\r\n running cron job….\r\n";
    Or  we can also set configuration from Project configuration file as below:

    require_once(dirname(__FILE__) . '/../config/ProjectConfiguration.class.php');
    $configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'dev', true);
    sfContext::createInstance($configuration);
 it’s similar to a standard front controller file. Now all you require is add code / function your cron job requires do.

Run through command prompt:
  1. go to your PROJECT_DEIRECTORY
  2. php batch/cron_example.php
  3. running cron job…
If you get the expected output, then everything is good to go.

The Crontab File

set up the cron to run every minute and output to null.
  1. * * * * * * php /home/me/my_project/batch/cron_example.php > /dev/null 2>&1
Hope it helps you. comment in case any issue/concern.

Monday, July 4, 2011

Fill up Select Box dynamically using Jquery and Ajax

To load the select box with dynamic option thorugh ajax,

you can use following function

function loadComponent(parentId){
        $.ajax({
            type: 'GET',
            url: '## YOUR URL##',
            data: 'id='+parentId,
            beforeSend: function(){
                options = '<option value="">Loading ..</option>';
                $("#DYNAMIC SELECTBOX ID##").html(options);
            },
            success: function( data ) {
                //alert(data);
                var arrObj = jQuery.parseJSON(data); // php response array as json_encode().
                options = '<option value="">select Component</option>';
                $.each(arrObj, function(index, obj) {
                    options += '<option value="' + obj.Id + '">' + obj.PrimaryName + '</option>';
                      // work with value
                });
                $("##DYNAMIC SELECTBOX ID##").html(options);
            }
        });
   }  

iterate array variable in jquery - foreach through jquery

I can across a issue, where i needed to access json response by ajax request.
json response was in array and needed to iterate through each of the records to display it in HTML.

for json response through php I did following
return json_encode($phpArray);

than in the ajax request on html template,
$.ajax({
            type: 'GET',
            url: ##YOURURL##,
            data: '##VARIABLE NAME##='+##VALUE##,
            success: function( jsondata ) {
              //  alert(jsondata);
                var arrObj = jQuery.parseJSON(
jsondata );
                $.each(arrObj, function(index, obj) {
         alert(obj.Id); // here id is any key index in array
         // work with value
       });

            }
        });


In my case, I needed to get the data and insert into an select options.

To create dynamic option for select box, please visit here

Tuesday, June 21, 2011

insert dynamic row in table using jquery

Today i came across a problem that requires to  add rows in table dynamically.

This can be done in an easy way with jquery, where as typical with writing all code in javascript.

hope it helps.

$('#buttonOrLinkId').click(function(){
$('#TableId tbody>tr:last').clone(true).insertAfter('#TableId tbody>tr:last');
});