<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>yalamber.com</title>
	<atom:link href="http://yalamber.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://yalamber.com</link>
	<description>I Develop applications for Web</description>
	<lastBuildDate>Thu, 21 Feb 2013 18:55:24 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>And this was how I bungee jumped</title>
		<link>http://yalamber.com/2013/02/and-this-was-how-i-bungee-jumped/</link>
		<comments>http://yalamber.com/2013/02/and-this-was-how-i-bungee-jumped/#comments</comments>
		<pubDate>Thu, 21 Feb 2013 18:55:24 +0000</pubDate>
		<dc:creator>yalamber</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://yalamber.com/?p=498</guid>
		<description><![CDATA[<p></p><p>The post <a href="http://yalamber.com/2013/02/and-this-was-how-i-bungee-jumped/">And this was how I bungee jumped</a> appeared first on <a href="http://yalamber.com">yalamber.com</a>.</p>]]></description>
				<content:encoded><![CDATA[<p><iframe width="560" height="315" src="http://www.youtube.com/embed/Bzfl7gsyp_g" frameborder="0" allowfullscreen></iframe></p>
<p>The post <a href="http://yalamber.com/2013/02/and-this-was-how-i-bungee-jumped/">And this was how I bungee jumped</a> appeared first on <a href="http://yalamber.com">yalamber.com</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://yalamber.com/2013/02/and-this-was-how-i-bungee-jumped/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Whynode.com</title>
		<link>http://yalamber.com/2013/02/whynode-com/</link>
		<comments>http://yalamber.com/2013/02/whynode-com/#comments</comments>
		<pubDate>Tue, 12 Feb 2013 17:01:24 +0000</pubDate>
		<dc:creator>yalamber</dc:creator>
				<category><![CDATA[nodejs]]></category>

		<guid isPermaLink="false">http://yalamber.com/?p=495</guid>
		<description><![CDATA[<p>I just completed development of whynode.com. It is entirely developed in nodejs. Source code is available in github.com/yalamber/whynode</p><p>The post <a href="http://yalamber.com/2013/02/whynode-com/">Whynode.com</a> appeared first on <a href="http://yalamber.com">yalamber.com</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>I just completed development of whynode.com. It is entirely developed in nodejs.<br />
Source code is available in <a href="http://github.com/yalamber/whynode">github.com/yalamber/whynode</a></p>
<p>The post <a href="http://yalamber.com/2013/02/whynode-com/">Whynode.com</a> appeared first on <a href="http://yalamber.com">yalamber.com</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://yalamber.com/2013/02/whynode-com/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Contact form 7 useful hook</title>
		<link>http://yalamber.com/2013/02/contact-form-7-useful-hook/</link>
		<comments>http://yalamber.com/2013/02/contact-form-7-useful-hook/#comments</comments>
		<pubDate>Mon, 11 Feb 2013 10:27:25 +0000</pubDate>
		<dc:creator>yalamber</dc:creator>
				<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://yalamber.com/?p=493</guid>
		<description><![CDATA[<p></p><p>The post <a href="http://yalamber.com/2013/02/contact-form-7-useful-hook/">Contact form 7 useful hook</a> appeared first on <a href="http://yalamber.com">yalamber.com</a>.</p>]]></description>
				<content:encoded><![CDATA[<pre class="brush: php; title: ; notranslate">
 function wpcf7_mail_users_custom($cfdata) {
    $formtitle = $cfdata-&gt;title;
    $formdata = $cfdata-&gt;posted_data;
    //logic code here
  }

  add_action('wpcf7_mail_sent', 'wpcf7_mail_users_custom', 1);
</pre>
<p>The post <a href="http://yalamber.com/2013/02/contact-form-7-useful-hook/">Contact form 7 useful hook</a> appeared first on <a href="http://yalamber.com">yalamber.com</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://yalamber.com/2013/02/contact-form-7-useful-hook/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Inotify in nodejs</title>
		<link>http://yalamber.com/2013/01/inotify-in-nodejs/</link>
		<comments>http://yalamber.com/2013/01/inotify-in-nodejs/#comments</comments>
		<pubDate>Mon, 28 Jan 2013 09:23:06 +0000</pubDate>
		<dc:creator>yalamber</dc:creator>
				<category><![CDATA[nodejs]]></category>

		<guid isPermaLink="false">http://yalamber.com/?p=484</guid>
		<description><![CDATA[<p>I recently used nodejs for a part of web app I have been working on. We have to connect to a ftp server and check for new files in that ftp server and process the new files and pull them to our web app server for processing. First we used ftp functions in php and [...]</p><p>The post <a href="http://yalamber.com/2013/01/inotify-in-nodejs/">Inotify in nodejs</a> appeared first on <a href="http://yalamber.com">yalamber.com</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>I recently used nodejs for a part of web app I have been working on. We have to connect to a ftp server and check for new files in that ftp server and process the new files and pull them to our web app server for processing. First we used ftp functions in php and checked file modified time and then ftp get the file. But this process was taking to much of time and as the ftp directory grew it was near impossible to withstand the processing time of that through php script. I searched web for some methods in php that could send in response when there is change in file in specific directory or watch a directory for changes. I came to know about <a href="http://en.wikipedia.org/wiki/Inotify">inotify</a> in linux. Wonderful that was what I needed. <a href="http://php.net/manual/en/book.inotify.php">Inotify</a> was available in php as well.<br />
But as I was interested in learning the nodejs I just thought of why not use nodejs for this part of the web app and searched for if modules were available for nodejs and found this <a href="https://github.com/c4milo/node-inotify">nodejs inotify</a>. It was exactly what I needed. I installed nodejs in the ftp server and added following modules <a href="https://github.com/mikeal/request">request</a>, <a href="https://github.com/nodejitsu/forever">forever</a>, <a href="https://github.com/c4milo/node-inotify">inotify</a> </p>
<p>Here is the code that will watch the directory mentioned</p>
<pre class="brush: plain; title: ; notranslate">
'use strict';
var request = require('request');
var fs = require('fs');
var Inotify = require('inotify').Inotify;
var inotify = new Inotify();
var return_watch_dir = function (dir_path) {
  var return_data;
  return_data = {
    path: dir_path,
    watch_for: Inotify.IN_CLOSE_WRITE,
    callback: function (event) {
      var request_url, mask, file_loc, r, str;
      request_url = 'http://example.com/call';
      mask = event.mask;
      file_loc = dir_path + '/' + event.name;
      if (mask &amp; Inotify.IN_CLOSE_WRITE) {
        r = request.put(request_url + '?file_name=' + event.name);
        fs.createReadStream(file_loc).pipe(r);
        str = '';
        r.on('data', function (chunk) {
          str += chunk;
        });
        r.on('end', function () {
          console.log(str);
        });
      }
    }
  };
  return return_data;
};
//watcher
inotify.addWatch(return_watch_dir('/home/ftpuser/folder_to_watch1'));
inotify.addWatch(return_watch_dir('/home/ftpuser/folder_to_watch2'));
</pre>
<p>Now I saved it as watch_folder.js and called it using forever.</p>
<pre class="brush: plain; title: ; notranslate">
forever start watch_folder.js
</pre>
<p>What this script does is watch two folders for inotify in Inotify.IN_CLOSE_WRITE(this means notify when file write is complete.)<br />
In notify callback function I made http put request to the remote server at http://example.com/call which can handle rest.<br />
So this just worked as expected and was fast enough than ftp from php.</p>
<p>The post <a href="http://yalamber.com/2013/01/inotify-in-nodejs/">Inotify in nodejs</a> appeared first on <a href="http://yalamber.com">yalamber.com</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://yalamber.com/2013/01/inotify-in-nodejs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AWS SDK php 2 in codeigniter application</title>
		<link>http://yalamber.com/2013/01/aws-sdk-php-2-in-codeigniter-application/</link>
		<comments>http://yalamber.com/2013/01/aws-sdk-php-2-in-codeigniter-application/#comments</comments>
		<pubDate>Thu, 03 Jan 2013 09:56:28 +0000</pubDate>
		<dc:creator>yalamber</dc:creator>
				<category><![CDATA[AWS]]></category>
		<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[Codeigniter]]></category>

		<guid isPermaLink="false">http://yalamber.com/?p=453</guid>
		<description><![CDATA[<p>I got a change to work on a interesting project where we needed to integrate AWS services like cloudfront and s3 to our application. we started out with using a class from tpyo @ https://github.com/tpyo/amazon-s3-php-class/ but soon found limitations so I decided to use latest AWS SDK for php from amazon available at http://aws.amazon.com/sdkforphp/. I [...]</p><p>The post <a href="http://yalamber.com/2013/01/aws-sdk-php-2-in-codeigniter-application/">AWS SDK php 2 in codeigniter application</a> appeared first on <a href="http://yalamber.com">yalamber.com</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>I got a change to work on a interesting project where we needed to integrate AWS services like cloudfront and s3 to our application. we started out with using a class from tpyo @ https://github.com/tpyo/amazon-s3-php-class/ but soon found limitations so I decided to use latest AWS SDK for php from amazon available at <a href="http://aws.amazon.com/sdkforphp/">http://aws.amazon.com/sdkforphp/</a>. I got to try out <a href="http://getcomposer.org/">composer</a> aswell, it is dependency management tool for php and aws sdk was available on it. So today I will be writing up a short tutorial on how to make use of aws sdk on your codeigniter application using composer and will also provide a wrapper library for some methods for services like cloudfront and s3.<br />
You can find this instructions <a href="http://docs.amazonwebservices.com/awssdkdocsphp2/latest/gettingstartedguide/sdk-php2-installing-the-sdk.html#sdk-php2-installing-via-composer">here</a> as well</p>
<p>1. First we need to prepare a composer.json file which will contain aws sdk as dependency in our project root path.<br />
composer.json</p>
<pre class="brush: plain; title: ; notranslate">
{
  &quot;require&quot;: {
      &quot;aws/aws-sdk-php&quot;: &quot;*&quot;
  }
}
</pre>
<p>2. Then download and install composer<br />
In terminal do following</p>
<pre class="brush: plain; title: ; notranslate">
curl -s &quot;http://getcomposer.org/installer&quot; | php
</pre>
<pre class="brush: plain; title: ; notranslate">
php composer.phar install
</pre>
<p>Above codes will download required files and libraries to vendor directory in our project. </p>
<p>Now we will create a new library called Myaws that will act as wrapper for our methods we will be using exclusively in our app.</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php 

if (!defined('BASEPATH'))
    exit('No direct script access allowed');
//composer auto load
include_once FCPATH.'/vendor/autoload.php';
use Aws\Common\Aws;
use Aws\Common\Enum\Region;
use Aws\S3\Enum\CannedAcl;
use Aws\S3\Exception\S3Exception;
use Aws\CloudFront\Enum\OriginProtocolPolicy;
use Aws\CloudFront\Enum\ViewerProtocolPolicy;
use Aws\CloudFront\Exception\CloudFrontException;
class Myaws {	
	private $aws;
	private $s3Client;
	private $cfClient;
	private $cfIdentity;
	public $debug=false;
	function __construct(){
		$CI =&amp; get_instance();
		$this-&gt;aws = Aws::factory(array(
		  'key'    =&gt; $CI-&gt;config-&gt;item('s3_access_key_id'),
		  'secret' =&gt; $CI-&gt;config-&gt;item('s3_secret_key')
		));
		$this-&gt;cfIdentity = $CI-&gt;config-&gt;item('cf_identity');
		$this-&gt;s3Client = $this-&gt;aws-&gt;get('s3');
		$this-&gt;cfClient = $this-&gt;aws-&gt;get('cloudfront');
	}
	
	function isValidBucketName($bucket_name){
		try {
			if($this-&gt;s3Client-&gt;isValidBucketName($bucket_name)){
				return true;
			}
			return false;
		} catch (S3Exception $e) {
			if($this-&gt;debug){
				return $e-&gt;getMessage();
			}
			else{
				return false;
			}
		}	
	}
	
	function doesBucketExist($bucket_name){
		try {
			if($this-&gt;s3Client-&gt;doesBucketExist($bucket_name)){
				return true;
			}
			return false;
		} catch (S3Exception $e) {
			if($this-&gt;debug){
				return $e-&gt;getMessage();
			}
			else{
				return false;
			}
		}
	}
	
	function createBucket($bucket_name){
		if($this-&gt;isValidBucketName($bucket_name)){
			if($this-&gt;doesBucketExist($bucket_name)){
				return false;
			}
			else{
				try{
					$this-&gt;s3Client-&gt;createBucket(
					array(
						'Bucket'=&gt;$bucket_name,
						'ACL'	=&gt; CannedAcl::PUBLIC_READ
						//add more items if required here
					));
					return true;
				} catch(S3Exception $e){
					if($this-&gt;debug){
						return $e-&gt;getMessage();
					}
					else{
						return false;
					}
				}	
			}
		}
		else{
			if($this-&gt;debug){
				return $e-&gt;getMessage();
			}
			else{
				return false;
			}
		}
	}
	
	function _return_bucket_policy($bucket_name = ''){
		return '{
			&quot;Version&quot;: &quot;2008-10-17&quot;,
			&quot;Id&quot;: &quot;PolicyForCloudFrontPrivateContent&quot;,
			&quot;Statement&quot;: [
				{
					&quot;Sid&quot;: &quot;1&quot;,
					&quot;Effect&quot;: &quot;Allow&quot;,
					&quot;Principal&quot;: {
						&quot;AWS&quot;: &quot;arn:aws:iam::cloudfront:user/CloudFront Origin Access Identity '.$this-&gt;cfIdentity.'&quot;
					},
					&quot;Action&quot;: &quot;s3:GetObject&quot;,
					&quot;Resource&quot;: &quot;arn:aws:s3:::'.$bucket_name.'/*&quot;
				}
			]
		}';
	}
	
	function putBucketPolicy($bucket_name){
		if($this-&gt;doesBucketExist($bucket_name)){
			try{
				$this-&gt;s3Client-&gt;putBucketPolicy(
				array(
					'Bucket'=&gt;$bucket_name, 
					'Policy'=&gt;$this-&gt;_return_bucket_policy($bucket_name)
				));
				return true;
			} catch(S3Exception $e){
				if($this-&gt;debug){
					return $e-&gt;getMessage();
				}
				else{
					return false;
				}
			}
		}
		else{
			return false;
		}
	}
	
	function deleteBucket($bucket_name){
		try {
			$this-&gt;s3Client-&gt;clearBucket($bucket_name);
			$this-&gt;s3Client-&gt;deleteBucket(array(
				'Bucket' =&gt; $bucket_name
			));
			return true;
		} catch (S3Exception $e) {
			if($this-&gt;debug){
				return $e-&gt;getMessage();
			}
			else{
				return false;
			}
		}
	}
	
	function doesObjectExist($bucket_name, $key){
		try {
			if($this-&gt;s3Client-&gt;doesObjectExist($bucket_name, $key)){
				return true;	
			}
			return false;
		} catch(S3Exception $e){
			if($this-&gt;debug){
				return $e-&gt;getMessage();
			}
			else{
				return false;
			}
		}	
	}
	
	function putObject($bucket_name, $key, $body){
		try {
			$this-&gt;s3Client-&gt;putObject(array(
				'Bucket'=&gt; $bucket_name,
				'Key'	=&gt; $key,
				'Body' 	=&gt; $body,
				'ACL'	=&gt; CannedAcl::PUBLIC_READ
			));
			return true;
		} catch(S3Exception $e){
			if($this-&gt;debug){
				return $e-&gt;getMessage();
			}
			else{
				return false;
			}
		}
	}
	
	function deleteObject($bucket_name, $objects){
		try {
			$this-&gt;s3Client-&gt;deleteObject(array(
				'Bucket'  =&gt;$bucket_name,
				'Objects' =&gt;$objects
			));
			return true;
		} catch (S3Exception $e) {
			if($this-&gt;debug){
				return $e-&gt;getMessage();
			}
			else{
				return false;
			}
		}
	}
	
	// $objects should be array(array('Key'=&gt;$key), array('Key'=&gt;$key2)); testing needed here before implementation
	function deleteObjects($bucket_name, $keys){
		try {
			$this-&gt;s3Client-&gt;deleteObjects(array(
				'Bucket' =&gt; $bucket_name,
				'Key'=&gt; $keys
			));
			return true;
		} catch (S3Exception $e) {
			if($this-&gt;debug){
				return $e-&gt;getMessage();
			}
			else{
				return false;
			}
		}	
	}
	
	function createDistribution($bucket_name, $domain_name){
		try{
			$return = $this-&gt;cfClient-&gt;createDistribution($this-&gt;_return_distribution_config_array($bucket_name, $domain_name, true));
			return $return-&gt;toArray();
		} catch(CloudFrontException $e){
			if($this-&gt;debug){
				return $e-&gt;getMessage();
			}
			else{
				return false;
			}
		}
	}
	
	function _return_distribution_config_array($bucket_name= '', $domain_name = '', $enabled = true){
		$origin_id = 'S3-'.$bucket_name;
		return array(
			'CallerReference' =&gt; md5(time()),
			'Aliases' =&gt; array(
				'Quantity'=&gt;1, 
				'Items'=&gt; array($domain_name)
			),
			'DefaultRootObject' =&gt; 'index.html',
			'Origins' =&gt; array(
				'Quantity' =&gt; 1, 
				'Items' =&gt; array(
					array(
						'Id' =&gt; $origin_id,
						'DomainName' =&gt; strtolower($bucket_name.'.s3.amazonaws.com'),
						'S3OriginConfig' =&gt; array(
							'OriginAccessIdentity' =&gt; 'origin-access-identity/cloudfront/'.$this-&gt;cfIdentity
						)
					)
				)
			),
			'DefaultCacheBehavior' =&gt; array(
				'TargetOriginId' =&gt; $origin_id,
				'ForwardedValues' =&gt; array(
					'QueryString' =&gt; false
				),
				'TrustedSigners' =&gt; array(
	            	'Enabled'  =&gt; false,
					'Quantity' =&gt; 0,
					'Items' =&gt; array()
	             ),
				'ViewerProtocolPolicy' =&gt; ViewerProtocolPolicy::ALLOW_ALL,
				'MinTTL' =&gt; 0
			),
			'CacheBehaviors' =&gt; array('Quantity' =&gt; 0, 'Items' =&gt; array()),
			'Comment' =&gt; 'Distribution for '.$bucket_name,
			'Logging' =&gt; array(
                'Enabled' =&gt; false,
                'Bucket' =&gt; '',
                'Prefix' =&gt; ''
            ),
			'Enabled' =&gt; $enabled
		);
	}
	
	function disableDistribution($cfID){
		try{
			$getConfig = $this-&gt;cfClient-&gt;getDistributionConfig(array('Id' =&gt; $cfID));
			$got_config_array = $getConfig-&gt;toArray();
			try{
				$config_array = $got_config_array;
				$config_array['Enabled'] = false;
				$config_array['Id'] = $cfID;
				$config_array['IfMatch'] = $got_config_array['ETag'];
				$config_array['Logging'] = array(
	                'Enabled' =&gt; false,
	                'Bucket' =&gt; '',
	                'Prefix' =&gt; ''
	            );
				unset($config_array['ETag']);
				unset($config_array['RequestId']);
				$this-&gt;cfClient-&gt;updateDistribution($config_array);
			} catch(CloudFrontException $e){
				if($this-&gt;debug){
					return $e-&gt;getMessage();
				}
				else{
					return false;
				}
			}
		} catch(CloudFrontException $e){
			if($this-&gt;debug){
				return $e-&gt;getMessage();
			}
			else{
				return false;
			}
		}
	}
	
	function deleteDistribution($cfID){
		try{
			$getDistribution = $this-&gt;cfClient-&gt;getDistribution(array('Id' =&gt; $cfID));
			$got_distribution_array = $getDistribution-&gt;toArray();
			if($got_distribution_array['Status'] == 'Deployed' and $got_distribution_array['DistributionConfig']['Enabled'] == false){
				try{
					$this-&gt;cfClient-&gt;deleteDistribution(array('Id' =&gt; $cfID, 'IfMatch' =&gt; $got_distribution_array['ETag']));
					return true;
				} catch(CloudFrontException $e){
					if($this-&gt;debug){
						return $e-&gt;getMessage();
					}
					else{
						return false;
					}
				}
			}
			else{
				if($this-&gt;debug){
					return $e-&gt;getMessage();
				}
				else{
					return false;
				}
			}	
		} catch(CloudFrontException $e){
			if($this-&gt;debug){
				return $e-&gt;getMessage();
			}
			else{
				return false;
			}
		}
	}
	
	
}
</pre>
<p>This library includes the vendor auto load file from composer and uses required namespaces for the library. The methods in this library are itself self explanatory. I have set some config items in constructer. You can add them in your codeigniter config file as follows:</p>
<pre class="brush: plain; title: ; notranslate">
$config['aws_access_key_id'] = '';
$config['aws_secret_key'] = '';
$config['cf_identity'] = '';
</pre>
<p>You can get these values from your aws management panel.</p>
<p>Now to use this library simply load the library and call the required methods in your controller:</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Testaws extends MY_Controller 
{
    function __construct() {
        parent::__construct();
		$this-&gt;load-&gt;library('myaws');
    }

    function index() {
		$this-&gt;myaws-&gt;createBucket('bucketname');
		$this-&gt;myaws-&gt;putBucketPolicy('bucketname', 'Bucket Policy in Json format here');
		$this-&gt;myaws-&gt;putObject('bucketname', 'keyname.txt', 'body content');
		$this-&gt;myaws-&gt;createDistribution('bucketname', 'domain');
		$this-&gt;myaws-&gt;disableDistribution('distribution ID');
		$this-&gt;myaws-&gt;deleteDistribution('distribution ID');
		
    }

</pre>
<p>That&#8217;s it you can add more methods as required. You can find detailed API documentation <a href="http://docs.amazonwebservices.com/aws-sdk-php-2/latest/">here</a>. If you need any help regarding the use of sdk and api let me know in comments I will try to help you out. </p>
<p>The post <a href="http://yalamber.com/2013/01/aws-sdk-php-2-in-codeigniter-application/">AWS SDK php 2 in codeigniter application</a> appeared first on <a href="http://yalamber.com">yalamber.com</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://yalamber.com/2013/01/aws-sdk-php-2-in-codeigniter-application/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Get the latest version number of WordPress Using API</title>
		<link>http://yalamber.com/2012/12/get-the-latest-version-number-of-wordpress-using-api/</link>
		<comments>http://yalamber.com/2012/12/get-the-latest-version-number-of-wordpress-using-api/#comments</comments>
		<pubDate>Wed, 12 Dec 2012 06:28:11 +0000</pubDate>
		<dc:creator>yalamber</dc:creator>
				<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://yalamber.com/?p=439</guid>
		<description><![CDATA[<p>I am going to show you how to check for the latest version of WordPress using API provided by WordPress. Below is the code to get the latest version of WordPress from api at http://api.wordpress.org/core/version-check/1.6/ [I did not know it existed. but there are several API provided by WordPress, go to http://codex.wordpress.org/WordPress.org_API] You will have [...]</p><p>The post <a href="http://yalamber.com/2012/12/get-the-latest-version-number-of-wordpress-using-api/">Get the latest version number of WordPress Using API</a> appeared first on <a href="http://yalamber.com">yalamber.com</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>I am going to show you how to check for the latest version of WordPress using API provided by WordPress.<br />
Below is the code to get the latest version of WordPress from api at http://api.wordpress.org/core/version-check/1.6/ [I did not know it existed. but there are several API provided by WordPress, go to <a href="http://codex.wordpress.org/WordPress.org_API">http://codex.wordpress.org/WordPress.org_API</a>]<br />
You will have to create a cache folder which will save the response in a file so that we do not ping the WordPress server often. You can use this code in your website to show latest version number as I have done in <a href="http://wpambulance.com">wpambulance.com</a></p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
function getData($url) {
	if(is_callable('curl_init')){
	  $ch = curl_init();
	  $timeout = 5;
	  curl_setopt($ch, CURLOPT_URL, $url);
	  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
	  $data = curl_exec($ch);
	  curl_close($ch);
	  return $data;
	}else{
		return file_get_contents($url);
	}
}
//check for latest WordPress version
$apiUrl = 'http://api.wordpress.org/core/version-check/1.6/';
$apiFile = 'cache/api.json';
if((is_file($apiFile) and filemtime($apiFile)&lt; time()-3600) OR !is_file($apiFile))
{
  $apiContent = getData($apiUrl);
  if($apiContent!=''){
    file_put_contents($apiFile, $apiContent);
  }
}
$apiContent = file_get_contents($apiFile);
$apiReturn = unserialize($apiContent);
$current_version = $apiReturn['offers'][0]['current'];
?&gt;
</pre>
<p>The post <a href="http://yalamber.com/2012/12/get-the-latest-version-number-of-wordpress-using-api/">Get the latest version number of WordPress Using API</a> appeared first on <a href="http://yalamber.com">yalamber.com</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://yalamber.com/2012/12/get-the-latest-version-number-of-wordpress-using-api/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making .svn directory not show up in apache</title>
		<link>http://yalamber.com/2012/10/making-svn-directory-not-show-up-in-apache/</link>
		<comments>http://yalamber.com/2012/10/making-svn-directory-not-show-up-in-apache/#comments</comments>
		<pubDate>Wed, 10 Oct 2012 16:46:38 +0000</pubDate>
		<dc:creator>yalamber</dc:creator>
				<category><![CDATA[Server management]]></category>
		<category><![CDATA[svn]]></category>

		<guid isPermaLink="false">http://yalamber.com/?p=431</guid>
		<description><![CDATA[<p>In your virtual host entry add following:</p><p>The post <a href="http://yalamber.com/2012/10/making-svn-directory-not-show-up-in-apache/">Making .svn directory not show up in apache</a> appeared first on <a href="http://yalamber.com">yalamber.com</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>In your virtual host entry add following:</p>
<pre class="brush: plain; title: ; notranslate">
&lt;DirectoryMatch \.svn&gt;
   Order allow,deny
   Deny from all
&lt;/DirectoryMatch&gt;
</pre>
<p>The post <a href="http://yalamber.com/2012/10/making-svn-directory-not-show-up-in-apache/">Making .svn directory not show up in apache</a> appeared first on <a href="http://yalamber.com">yalamber.com</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://yalamber.com/2012/10/making-svn-directory-not-show-up-in-apache/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Listing chmod status in linux</title>
		<link>http://yalamber.com/2012/09/listing-chmod-status-in-linu/</link>
		<comments>http://yalamber.com/2012/09/listing-chmod-status-in-linu/#comments</comments>
		<pubDate>Thu, 13 Sep 2012 06:32:35 +0000</pubDate>
		<dc:creator>yalamber</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://yalamber.com/?p=412</guid>
		<description><![CDATA[<p></p><p>The post <a href="http://yalamber.com/2012/09/listing-chmod-status-in-linu/">Listing chmod status in linux</a> appeared first on <a href="http://yalamber.com">yalamber.com</a>.</p>]]></description>
				<content:encoded><![CDATA[<pre class="brush: plain; title: ; notranslate">
stat -c '%A %a %n' *
</pre>
<p>The post <a href="http://yalamber.com/2012/09/listing-chmod-status-in-linu/">Listing chmod status in linux</a> appeared first on <a href="http://yalamber.com">yalamber.com</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://yalamber.com/2012/09/listing-chmod-status-in-linu/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Auto updating your dev ec2 environment with svn on codebasehq</title>
		<link>http://yalamber.com/2012/08/auto-updating-your-dev-ec2-environment-with-svn-on-codebasehq/</link>
		<comments>http://yalamber.com/2012/08/auto-updating-your-dev-ec2-environment-with-svn-on-codebasehq/#comments</comments>
		<pubDate>Wed, 29 Aug 2012 10:33:25 +0000</pubDate>
		<dc:creator>yalamber</dc:creator>
				<category><![CDATA[SSH]]></category>
		<category><![CDATA[svn]]></category>

		<guid isPermaLink="false">http://yalamber.com/?p=405</guid>
		<description><![CDATA[<p>I wanted to auto update my dev environment whenever commit happens on my codebasehq Repo. Below is my solution based on php, ssh using phpseclib. Below is my php script that uses ssh to run svn update command, we can name it as updater.php and place it in root folder. In your codebasehq repo setting [...]</p><p>The post <a href="http://yalamber.com/2012/08/auto-updating-your-dev-ec2-environment-with-svn-on-codebasehq/">Auto updating your dev ec2 environment with svn on codebasehq</a> appeared first on <a href="http://yalamber.com">yalamber.com</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>I wanted to auto update my dev environment whenever commit happens on my codebasehq Repo. Below is my solution based on php, ssh using phpseclib.</p>
<p>Below is my php script that uses ssh to run svn update command, we can name it as updater.php and place it in root folder.</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php	
    @set_time_limit( 0 );
    set_include_path(get_include_path() . PATH_SEPARATOR . 'phpseclib');
	include('Net/SSH2.php');
    include('Crypt/RSA.php');
    $ssh = new Net_SSH2('devserver.com');
    $key = new Crypt_RSA();
    $key-&gt;setPassword('passphrase');
    $key-&gt;loadKey('your key here');
    if (!$ssh-&gt;login('username', $key)) {
        exit('Login Failed');
    }
    echo $ssh-&gt;exec('svn update /var/www');
</pre>
<p>In your codebasehq repo setting place url in post-receive hook to your updater script written in php. http://yourdevserver.com/updater.php</p>
<p>you need to checkout repo in your dev server then after each commit it will get auto updated by this script. </p>
<p>The post <a href="http://yalamber.com/2012/08/auto-updating-your-dev-ec2-environment-with-svn-on-codebasehq/">Auto updating your dev ec2 environment with svn on codebasehq</a> appeared first on <a href="http://yalamber.com">yalamber.com</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://yalamber.com/2012/08/auto-updating-your-dev-ec2-environment-with-svn-on-codebasehq/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using SSH from php to create virtualhost in apache</title>
		<link>http://yalamber.com/2012/08/using-ssh-from-php-to-create-virtualhost-in-apache/</link>
		<comments>http://yalamber.com/2012/08/using-ssh-from-php-to-create-virtualhost-in-apache/#comments</comments>
		<pubDate>Tue, 14 Aug 2012 23:00:21 +0000</pubDate>
		<dc:creator>yalamber</dc:creator>
				<category><![CDATA[SFTP]]></category>
		<category><![CDATA[SSH]]></category>

		<guid isPermaLink="false">http://yalamber.com/?p=396</guid>
		<description><![CDATA[<p>So today I had to write a code that would use ssh from php to create virtual hosts in apache. I used phpsec library and following code worked out great. This one is for ubuntu server on amazon EC2. What i did is create new folder in var/www and upload necessary files and vhost file [...]</p><p>The post <a href="http://yalamber.com/2012/08/using-ssh-from-php-to-create-virtualhost-in-apache/">Using SSH from php to create virtualhost in apache</a> appeared first on <a href="http://yalamber.com">yalamber.com</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>So today I had to write a code that would use ssh from php to create virtual hosts in apache. I used <a href="http://phpseclib.sourceforge.net">phpsec</a> library and following code worked out great. This one is for ubuntu server on amazon EC2. What i did is create new folder in var/www and upload necessary files and vhost file in that folder. I didnot upload vhost file directly to /etc/apache2/sites-available due to permission issues. After I uploaded the vhost file that is preconfigured, I moved it to /etc/apache2/sites-available and used commands to enable site and restart server using $ssh->exec();</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
	set_include_path(get_include_path() . PATH_SEPARATOR . 'phpseclib');
	include('Net/SFTP.php');
	include('Crypt/RSA.php');
	$sftp = new Net_SFTP('www.example.com');
	$key = new Crypt_RSA();
	$key-&gt;setPassword('passphrase');
	$key-&gt;loadKey(file_get_contents('ppkfile.ppk'));
	if (!$sftp-&gt;login('username', $key)) {
	    exit('Login Failed');
	}
	$sftp-&gt;mkdir('/var/www/test'); 
	$sftp-&gt;put('/var/www/test/index.html', 'upload.html', NET_SFTP_LOCAL_FILE);
	$sftp-&gt;put('/var/www/test/test', 'vhostTemplate', NET_SFTP_LOCAL_FILE);
	$ssh = new Net_SSH2('www.example.com');
	$key = new Crypt_RSA();
	$key-&gt;setPassword('passphrase');
	$key-&gt;loadKey(file_get_contents('ppkfile.ppk'));
	if (!$ssh-&gt;login('username', $key)) {
	    exit('Login Failed');
	}
	echo $ssh-&gt;exec('sudo mv /var/www/test/test /etc/apache2/sites-available/test');
	echo $ssh-&gt;exec('sudo a2ensite test');
	echo $ssh-&gt;exec('sudo /etc/init.d/apache2 restart');	
</pre>
<p>The post <a href="http://yalamber.com/2012/08/using-ssh-from-php-to-create-virtualhost-in-apache/">Using SSH from php to create virtualhost in apache</a> appeared first on <a href="http://yalamber.com">yalamber.com</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://yalamber.com/2012/08/using-ssh-from-php-to-create-virtualhost-in-apache/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced

 Served from: yalamber.com @ 2013-05-21 10:56:56 by W3 Total Cache -->