Thursday, 24 July 2014

Twig Complete reference




- Developed By :  Fabien Potencier.

- Rquirements : PHP5.2.4

- Functionality : Twig parses templates and then outputs the result.

- Advantages:
    1) However, you can speed up the whole process by caching the compiled version in the form of plan PHP files to reduce the overhead.
    2) The framework is extensible, meaning that in case something you need is missing, you can create your own language constructs.

Installing the Twig:
----------------------------------

- Install the twig via Composer. The most common and recommended way is via Composer.
- Create the folder in your working directory

    Ex: $ mkdir work/twigtests

- If you are not installed the composer

    Run this in your terminal to get the latest Composer version:

    $ curl -sS https://getcomposer.org/installer | php
   
    Reference: https://getcomposer.org/download/

    Out put :
          #!/usr/bin/env php
      All settings correct for using Composer
      Downloading...
      Composer successfully installed to: /home/yanju/work/twigtests/composer.phar
      Use it: php composer.phar

- Next, step is to install the twig by the composer using following command.

    $ php composer.phar require "twig/twig:1.*"
    Out put:
        ./composer.json has been updated
        Loading composer repositories with package information
        Updating dependencies (including require-dev)
        - Installing twig/twig (v1.16.0)
            Loading from cache

        Writing lock file
        Generating autoload files

 In this step your successfully genereated the autoload file.

Twig Tutorials: -
-------------------------

    You want to very familiar about the twig concepts to build the templates.
    For Reference please find the following link.

        http://twig.sensiolabs.org/doc/intro.html ( or )
        http://twig.sensiolabs.org/pdf/Twig.pdf

Create a Sample Template :
-------------------------------------------------

    Create the 2 directories as templates, cache in your application directoy. In this example twigtests is the application directory

        $ mkdir work/twigtests/templates
        $ mkdir work/twigtests/cache

    give the write permissions on cache directory.

        $ sudo chmod -R 0777 /cache/twig

    and switch to the folder templates and create the 1 twig template and add some code. I done with the following code.

        {# I'm a comment and these are some examples #}

        {# Evaluates the variable bookTitle and print the result inside an h1  #}
        <h1>{{ bookTitle }}</h1>

        {# Evaluates the expression composed of the authorName variable and the string " De Rosa", concatenated by the "~" character #}
        <h2>{{ authorName ~ " De Rosa" }}</h2>

        {# Evaluates the variable count and change the resulting template accordingly #}
        {% if count < 1000 %}
           <p>This is a good book</p>
        {% else %}
           <p>This is a best seller</p>
        {% endif %}



How to load and show a template :
---------------------------------------------------------------
    Change the directory to your working directory and create the file as test1.php

        $ vi test1.php

    Remove everything inside and add this line to the top:

        <?php require_once '../vendor/autoload.php'; ?>

    With this line, we load the Composer autoloader which in turn loads Twig.
   
    If you installed Twig some other way, you’ll have to require the Twig autoloader directly:

        require_once '/path/to/lib/Twig/Autoloader.php';
        Twig_Autoloader::register();


    Now you want to initialize the twig :

        $twig = new Twig_Environment(
            new Twig_Loader_Filesystem('templates/'), array(
                      'cache' => 'cache/twig/',
                      'auto_reload' => true,
                      'strict_variables' => true
              )
        );


    The last step is to load the template and then render it, passing in the required variables.
    To load a template you have to call the loadTemplate() method and pass the path of the template as a parameter.

        $template = $twig->loadTemplate('test1.twig');
        echo $template->render(array('bookTitle' => 'Instant jQuery Selectors', 'bookAuthor' => 'Aurelio De Rosa'));


    or
        $twig->display('test1.twig', array('bookTitle' => 'Instant jQuery Selectors', 'bookAuthor' => 'Aurelio De Rosa'));

Tuesday, 22 July 2014

Compress the JS/CSS files using yui-compressor in Ubuntu


Hi,
   In this post i am showing how to compress the js as well as css file using yui-compressor.

Step 1: Install the YUI-COMPRESSOR.
         
 You can install the yui-compressor using a simple command

$ sudo apt-get install yui-compressor

or

You can directly install from the Ubuntu Software center by searching by yui-compressor 

Step 2: 
You can minify the CSS files by using the following command

 $ yui-compressor --type css -o main-min.css main.css

If you have to minify more files use the following command

$ yui-compressor --type css -o main-min.css file1.css file2.css


Similarly you can minify the JS files as follows

$ yui-compressor --type js -o main-min.js main.js


If you want know more about the Yui-compressor try the following command
$ yui-compressor -help



Tuesday, 11 February 2014

git commands (Git tutorials)

git commands (Git tutorials)
-----------------------------------

* git init - To inintialize the git repository
* git status -  Checking the Status
* git add somefilename.txt - To add the files into repository (Adding Changes)
* git commit -m "Add cute octocat story" - to commit the file changes into repository
* git log - To view the logs
* git remote add origin https://github.com/try-git/try_git.git - to add the files from the remote URL.
* git push -u origin master -
* git diff HEAD - To check the difference
* git add octofamily/octodog.txt - To check the changes with file alredy been staged.
* git diff --staged    -  go ahead and run git diff with the --staged option to see the changes you just staged
* git reset octofamily/octodog.txt - Resetting the stage
* git checkout -- octocat.txt - to check out the branch
* git rm '*.txt' - to remove all the files
* git checkout master - Switching back to master
* git merge clean_up - Merge with the branch
* git branch -d clean_up - to delete the branch

Saturday, 8 February 2014

UI Developer should know this Must.

What is the Main differnce Put Stylesheets at the Top(head tag) and Put Scripts at the Bottom (other than head tag)?

What is the Main differnce Put JS script at the Top(head tag) and Put Scripts at the Bottom (other than head tag)?

Put Stylesheets at the Top

tag: css
If you put style sheets to the document HEAD makes pages appear to be loading faster. This is because putting stylesheets in the HEAD allows the page to render progressively.
Front-end engineers that care about performance want a page to load progressively; that is, we want the browser to display whatever content it has as soon as possible. This is especially important for pages with a lot of content and for users on slower Internet connections. The importance of giving users visual feedback, such as progress indicators, has been well researched and documented. In our case the HTML page is the progress indicator! When the browser loads the page progressively the header, the navigation bar, the logo at the top, etc. all serve as visual feedback for the user who is waiting for the page. This improves the overall user experience.
The problem with putting style sheets near the bottom of the document is that it prohibits progressive rendering in many browsers, including Internet Explorer. These browsers block rendering to avoid having to redraw elements of the page if their styles change. The user is stuck viewing a blank white page.
The HTML specification clearly states that stylesheets are to be included in the HEAD of the page: "Unlike A, [LINK] may only appear in the HEAD section of a document, although it may appear any number of times." Neither of the alternatives, the blank white screen or flash of unstyled content, are worth the risk. The optimal solution is to follow the HTML specification and load your stylesheets in the document HEAD.

Put Scripts at the Bottom

tag: javascript
The problem caused by scripts is that they block parallel downloads. The HTTP/1.1 specification suggests that browsers download no more than two components in parallel per hostname. If you serve your images from multiple hostnames, you can get more than two downloads to occur in parallel. While a script is downloading, however, the browser won't start any other downloads, even on different hostnames.
In some situations it's not easy to move scripts to the bottom. If, for example, the script uses document.write to insert part of the page's content, it can't be moved lower in the page. There might also be scoping issues. In many cases, there are ways to workaround these situations.
An alternative suggestion that often comes up is to use deferred scripts. The DEFER attribute indicates that the script does not contain document.write, and is a clue to browsers that they can continue rendering. Unfortunately, Firefox doesn't support the DEFER attribute. In Internet Explorer, the script may be deferred, but not as much as desired. If a script can be deferred, it can also be moved to the bottom of the page. That will make your web pages load faster.

Tuesday, 10 December 2013

What is a DAA File?
Did you find a DAA file on your computer and wonder what program should open it? Maybe someone emailed you a DAA file but you're not sure how to use it. Perhaps you tried to open the DAA file but Windows told you that it could not open it.
Before you can open a DAA file (assuming it's even a file format that's intended to be viewed or edited), you'll need to determine what kind of file the .DAA file extension refers to.

Download & Install http://www.poweriso.com/download.htm


Extract DAA File
  • Run PowerISO.
  • Choose "File > Open" menu or click on the "Open" button on toolbar to open an daa file.
  • Select files and directories you want to extract.
  • Click on the "Extract" button to open DAA extractor dialog.
  • Choose the destination directory.
  • If you want to extract all files, you should select "All files" option.
  • Click on the "OK" button to extract daa file to selected folder.

Friday, 6 December 2013

Interview Tips

Interviews are lost, not because of lack of technical skills, but lack of "Positive Attitude". 

Shiv Khera (Leading speaker of the world) Says:

"85% of the time, a candidate gets promotion of wins an interview just because of right attitude and only 15% matters how technically sound a candidate is" - I totally agree with him !!

Few things which interviewers hate in candidates during interviews !

1. Candidates by-heart-ing the "What is" concepts rather understanding "Why is" concepts.
Example:What is the size of an empty class in C++ ? Easy 
Why is the size of an empty class generally 1 byte? 

2. Faking their identity. Example: Acting to be very innocent, Not being natural. This shows what is your real identity.

3. Very poor communication skills. It does not mean, having sound knowledge in English. It means candidate lack the "quality of convincing others"

4. Giving reasons/blaming others for not knowing the right answers. Example: This was not in my syllabus, my teacher did not teach this concept, my university syllabus is not upto the mark, "I am not from computer science background, so do not ask me questions related to programming languages" etc.

5. Not showing any learning attitude. Always want ready-made answers.

6. Given a question, a candidate should take time and solve it. But few candidates don't even bother to solve it on paper. They don't make their brains work. They just say "No, I don't know the answer". This really irritates the interviewer.

7. And many more ....

Interview cracking is an ART !! But, just mastering the ART requires actual knowledge !!

Monday, 25 November 2013

Installing JMeter on Windows

Downloading & Installing JMeter on Windows

Now finally we will learn from where we should download JMeter and how to install it on your local Windows Machine.
But before that, we should know what are the basic requirements for installing JMeter and to run it on your local windows machine.

JMeter Requirements 

JMeter requires your computing environment meets some minimum requirements.

Java Version

• JMeter requires a fully compliant JVM 1.4 or higher.

• Version 2.2 and later no longer support Java 1.3.

• It is recommended to use JVM 1.5 to conduct HTTPS test with JMeter.

Operating System

• JMeter is a 100% Java application and should run correctly on any system that
has a compliant Java implementation.

• JMeter has been tested and works under:

• Unix (Solaris, Linux, Fedora etc)

• Windows (98, NT, XP, etc)

• OpenVMS Alpha 7.3+


Downloading and Installing JMeter

Jmeter is a Java application, so a JRE or SDK first needs to be installed with a JAVA_HOME environment variable.
Jmeter can be downloaded in the below link:


• Download Jmeter, and install by unzipping the .zip or .tgz file in any directory.
• Go to jakarta-jmeter Directory (Directory in which the .zip of .tgz file is unzipped)
• Type ./bin/jmeter on command prompt(for Unix) or Run bin/jmeter.bat (for Windows)
• JMeter is ready to test application.

When you run jmeter.bat file in bin directory of  jakarta-jmeter Directory, you will see the following JMeter Screen.

The user interface has two panes. The left pane displays the elements used in our testing. Initially, there are the Root and two sub-elements, Test Plan and WorkBench.
In this article we're only concerned with Test Plans. Add an element to a node by right-clicking it and selecting Add. To remove an element, select the element by clicking on it, then right-click on the element and choose the Remove option.

Test Plan: A test plan describes a series of steps JMeter will execute when run. A complete test plan will consist of one or more Thread Groups, logic conrollers, sample generating controllers, listeners, timers, assertions, and configuration elements.

WorkBench: Workbench is place where we store test elements which are saved and used in later stages. It has two elements which are HTTP proxy server and HTTP mirror server. Http proxy server is used for recording purpose.
To use it right click on workbench  then select Add --> Non-Test Elements --> HTTP Proxy Server.

This is how we install and run JMeter in windows.
I think its quite easy to download and install JMeter and even more if you get such stuffs which does your work more simpler.