Friday, 4 April 2014

To add to one GIT repository to another repository on same machine

Well, what I have done here is I have development and production repositories on my PC which were exclusively linked to their own GitHub repositories.

Now, I would like to update my production repo from development locally and push back to production repository on GitHub.

And here is my commands;

# Go to local "production" repo
 
$ cd project.production/  
RC@MyPC-001 /c/xampp/htdocs/project.production (master)

$ git remote add development /c/xampp/htdocs/hillingdon/dev.hcp.branch
RC@MyPC-001 /c/xampp/htdocs/project.production (master)

$ git fetch development

$ git merge development/
development/forum-devt   development/master // This is because I had two branch on my development repo

$ git merge development/master // I am merging the master branch only

// If you got any conflicts, please resolve them and add them all
 
$ git add --all 

SSH/SCP commands to/from remote server in window/Linux

Syntax for Secure Copy (scp) via HTTP

What is Secure Copy?

scp allows files to be copied to, from, or between different hosts. It uses ssh for data transfer and provides the same authentication and same level of security as ssh.

Examples

Copy the file "foobar.txt" from a remote host to the local host

$ scp your_username@remotehost.edu:foobar.txt /some/local/directory

Copy the file "foobar.txt" from the local host to a remote host

$ scp foobar.txt your_username@remotehost.edu:/some/remote/directory

Copy the directory "foo" from the local host to a remote host's directory "bar"

$ scp -r foo your_username@remotehost.edu:/some/remote/directory/bar

Copy the file "foobar.txt" from remote host "rh1.edu" to remote host "rh2.edu"

$ scp your_username@rh1.edu:/some/remote/directory/foobar.txt \
your_username@rh2.edu:/some/remote/directory/

Copying the files "foo.txt" and "bar.txt" from the local host to your home directory on the remote host

$ scp foo.txt bar.txt your_username@remotehost.edu:~

Copy the file "foobar.txt" from the local host to a remote host using port 2264

$ scp -P 2264 foobar.txt your_username@remotehost.edu:/some/remote/directory

Copy multiple files from the remote host to your current directory on the local host

$ scp your_username@remotehost.edu:/some/remote/directory/\{a,b,c\} .
$ scp your_username@remotehost.edu:~/\{foo.txt,bar.txt\} .

scp Performance

By default scp uses the Triple-DES cipher to encrypt the data being sent. Using the Blowfish cipher has been shown to increase speed. This can be done by using option -c blowfish in the command line.
$ scp -c blowfish some_file your_username@remotehost.edu:~
It is often suggested that the -C option for compression should also be used to increase speed. The effect of compression, however, will only significantly increase speed if your connection is very slow. Otherwise it may just be adding extra burden to the CPU. An example of using blowfish and compression:
$ scp -c blowfish -C local_file your_username@remotehost.edu:~

Reference: http://www.hypexr.org/linux_scp_help.php

Tuesday, 4 March 2014

To run the Joomla controller task ( via Joomla frontend ) with CronJobs in CPanel

To run the Joomla controller task (via Joomla Frontend) with Cron Jobs (Cron Scheduler) in CPanel, please follow the below instruction.

For security: It's always better to include key for your Cron Jobs like simple param &key=someencrypetd_value with the url, then decrypt and compare inside your controller task before starting the controller task functionality.

In fact, this will help you to prevent someone executing your Cron via direct url.

And, to Set Up Cron Jobs, just login to Cpanel->Cron Jobs->add your url in below format on Command.
// Add the below link into command.
wget -O /dev/null "http://www.yourdomain.com/index.php?option=com_article&view=cronjobs&key=eyJ0eXBl"

// And it would look like below; ( it schedules the job on every 6th of every 2hrs )

*/6 */2 * * * wget -O /dev/null "http://www.yourdomain.com/index.php?option=com_article&view=cronjobs&key=eyJ0eXBl"

//
More about Cpanel CronJobs

Friday, 28 February 2014

Function to add the Error Log into Custom Log File in Joomla 3.0

Function to add the Error Log into Custom Log File in Joomla 3.0
function addErrorToLog($message='')
{
 $data = date('Y-m-d H.i.s'). "\t INFO \t\t ".$_SERVER['REMOTE_ADDR']." \t\t Message: ".$message;
 
 $log_path = JFactory::getApplication()->getCfg('log_path');
 $logfile_path = $log_path . '\com_locator.formbridge.log.php';
 
 if ( !file_exists($logfile_path) )  // if file is not exist.
 {
  $ini_data = "#\n" .
     "#\n" .
     "#Date: 28.02.2014 13:46:29 UTC\n" .
     "#WebApp: Form Bridge (Joomla Platform) 1.0 Stable [ IRC Adhikari ] 28.02.2014 00:00 GMT\n\n".
     "#Fields: date time \t priority \t clientip \t category : message\n";
  $error =  file_put_contents($logfile_path, (PHP_EOL . $ini_data . $data) );
 } else // If file already exist, add the data into existing file.
 {
  $error = file_put_contents($logfile_path, (PHP_EOL . $data), FILE_APPEND | LOCK_EX);
 }

 return true;
}
$this->addErrorToLog($message=' This is test message ');

Function to update the DB Table Record in Joomla 3.0+

// Function to update the DB Table Records in Joomla 3.0+ by passing the data in arrays
protected function updateTableRecordByClauses($fields, $table, $where=array())
{
 $this->db = JFactory::getDBO();
 
 $query = "UPDATE ".$table." SET %s WHERE %s";
 
 $fields = array();
 foreach ($fields as $key => $val ) :
  $fields[] = $this->db->quoteName($key) . '=\''.$val.'\'';
 endforeach;
 
 // Conditions for which records should be updated.
 $conditions = array();
 foreach ($where as $key => $val ) :
  $conditions[] = $this->db->quoteName($key) . '=\''.$val.'\'';
 endforeach;
 
 $this->db->setQuery( $query = sprintf($query, implode(",", $fields), implode(" AND ", $conditions)) );
 $result = $this->db->execute();

 return $result;
}
// To call the function 
 $fields = array('Status'=>'Approved');
 $whereClause = array('SubmissionId' => 12 'FieldName' => 'Membership', 'FieldValue' => 'Pending');
 $this->updateTableRecordByClauses($fields, '#__users_submission', $whereClause);


// Function to update the Single Where Clause.
protected function updateTableRecord($locationObj, $table)
{
 $this->db = JFactory::getDBO();
 // Update a new query object.
 $result = $this->db->updateObject($table, $locationObj, 'id');
 // $id = (int)$this->db->insertid();
 
 return $result;
}
 // Update the user record into '__users' table.
 $dataObj = new stdClass();
 $dataObj->id = $myfields['UserId'];
 $dataObj->lastResetTime = $location_id;
 $dataObj->block = $myfields['Country'];
 $dataObj->updated = date('Y-m-d H:i:s');
 $this->updateTableRecord($dataObj, '#__users');

Wednesday, 26 February 2014

Get Geocodes Latitude and Longitude using PHP (via Google API)

The below function pulls the Geocode Location Latitude and Longitude values using PHP. It uses the Google API to pull those Geo co-ordinates.
 function getLatLogOfAddress($address='')
 {
  $address = urlencode($address);
  
  //here is the google api url
  $url = "http://maps.googleapis.com/maps/api/geocode/json?address=$address&sensor=false";
  
  //get the content from the api using file_get_contents
  $getmap = file_get_contents($url);
  
  //the result is in json format. To decode it use json_decode
  $googlemap = json_decode($getmap);

  $data = array();
  //get the latitute, longitude, address from google api's json result 
  $googlemap = isset($googlemap->results[0]) ? $googlemap->results[0] : '';
  $data['lat'] = isset($googlemap->geometry->location->lat) ? $googlemap->geometry->location->lat : '';
  $data['lng'] = isset($googlemap->geometry->location->lng) ? $googlemap->geometry->location->lng : ''; 
  $data['address'] = isset($googlemap->formatted_address) ? $googlemap->formatted_address : $address;
  
  return $data;
 }

// Call the function as below;
 $address = "Apollo Victoria Theatre, 17 Wilton Road, Westminster, London, SW1V 1LG, UK";
 $geocodes = $this->getLatLogOfAddress($address);
 print_r($geocodes);
 
// The Result would be...
 Array
 (
     [lat] => 51.4957746
     [lng] => 51.4957746
     [address] => London SW1V 1LG, UK
 ) 

Monday, 24 February 2014

How the HTTP Live Streaming works: The Basics of HTTP Live Streaming

The research for this article started when some of my subscription users started complaining that they could only see a few minutes of one of my longer webinars before they needed to reset their browser. At first, I thought this was caused by bad programming on our part. But, further research made me realize that iOS devices only stream about 10 minutes of continuous video content when they are connected to a cellular data network, then they stop.
Period.
This article explains why. (If you want a more technical explanation, read this Apple Support Note.)
NOTE: If any of the following conditions are true, you can ignore this article:
  • You stream all your videos off YouTube, Vimeo, or other commercial streaming service
  • Your videos run less than 10 minutes
  • No one watches your videos on an iOS mobile device (apparently, Android devices don’t have this limitation).
Understanding Live Streaming isn’t easy, but it isn’t impossible, and this article provides a cookbook you can follow which makes a lot of it fairly simple.
SOME BACKGROUND
There are two types of web video:
  • Progressive downloads
  • Streaming video

Find more on below link:

Referred: The Basics of HTTP Live Streaming