Pagination for Laravel 4.1 | Working with Laravel Custom Pagination | Laravel 4.1 Pagination

Working with Laravel 4.1 pagination was not so difficult though the resource in internet is low rather than the Laravel 4.0. Up to day Laravel 4.1 has some inbuilt problem (which they are making correction) had given me some hard time, like with the static function. Anyway I recovered them and lets talk about how we can manage the custom pagination with Laravel 4.1.

We will be using “paginate” method with Eloquent model or the Query Builder. We will be using Laravels “Paginator” class which has a “make” method which allow us to create the custom pagination. Oh, one thing, if you guys are using simple raw mysql queries its the high time that you should change it to a ORM. I will discuss the usefulness of ORM on another post, but, briefly it allows you to change the db frequently, gives you more handle to relational database, gives you more power to accumulate things shortly as they have lots of method to help you out to save your raw coding of sql’s. For example you want to find all the data of the table, and its very simple like $table->;find(), almost every ORM has method like this. Eloquent is one of the easiest ORM I have seen so far. Lets come to the point how we can do it icon smile Pagination for Laravel 4.1 | Working with Laravel Custom Pagination | Laravel 4.1 Pagination

In my case I am giving example of a contact table where all table information should in paginated form. To achieve this we will create a new method in my Contact repository. The code sample is like bellow.

* Getting the contacts as paginated
* Get results by page
* @param int $page
* @param int $limit
* @return StdClass
public function getByPage($page = 1, $limit = 10){
    $results = new StdClass;
    $results->page = $page;
    $results->limit = $limit;
    $results->totalItems = 0;
    $results->items = array();
    $contacts = Contact::skip($limit * ($page - 1))
    $totalCont = Contact::all()->count();
    $results->totalItems = $totalCont;
    $results->items = $contacts->all();  
    return $results;

Now in your controller call the getByPage method and make the pagination. The code should be as follows

* Function to list contacts
* @author Zea
* @version 0.1
* @copyright iVive Labs
* @access pulic
* @param optional pagination-> page, limit
* @return contacts
public function listContact(){
    $page = Input::get('page', 1);
    $limit = Input::get('limit', 10);
    $contact = new Contact;  // correct
    $data = $contact->getByPage($page, $limit);
    $contacts = Paginator::make($data->items, $data->totalItems, $limit);      

    foreach ($contacts->getCollection() as $key => $contact){
        $explode_contact[$key]= array (
            'id' => $contact->id,
            'name' => $contact->name,
            'street' => $contact->street,
            'zipcode' => $contact->zipcode,
            'city' => $contact->city
    $explode_contact['paging'] = (array("page"=>$contacts->getCurrentPage(),"pageSize" =>$contacts->count(), "pageCount"=>ceil($contacts->getTotal()/$contacts->getPerPage()),"total"=>$contacts->getTotal()));
    $explode_contact['success'] = true;
    return json_encode($explode_contact);

I guess it will solve the pagination things with Laravel 4.1

The Paginator class has lots of methods for creating the pagination. Some useful ones are as follows:


There are more methods over there, you can check it by this link.

Create Virtual host in Linux : ubuntu for running any standalone application like angularjs in appache

Suppose you want to make a virtual host on port 8090, you need to create a virtual host. You can do it for appache. The interesting part is you dont need to put your web directory in /var/www. You can point it in anaywhere of you drive. Which might help you to standalone app for an angularjs project. Just follow the steps.

1. Go to site-available directory, it is symlinked to site-enabled. It is located to

cd /etc/apache2/sites-available

2. Create a virtual host, say named “msdrg” and put the following lines over there. You can do it just by nano.


sudo nano msdrg

b. paste the following lines over there, suppose I have my app msdrg in my home directory

<VirtualHost *:80>
        DocumentRoot /home/zea/msdrg
        <Directory /home/zea/msdrg/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all


note that I have named the servername as And I will get by this name in browser

3. save it by ctrl+x and run

sudo a2ensite msdrg

4. Reload you apache

sudo service apaceh2 reload

5. Just one more thing to do which is add the server name in your host which located at etc directory.

sudo nano /etc/hosts

you will find your localhost and other hosts. just add your new servername as host there

thats it, save it by pressing ctrl+x and exit. Go to your browser and type, it will load whatever you have in your msdrg dircetory.

Some Google services/products are unavailable for IPs block: Youtube, google drive or other services/products are sometimes unavailable from different Ip

Youtube, google drive or other services/products are sometimes unavailable from different Ips of isps. Reason is explained bellow is taken from arez afsar from his facebook status.

Youtube is one of the Google Inc. utilities or services. The Youtube website’s IP addresses assigned are the IPs of Google services. To block Youtube, BTRC might have obstructed a percentage of the common IPs of Youtube that are discovered officially or formally, worldwide. A tremendous and huge site like Youtube can have some countless IP addresses to run and send its data to a few million users during that timeframe. It might have mirror sites excessively assigned for every region. When we type the DNS server of your ISP converts the name into an IP address appropriate for the region, country, etc.

Here, BTRC has blocked these range of IPs which are used to fetch the site data from the hosting server – the only IPs that are permanently been used by Youtube. The thing is, as Youtube is currently an services of Google, accordingly, the IPs assigned to youtube are also utilized for other Google services like Gmail, Google Drive and so on. Assuming that you can review, when Youtube was blocked without precedent in our nation, individuals confronted situation loading their Gmail too in light of the fact that BTRC had it blocked inadvertently as the aforementioned IPs might have been utilized for Youtube officially as its a Google service. Notwithstanding, that thing is altered. A few of us off and on again ready to see or open Youtube just when the IP is in the recorded IPs of Google services. This is same for google ads and any other services that you use. In many of my sites who have google adsense, ads, analytics or some other services from google dosent load in my home IP time to time but runs well in my office.

Still some folks see lapse posts and cant watch the videos legitimately. This is for the reason that, blocking a site is not just blocking the IP addresses. There are other filtering methods as well. A straightforward sample could be, filtering with diverse decisive words i.e. a common sensation at NSU, we cannot even find the saying “music” in while gaining entrance to with laptop WIFI as the network administrator of NSU has put the “music” word in the routers’ block channels.

So now and then regardless of the possibility that the site burdens you can and at times you cannot view videos on Youtube. There are numerous different demonstrations also.

Cheerful Browsing…. icon biggrin Some Google services/products are unavailable for IPs block: Youtube, google drive or other services/products are sometimes unavailable from different Ip

Facebook Graph Search Beta

Facebook Graph Search is another way of system for you to find friends, places, photographs and engages that are for the most part significant to you. Graph Search encourages you to find alternates quickly,  make connections, explore photos, quickly find places like local attractions and restaurants, and learn about common interests like music, movies, books and more.  All results are unique based on the strength of relationships and connections.With Graph Search, you can search for individuals, photographs, places and interests. Type your search into the blue bar at the top of the page. As you begin to sort, prescriptions show up in a drop down. You can refine your search utilizing the tools on the right-hand side of the page.

Some example for Facebook Graph Search:

· People who like tennis and live adjacent
· Photos before 1990
· Photos of my companions in New York
· Sushi restaurants in Palo Alto my companions have loved
· Tourist magnetisms in Italy went to by my associates

Screenshot PeopleWhoLikeThingsILike Facebook Graph Search Beta

Facebook Graph Search is in a restricted snapshot, or beta. That means Graph Search could just be accessible to an extremely modest number of friends who utilize Facebook as a part of US English.You can join the waitlist at No. Diagram Search accompanies your flow protection settings. You can just scan for substance that has been shared to you. To control tags, photographs or posts with areas about you that show up in inquiry, head off to your Activity Log.

Facebook’s mission is to make the planet more open and joined. The essential way we do this is by giving people the tools to guide out their associations with the people and things they want to think about. We call this guide the graph. It’s colossal and un-varyingly unfolding with revamped people, content and connections. There are presently more than a billion people, more than 240 billion photos and more than a trillion connections.

Today we’re proclaiming another course to go these connections and make them more of service. We’re calling it Graph Search, and it begins today with a restrained preview, or beta.

At the point that Facebook first started, the prevailing way most people utilized the locale was to search around, study about people and make revamped connections. Graph Search takes us back to our roots and permits people to utilize the graph to make revamped connections.

Graph Search will show up as a more gigantic search bar at the top of every page. At the point that you search for something, that search not just figures out the set of effects you get, and yet serves as a title for the page. You can alter the title – and in doing so make your particular convention perspective of the substance you and your friends have imparted on Facebook.

Graph Search and network search are exceptionally diverse. Net search is composed to take a set of decisive words for instance: “hip jump”) and give the best conceivable comes about that match the previously mentioned pivotal words. With Graph Search you join together statements for instance: “my friends in New York who like Jay-Z”) to get that set of people, places, photos or other substance that is been imparted on Facebook. We accept they have extremely distinctive employments.

A different huge distinction from net search is that each bit of substance on Facebook has its particular gathering of people, and most substance isn’t popular. We’ve manufactured Graph Search from the begin in view of protection, and it regards the security and gathering of people of every bit of substance on Facebook. It makes finding unique things much more straightforward, yet you can just see what you might as of now see somewhere else on Facebook.

We’re exceptionally promptly in the infrastructure of Graph Search. It’s sole ready in English today and you can search for just a subset of substance on Facebook. Posts and Open Graph movements for instance, tune listens are not yet ready. We’ll be taking on these things over the impending months.

The primary variant of Graph Search centers on four fundamental zones –people, photos, places, and interests.

    • People: “friends who exist in my city,” “people from my hometown who like iVivelabs,” “friends of friends who have been to Yosemite National Park,” “programming designers who exist in San Francisco and like skiing,” “people who like things I like,” “people who like tennis and live close-by”


    • Photos: “Photos I like,” “photos of my family,” “photos of my friends before 1999,” “photos of my friends taken in New York,” “photos of the Eiffel Tower”


    • Places: “restaurants in San Francisco,” “urban areas went by my family,” “Indian restaurants liked by my friends from India,” “vacation spots in Italy went by my friends,” “restaurants in New York liked by lead cooks,” “nations my friends have gone to”


    • Interests: “Gadgets products like by close friends”, “music my friends like,” “motion pictures liked by people who like films I like,” “dialects my friends articulate,” “method amusements played by friends of my friends,” “motion pictures liked by people who are picture heads,” “books peruse by CEOs”


  • Videos: “video of  attraction and landmark in New York”

The Graph Search beta begins today. Head off to to get on the waitlist.

The roll out is setting off to be abate so we can see how people use Graph Search and make upgrades.

Additional Media Resources:
To learn more about How Graph Search work, go to
To learn about Graph Search and privacy, go to
To learn more on how Graph Search was built, click here.
To download a behind the scenes video, click here.
For a collection of screen shots, click here.
For how Graph Search can help people discover your business, visit Facebook Studio.

MPTT — Managing Hierarchical Data in Mysql

For a hierarchical table which has depth more than 3 is a tough one to fetch data and show it. And for a bigger table its near to impossible to fetch. It will give you time out. Even if you manage the time the application will be slower. Let me give an example. Suppose you have a region table which have got 4 level of depth and has data about only 100 rows. The levels are State, City, Town, Area. So to show it hierarchically you will have to loop all the data, for this case it will 4 loops which is 100*100*100*100 = 100000000, you might lesser it a bit by some breaks but still it is a n^3 times algorithm which will slow your system definitely and crash your system eventually.

So there is a technique which is called MPTT — modified preordered tree traversal algorithm for multiple depth search or to search hierarchical data. Its a very simple technique where the table in our case the region table is ordered accordingly and serve before the fetch. This technique reminds me the concept of set while I was in grade 8.

 MPTT    Managing Hierarchical Data in Mysql

From the above image you can see

New York State has the range from 1 – 8
New York City has the range from 2 – 7
Manhattan has the range from 3 – 6
Midtown has the range from 4 – 5

Similarly if you have more city or town you need to add them up and whole range would be larger then, for instance if you add two other city Long Island and Columbia then the range should be

New York State has the range from 1 – 12
New York City has the range from 2 – 7
Manhattan has the range from 3 – 6
Midtown has the range from 4 – 5
Long Island has the range from 8 – 9
Columbia has the range from 10 – 11

And you have to make the data base like this. Here we will use the left and right column for the range. Like for new york city the left column should be 2 and the right is 7. Every other rows should have the same thing. Now as I have used symfony2 with doctrine 2.2 with dql I will show how you can generate the full tree

 public function crossJoin(){

 $q = $this->_em->createQuery("
SELECT, node.regionId, node.regionName
FROM ViveZeaBundle:RegionRedefines AS node,
ViveZeaBundle:RegionRedefines AS parent
WHERE node.lft BETWEEN parent.lft AND parent.rgt
GROUP BY node.regionId
ORDER BY node.lft  ");
return $q->getResult();


Now in my controller I call it and I have used jquery tree to show it.

$tree = $em->getRepository("ViveZeaBundle:RegionRedefines")->crossJoin();
$result = '';
foreach ($tree as $node) {
foreach($tree as $traceTree){
if($traceTree['hierarchyId'] == $node['regionId']){
$node_depth = $node['depth'];
$node_name = $node['regionName'];
if ($node_depth == $current_depth) {
if ($counter > 0)
$result .= '';

elseif ($node_depth > $current_depth) {
$result .= ”, $current_depth – $node_depth) . ”;
$current_depth = $current_depth – ($current_depth – $node_depth);

$result .= ‘<li ‘; if($trace_last_node!=””){ if($catName!=””) $tit = $catName.”-in-”.$node['regionName']; else $tit = $node['regionName'];              $tit = preg_replace(“/[^a-zA-Z0-9\/ _-]/”, ”, $tit); $tit = str_replace(‘ ‘,’-’, ucwords($tit)); $tit = str_replace(‘–’,’-’,$tit); $result .= ‘class = “expandable”‘;

$result .=$basePath.’/’.$tit.’/’.$categoryId.’/’.$node['regionId'].’/0/ $node_name . ”;

$tit = $catName.”-in-”.$node['regionName'];
$tit = $node['regionName'];
$result .=$basePath.’/’.$tit.’/’.$categoryId.’/’.$node['regionId'].’/0/ $node_name . ”;
$temp = ” . $node_name . ‘ ‘;
$result .= str_repeat(”, $node_depth) . ”;
$result .= ”;

Now just return the result.

Install / setup Symfony 2 windows xp windows 7 windows 8

Symfony 2 install / setup for window xp, windows 7 or windows 8 is lot easier than installing the symfony 1.* especially 1.4 version. Follow the steps how to install or setup it.

Step 1. Go to and download symfony 2.* version and unpack it. I used 7zip to unpack it. In my case I had to extract twice the file and got a folder named Symfony. Which I copied to my htdocs folder. in my case it is d:/xampp/htdocs

Step 2. Install Composer. I did it by the command

php -r "eval('?&gt;'.file_get_contents(''));"
for this you need to go to your command prompt and if the php environmental variable is not set then you have go to the php directory and run the above command. In my case it is d:/xampp/php. You might get error for 'https' if it arises just type the following command in commandprompt
<code>php -r "eval('?&gt;'.file_get_contents(''));"

Step 3. Its almost done the installing part. just for checking run php


for my case it is

D:\xampp\php&gt;php d:/xampp/htdocs/Symfony/app/check.php

. There might be some warnings but you can correct them later.

WordPress having .htaccess permalink problem – page shows 404

I got a serious problem while changing pemalink style in admin settings of wordpress site. It was showing 404 for every posts/pages accept the home page. I really dont know what would be the solution. My dear fellow colouge Russel Vai helped me to solve this problem. The problem was with the .htaccess file in base path. So if this problem arrise first check the base path in .htaccess file. Though we figured it out later. We did some other process earlier and got it right. We first took a backup of the .htaccess file and deleted it from the server with ftp. Then we set the permalink in default mode and changed to it to my desired custom mood later. And it returns the posts/page which shows 404 to actual content. What it did actually it regenarate the .htaccess file automatically while changing the permalinks type in admin panel.

Ruby – Problem while scaffold – routes.rb needs to have the action name

I got a serious problem when scaffold in ruby and couldn’t get the route working with different action rather than auto generated actions. I had controller name search and action zea. It was working fine while I hit it. But while create an action named nokogiri, it wasnt working. I searched it to google and stackoverflow with ruby – problem with routes.rb in scaffold and got some results. It suggested to add a line in routes.rb

get "searches/nokogiri"

But it wasnt working simply because of the serialized sequence of the line of code for custom action. it was previously

resources :searches
  get "searches/nokogiri"

But it should be

get "searches/nokogiri"
resources :searches

get should be before resources, It is working fine right now.

Ruby on Rails common Command / Instruction

Following are some common command / instruction that I have been using last 15 days as new ruby on rails developer.

1. To check Ruby Version

ruby -v

2. To create new rails project

rails new projectName

3. To start rails server

rails server


rails s

4. To generate model or controller

rails generate controller controllerName
rails generate model modelName

you can see the  what generate can do by the command

rails generate

. it will show like this


5. To create db or migrate db

rake db:create
rake db:migrate

6. You can also generate migration

rails generate migration migrationName

7. To go to db version or migrate to a version

rake db:migrate VERSION=version_number

8.Run server on different port

rails server -e development -p 3001

Bug Protein USB Flash drives reaches 50 terabyte (TB)

A sample USB drive / Flash drive size of 50 terabytes (TB) worth of data could will be in the market using bug protein memory to store data in less than one and half years. Professor V Renugopalakrishnan of the Harvard Medical School in Boston’s initial thought was to start out by coating DVDs with a layer of protein so that one day solid state memory could grasp so much information that the storing data on conventional computer hard drive will be outdated.

USB drive

Flash drive

USB flash drives

usb drive

50 TB Flash drives USB drives

50 TB Modern Flash drives USB drives

Flash drives

USB flash drives


usb drives

flash drive

usb drive

flash drive

50 TB Modern Flash drives USB drives

Flash drives

USB flash drives

usb drives


 Bug Protein USB Flash drives reaches 50 terabyte (TB)

Bug protein memory USB flash drive

Ultimately it will remove the need for hard drive memory completely. This is the future of flash memory. High-capacity storage devices like the new protein-based DVDs will be crucial to the defense, medical and entertainment industries. Transfer of information such as satellite images, imaging scans and movies will be traded in with terabytes of information. Magnetic storage technology will not serve the persuasive demand of storing data.

New protein-based DVD will have advantages over recent optical storage devices (like the Blue-ray). It will be able to store no less than 20 times more than the Blue-ray and sooner or later even up to 50,000 gigabytes (about 50 terabytes) of information. The first protein-based information storage structure to store terabytes of information is made of Membrane proteins. The star at the centre of the high-capacity DVD is nothing but a light-activated protein situated in the membrane of a salt marsh microbe Halobacterium salinarum. This protein is named as bacterio rhodopsin (bR), captures and stores sunlight to convert it to chemical energy.

Sunlight on bR converts a series of intermediate molecules each with a distinctive shape and color before returning to its ‘ground state’ (as zero). It is only for some hours or at most a day that the intermediates generally last. But modified DNA that produces bR protein is to create an intermediate that lasts for more than several years, which is a building block to store data for a binary system. Any of the intermediates can be ‘one’ and ground state surely is the ‘zero’. BR protein is engineered to make its intermediates more stable and durable at the high temperatures generated by storing terabytes of data.

The opposite site of the coin is modern technology flash drive like this  is so portable that wrong hands will be easily broadcast the large amounts of information with this new technology flash drives or pen drives. Fortunately or unfortunately science can be used or abused. Data can be stolen very quickly by this flashdrives. One has to have some safeguards or protection there. In conclusion with NEC in Japan, Renugopalakrishnan’s team has estimated a USB flash drive will be in the market in 12 months and a DVD in 18 to 24 months. The work has been funded by a range of US military, government, academic institutions and commercial companies, as well as the European Union.
Source: ABC News Australia