How to upload files to Google Drive from linux, unix command prompt?

  • Check what version of unix you are using: uname -a
  • Visit and download respective ‘drive’ utility from:
  • wget the file.
  • Rename the file to drive using ‘mv ????? drive’
  • Set the correct file permission for ‘drive’, chmod 755 drive
  • Execute drive: ./drive
  • Visit the on-screen URL, obtain the code and paste into ‘drive’ program.
  • Use the following command to upload: drive upload -f <folder/file>
  • The upload happens in real-time on Google Drive.
facebooktwittergoogle plus


How install and use Xajax 0.6 beta 1 on Codeigniter 2.0+ ?

Do not use the 0.6 version on Github as it causes:

Warning: file_put_contents(K:DreamWebSitesxAjax/xajax_js/deferred/7b5d4816861867bcd00d0bc0466be45b.js) [function.file-put-contents]: failed to open stream: No such file or directory in K:DreamWebSitesxAjaxxajax_corexajaxPluginManager.inc.php on line 588


  1. Download and install Xajax 0.6 beta 1 from xajax-project.org
  2. move contents of xajax_core into application/libraries/
  3. rename xajax.inc.php to xajax.php
  4. put the xajax_js folder in root folder where CI is installed. (where the /application/ /system/ license.txt are)
  5. follow step 6 onwards from: http://www.gen.newrandom.com/2011/07/21/codeigniter-and-xajax-csrf-fix/
  6. You may skip 7 onwards if not using CSRF.
facebooktwittergoogle plus


How to convert seconds into days hours minutes in PHP? (Time elapsed, just now, ago)

Use example :

echo time_elapsed_string('2013-05-01 00:22:35');
echo time_elapsed_string('@1367367755');# timestamp input
echo time_elapsed_string('2013-05-01 00:22:35',true);

Input can be any supported date and time format.

Output :

4 months ago
4 months,2 weeks,3 days,1 hour,49 minutes,15 seconds ago

Function :

function time_elapsed_string($datetime, $full =false){
    $now =newDateTime;
    $ago =newDateTime($datetime);
    $diff = $now->diff($ago);

    $diff->w = floor($diff->d /7);
    $diff->d -= $diff->w *7;

    $string = array('y'=>'year','m'=>'month','w'=>'week','d'=>'day','h'=>'hour','i'=>'minute','s'=>'second',);foreach($string as $k =>&$v){if($diff->$k){
            $v = $diff->$k .' '. $v .($diff->$k >1?'s':'');}else{
            unset($string[$k]);}}if(!$full) $string = array_slice($string,0,1);return $string ? implode(', ', $string).' ago':'just now';}



facebooktwittergoogle plus


Best practice to log view hits to a page

The “correct” answer varies according to the situation; primarily the most desired statistic and the availability of resources to gather and process them: eg:

Server Side

Raw web server logs

All webservers have some facility to log requests. The trouble with them is that it requires a lot of processing to get meaningful data out and, for your example scenario, they won’t record application specific details; like whether or not the request was associated with a registered user.

This option won’t work for what you’re interested in.

File based application logs

The application programmer can apply custom code to the application to record the stuff you’re most interested in to a log file. This is similiar to the webserver log; except that it can be application aware and record things like the member making the request.

The programmers may also need to build scripts which extract from these logs the stuff you’re most interested. This option might be suited to a high traffic site with lots of disk space and sysadmins who know how to ensure the logs get rotated and pruned from the production servers before bad things happen.

Database based application logs

The application programmer can write custom code for the application which records every request in a database. This makes it relatively easy to run reports and makes the data instantly accessible. This solution incurs more system overhead at the time of each request so better suited to lesser traffic sites, or scenarios where the data is highly valued.

Client Side

Javascript postback

This is a consideration on top of the above options. Google analytics does this.

Each page includes some javascript code which tells the client to report back to the webserver that the page was viewed. The data might be recorded in a database, or written to file.

Has an strong advantage of improving accuracy in scenarios where impressions get lost due to heavy caching/proxying between the client and server.


Every time a request is received from someone who doesn’t present a cookie then you assume they’re new and record that hit as ‘anonymous’ and return a uniquely identifying cookie after they login. It depends on your application as to how accurate this proves. Some applications don’t lend themselves to caching so it will be quite accurate; others (high traffic) encourage caching which will reduce the accuracy. Obviously it’s not much use till they re-authenticate whenever they switch browsers/location.

What’s most interesting to you?

Then there’s the question of what statistics are important to you. For example, in some situations you’re keen to know:

  • how many times a page was viewed, period,
  • how many times a page was viewed, by a known user
  • how many of your known users have viewed a specific page

Thence you typically want to break it down into periods of time to see trending. Respectively:

  • are we getting more views from random people?
  • or we getting more views from registered users?
  • or has pretty much every one who is going to see the page now seen it?

So back to your question: best practice for “number of imprints when a user goes on a page”?

It depends on your application.

My guess is that you’re best off with a database backed application which records what is most interesting to your application and uses cookies to trace the member’s sessions.



facebooktwittergoogle plus