Author: hasin

A helpful Twig extension – Fetch

twig

Inspired by Symfony’s twig extension to fetch output from external controllers and URL’s in their Twig subsystem, I wrote this small Twig function which you can use in your general twig templates. The main purpose of this extension is to fetch external URL (via GET or POST). You can also pass an arbitrary number of parameters which is helpful while fetching external URL via POST.

Here is the code of the Fetch extension.

https://gist.github.com/hasinhayder/9705763

To use this newly created extension, initialize your Twig loader in this way

[sourcecode language=”php”]
//include the twig extension file first

$loader = new \Twig_Loader_Filesystem(__DIR__ . "/../app/twig"); //change accordingly
$twig = new \Twig_Environment($loader);
$twig->addExtension(new Fetch());
return $twig;
[/sourcecode]

And then you can simply call it in your twig files in this way

[sourcecode language=”php”]
{{ fetch("http://yourdomain.tld") }}

//or

{{ fetch("http://yourdomain.tld", {‘param1′:’value1′,’param2′:’value2’}) }}
[/sourcecode]

And you’ll notice that the output from the URL is now fetched and displayed in your twig output 🙂

Hope you enjoy this 🙂

āĻ¸āĻšāĻœ āĻŦāĻžāĻ‚āĻ˛āĻžā§Ÿ āĻĄāĻŋāĻœāĻžāĻ‡āĻ¨ āĻĒā§āĻ¯āĻžāĻŸāĻžāĻ°ā§āĻ¨: āĻĢā§āĻ¯āĻžāĻ¸āĻžāĻĄ (Facade)

āĻĄāĻŋāĻœāĻžāĻ‡āĻ¨ āĻĒā§āĻ¯āĻžāĻŸāĻžāĻ°ā§āĻ¨ āĻļā§āĻ¨āĻ˛ā§‡āĻ‡ āĻ…āĻ¨ā§‡āĻ•ā§‡āĻ‡ āĻ˜ā§‡āĻŽā§‡ āĻ“āĻ ā§‡āĻ¨ āĻ†āĻ° āĻŽāĻ¨ā§‡ āĻĒā§œā§‡ āĻ¯āĻžā§Ÿ āĻ—ā§āĻ¯āĻžāĻ‚-āĻ…āĻŦ-āĻĢā§‹āĻ°ā§‡āĻ° āĻĻāĻžāĻāĻ¤ āĻ•āĻŋā§œāĻŽāĻŋā§œ āĻ•āĻ°āĻž āĻĄāĻŋāĻœāĻžāĻ‡āĻ¨ āĻĒā§āĻ¯āĻžāĻŸāĻžāĻ°ā§āĻ¨ āĻŦāĻ‡āĻŸāĻžāĻ° āĻ•āĻĨāĻžāĨ¤ āĻ¤āĻŦā§‡ āĻŽāĻœāĻžāĻ° āĻŦāĻŋāĻˇā§Ÿ āĻšāĻ˛ āĻ¯ā§‡ āĻ†āĻŽāĻ°āĻž āĻ†āĻŽāĻžāĻĻā§‡āĻ° āĻ¨āĻŋāĻ¤ā§āĻ¯āĻĻāĻŋāĻ¨ā§‡āĻ° āĻĒā§āĻ°ā§‹āĻ—ā§āĻ°āĻžāĻŽāĻŋāĻ‚ā§Ÿā§‡ āĻ…āĻ¨ā§‡āĻ•āĻ¸āĻŽā§ŸāĻ‡ āĻœā§‡āĻ¨ā§‡ āĻŦāĻž āĻ¨āĻž āĻœā§‡āĻ¨ā§‡ āĻāĻ¸āĻŦ āĻĒā§āĻ¯āĻžāĻŸāĻžāĻ°ā§āĻ¨ āĻŦā§āĻ¯āĻŦāĻšāĻžāĻ° āĻ•āĻ°ā§‡ āĻĨāĻžāĻ•āĻŋ, āĻ•āĻŋāĻ¨ā§āĻ¤ā§ āĻŸā§‡āĻ•āĻ¨āĻŋāĻ•ā§āĻ¯āĻžāĻ˛ āĻ¨āĻžāĻŽ āĻļā§āĻ¨āĻ˛ā§‡ āĻ…āĻ¨ā§‡āĻ•ā§‡āĻ‡ āĻŦāĻ˛āĻ¤ā§‡ āĻĒāĻžāĻ°āĻŋ āĻ¨āĻž āĻ¯ā§‡ āĻœāĻŋāĻ¨āĻŋāĻ¸āĻŸāĻž āĻ†āĻ¸āĻ˛ā§‡ āĻ•āĻŋāĨ¤ āĻāĻ–āĻ¨ āĻĨā§‡āĻ•ā§‡ āĻ†āĻŽāĻŋ āĻšā§‡āĻˇā§āĻŸāĻž āĻ•āĻ°āĻŦ āĻāĻ•āĻĻāĻŽ āĻ¸āĻšāĻœā§‡ āĻ•āĻŋāĻ›ā§ āĻŦāĻšā§āĻ˛ āĻĒā§āĻ°āĻšāĻ˛āĻŋāĻ¤ āĻĄāĻŋāĻœāĻžāĻ‡āĻ¨ āĻĒā§āĻ¯āĻžāĻŸāĻžāĻ°ā§āĻ¨ āĻŦā§āĻāĻŋā§Ÿā§‡ āĻĻāĻŋāĻ¤ā§‡, āĻ†āĻ° āĻ¤āĻžāĻ°āĻ‡ āĻĒā§āĻ°āĻšā§‡āĻˇā§āĻŸāĻž āĻšāĻŋāĻ¸ā§‡āĻŦā§‡ āĻ†āĻœāĻ•ā§‡āĻ° āĻŦāĻŋāĻˇā§Ÿ āĻšāĻ˛ Facade āĻŦāĻž “āĻĢā§āĻ¯āĻžāĻ¸āĻžāĻĄ”

āĻāĻ•āĻŸā§ āĻ•āĻ āĻŋāĻ¨ āĻŦāĻžāĻ‚āĻ˛āĻžā§Ÿ āĻĢā§āĻ¯āĻžāĻ¸āĻžāĻĄ āĻšāĻ˛ āĻ•ā§‹āĻ¨ āĻ…āĻŦāĻœā§‡āĻ•ā§āĻŸ (āĻŦāĻž āĻ…āĻŦāĻœā§‡āĻ•ā§āĻŸāĻ¸āĻŽā§‚āĻš) āĻ†āĻ°āĻ“ āĻ¸āĻšāĻœā§‡ āĻŦā§āĻ¯āĻžāĻŦāĻšāĻžāĻ° āĻ•āĻ°āĻžāĻ° āĻœāĻ¨ā§āĻ¯ āĻ•ā§āĻ‡āĻ•āĻ˛āĻŋ āĻ•ā§‹āĻ¨ āĻĢāĻžāĻ‚āĻļāĻ¨ āĻŦāĻž āĻ†āĻ°ā§‡āĻ•āĻŸāĻž āĻ…āĻŦāĻœā§‡āĻ•ā§āĻŸ āĻ˛ā§‡āĻ–āĻž, āĻ¯āĻžāĻ° āĻĢāĻ˛ā§‡ āĻŦā§āĻ¯āĻŦāĻšāĻžāĻ°āĻ•āĻžāĻ°ā§€ āĻ•āĻˇā§āĻŸ āĻ¨āĻž āĻ•āĻ°ā§‡ āĻ…āĻ¨ā§‡āĻ• āĻ¸āĻšāĻœā§‡ āĻ¸ā§‡āĻ‡ āĻ…āĻŦāĻœā§‡āĻ•ā§āĻŸ (āĻŦāĻž āĻ…āĻŦāĻœā§‡āĻ•ā§āĻŸāĻ¸āĻŽā§‚āĻš) āĻŦā§āĻ¯āĻŦāĻšāĻžāĻ° āĻ•āĻ°āĻ¤ā§‡ āĻĒāĻžāĻ°āĻŦā§‡āĻ¨āĨ¤

āĻāĻŦāĻžāĻ° āĻšāĻ˛ā§āĻ¨ āĻ¸āĻšāĻœ āĻŦāĻžāĻ‚āĻ˛āĻžā§Ÿ āĻŦā§āĻāĻŋ āĻĢā§āĻ¯āĻžāĻ¸āĻžāĻĄ āĻ•āĻŋ (more…)

āĻĨāĻŋāĻŽāĻĢāĻ°ā§‡āĻ¸ā§āĻŸā§‡ āĻ“ā§ŸāĻžāĻ°ā§āĻĄāĻĒā§āĻ°ā§‡āĻ¸ āĻĨāĻŋāĻŽ āĻĒāĻžāĻŦāĻ˛āĻŋāĻļ āĻ•āĻ°āĻžāĻ° āĻ†āĻ—ā§‡ āĻāĻ•āĻŸāĻž āĻĒā§āĻ°ā§Ÿā§‹āĻœāĻ¨ā§€ā§Ÿ āĻšā§‡āĻ•āĻ˛āĻŋāĻ¸ā§āĻŸ

checklist

āĻ…āĻ¨ā§‡āĻ• āĻ•āĻˇā§āĻŸ āĻ•āĻ°ā§‡ āĻāĻŦāĻ‚ āĻ¸āĻŽā§Ÿ āĻŦā§āĻ¯ā§Ÿ āĻ•āĻ°ā§‡ āĻāĻ•āĻŸāĻž āĻ“ā§ŸāĻžāĻ°ā§āĻĄāĻĒā§āĻ°ā§‡āĻ¸ āĻĨāĻŋāĻŽ āĻ¤ā§ˆāĻ°ā§€ āĻ•āĻ°ā§‡ āĻ¤āĻžāĻ°āĻĒāĻ° āĻšāĻžāĻ°ā§āĻĄ āĻ°āĻŋāĻœā§‡āĻ•ā§āĻŸ āĻŦāĻž āĻāĻ•ā§‡āĻ° āĻĒāĻ° āĻāĻ• āĻ¸āĻĢāĻŸ āĻ°āĻŋāĻœā§‡āĻ•ā§āĻŸ āĻ–ā§‡āĻ˛ā§‡ āĻĻā§‡āĻ–āĻž āĻ¯āĻžā§Ÿ āĻ…āĻ¨ā§‡āĻ•ā§‡āĻ‡ āĻ•āĻ¨āĻĢāĻŋāĻĄā§‡āĻ¨ā§āĻ¸ āĻšāĻžāĻ°āĻŋā§Ÿā§‡ āĻĢā§‡āĻ˛ā§‡āĻ¨āĨ¤ āĻ¤āĻžāĻĻā§‡āĻ° āĻœāĻ¨ā§āĻ¯ āĻ†āĻœāĻ•ā§‡ āĻ†āĻŽāĻžāĻ° āĻ›ā§‹āĻŸā§āĻŸ āĻāĻ‡ āĻšā§‡āĻ•āĻ˛āĻŋāĻ¸ā§āĻŸ āĻ¯āĻžāĻ¤ā§‡āĻ•āĻ°ā§‡ āĻĒā§āĻ°ā§Ÿā§‹āĻœāĻ¨ā§€ā§Ÿ āĻ•āĻžāĻœāĻ—ā§āĻ˛ā§‹ āĻ†āĻ—ā§‡āĻ‡ āĻ āĻŋāĻ•āĻŽāĻ¤ āĻ•āĻ°ā§‡ āĻ°āĻžāĻ–āĻ¤ā§‡ āĻĒāĻžāĻ°ā§‡āĻ¨ āĻāĻŦāĻ‚ āĻ°āĻŋāĻœā§‡āĻ•āĻļāĻ¨ā§‡āĻ° āĻ¸āĻŽā§āĻ­āĻžāĻŦāĻ¨āĻžāĻ“ āĻ•āĻŽāĻŋā§Ÿā§‡ āĻĢā§‡āĻ˛āĻ¤ā§‡ āĻĒāĻžāĻ°ā§‡āĻ¨

ā§§. āĻ­ā§āĻ¯āĻžāĻ˛āĻŋāĻĄ āĻŽāĻžāĻ°ā§āĻ•āĻ†āĻĒ āĻ˛āĻŋāĻ–ā§āĻ¨āĨ¤ āĻŽāĻžāĻ°ā§āĻ•āĻ†āĻĒ āĻ¯āĻĻāĻŋ āĻŦā§āĻ°ā§‹āĻ•ā§‡āĻ¨ āĻšā§Ÿ āĻ¤āĻžāĻšāĻ˛ā§‡ āĻ¸ā§‡āĻŸāĻž āĻ°āĻŋāĻœā§‡āĻ•ā§āĻŸ āĻ–āĻžāĻ“ā§ŸāĻžāĻ° āĻ¸āĻŽā§āĻ­āĻžāĻŦāĻ¨āĻž āĻļāĻ¤āĻ•āĻ°āĻž ā§¯ā§¯ āĻ­āĻžāĻ—
ā§¨. āĻĄāĻŋāĻœāĻžāĻ‡āĻ¨ā§‡ āĻŦā§ˆāĻšāĻŋāĻ¤ā§āĻ° āĻ†āĻ¨āĻ¤ā§‡ āĻšāĻŦā§‡ āĻāĻŽāĻ¨ āĻ•ā§‹āĻ¨ āĻ•āĻĨāĻž āĻ¨ā§‡āĻ‡, āĻœāĻžāĻ¸ā§āĻŸ āĻ†āĻĒāĻ¨āĻžāĻ° āĻ•āĻžāĻœ āĻ¯ā§‡āĻ¨ āĻ¸āĻŦ āĻŦā§āĻ°āĻžāĻ‰āĻœāĻžāĻ°ā§‡ āĻ āĻŋāĻ• āĻŽāĻ¤ āĻšāĻ˛ā§‡ āĻ¸ā§‡āĻĻāĻŋāĻ•ā§‡ āĻ˛āĻ•ā§āĻˇā§āĻ¯ āĻ°āĻžāĻ–ā§āĻ¨āĨ¤
ā§Š. āĻŸāĻžāĻ‡āĻĒā§‹āĻ—ā§āĻ°āĻžāĻĢāĻŋ āĻāĻŦāĻ‚ āĻ•āĻ¨āĻŸā§‡āĻ¨ā§āĻŸā§‡āĻ° āĻŦāĻŋāĻ¨ā§āĻ¯āĻžāĻ¸ āĻ–ā§āĻŦāĻ‡ āĻĒā§āĻ°ā§Ÿā§‹āĻœāĻ¨ā§€ā§Ÿ āĻāĻ•āĻŸāĻž āĻŦāĻŋāĻˇā§ŸāĨ¤ āĻāĻ‡ āĻŦāĻŋāĻˇā§Ÿā§‡ āĻ…āĻ­āĻŋāĻœā§āĻž āĻšāĻŦāĻžāĻ° āĻœāĻ¨ā§āĻ¯ āĻ¨āĻ¤ā§āĻ¨ āĻŦāĻž āĻ…ā§āĻ¯āĻžāĻĒā§āĻ°ā§āĻ­ āĻšāĻ“ā§ŸāĻž āĻĨāĻŋāĻŽāĻ—ā§āĻ˛ā§‹ āĻŦā§‡āĻļā§€ āĻ•āĻ°ā§‡ āĻĻā§‡āĻ–ā§āĻ¨āĨ¤ āĻ–ā§āĻŦ āĻŦā§‡āĻļā§€ āĻāĻ˛āĻŋāĻŽā§‡āĻ¨ā§āĻŸ āĻĻā§‡ā§ŸāĻžāĻ° āĻšā§‡ā§Ÿā§‡ āĻŦāĻ°āĻ‚ āĻ†āĻ•āĻ°ā§āĻˇāĻ¨ā§€ā§Ÿ āĻ­āĻžāĻŦā§‡ āĻ‰āĻĒāĻ¸ā§āĻĨāĻžāĻĒāĻ¨ āĻ•āĻ°āĻžāĻŸāĻž āĻŦā§‡āĻļā§€ āĻœāĻ°ā§āĻ°ā§€ (more…)

SupportX – A rich support app-theme for Envato Authors built using WordPress

01_supportx_preview.__large_preview (1)
Last week, we have developed SupportX, a beautiful support theme based on WordPress. SupportX is built specially for the Envato marketplace authors where it’s a tedious job to provide proper support to the buyers of their product. It comes with a handful of useful features like SMS notification, live notification feed, purchase code verification and Knowledge base, and it doesn’t require to install external plugins like bbPress to use SupportX.

For $45, I must say that it’s a real bargain. You can purchase SupportX from Themeforest by going to this link http://bit.ly/1o90Wvc

With 1.1GB/s IO, Ramnode is possibly one of the best VPS providers out there

When you search for low end boxes, you may think that services are not up to the mark with these providers. Guess what, You are WRONG, so WRONG indeed. There are a few providers who gives you a top class services, despite their price point.

Ramnode

I have been using Ramnode for almost 6 months by now, had used Rackspace and Amazon EC2 before and I am not a big fan of them except the instant resource modification feature. When I purchased my first box from Ramnode, I was just thinking let’s give a try. And once I started, I totally loved their services. From 1Gbit network to an amazing RAID10 setup that gives you upto 1.3 GB/s in SSD and 800MB/s in SSD Cached VPSes. Here is the result of dd test in one of my SSD boxes.

[sourcecode language=”shell”]
d if=/dev/zero of=iotest bs=64k count=16k conv=fdatasync && rm -rf iotest
16384+0 records in
16384+0 records out
1073741824 bytes (1.1 GB) copied, 1.01694 s, 1.1 GB/s
[/sourcecode]

and here is the result from one of my SSD cached boxes

[sourcecode language=”shell”]
dd if=/dev/zero of=iotest bs=64k count=16k conv=fdatasync && rm -rf iotest
16384+0 records in
16384+0 records out
1073741824 bytes (1.1 GB) copied, 1.37957 s, 778 MB/s
[/sourcecode]

Ramnode has been a great provider to many people out there for last 2 years, and several time won the quarterly poll arranged by LEB community. Give it a shot anytime without worrying much, you won’t be disappointed. And beside enjoying such a great servcie, enjoy an additional discount of 38% by using the coupon code WOWNUM1 for any of their plans.

Integrate Social Sign On in your PHP apps using HybridAuth

nt.social.network.big_

Integrating social sign-ons in a web application can become a tedious task because you need to take care of different endpoints, credentials and finally manage the oauth dance to get the access token. However, using HybridAuth package, this task can be easy as pie 🙂 Let’s have a look

In this example I will show you how to connect to Facebook and Twitter using HybridAuth. So you need to create two applications in Facebook and Twitter each. Save those app’s id and secret somewhere because we will need that in a minute.

Step 1: Install the Package via Composer

Composer is an excellent package manager for PHP apps. Let’s use that to install HybridAuth in our current projects scope. Add a composer.json file in your project path, or update it with the following contents if it already exists. But before that, make sure that you have composer installed in this machine.

[sourcecode language=”javascript”]
{
"require": {
"hybridauth/hybridauth": "3.0.0.*@dev"
}
}
[/sourcecode]

now run the following command to install hybridauth

[sourcecode language=”shell”]
composer install
[/sourcecode]

Step 2: Connect with Facebook

Let’s make a good use of this HybridAuth. This time we need to create two files, fb.php and hybrid.php. Make sure that your facebook app’s callback url points to this hybrid.php. FOllowing is the code of fb.php (more…)

Automated Rsync – without compromising security

Rsync is one of the most popular tools to synchronize data between two computers, and used mostly in taking backups using this sync feature. It’s easy to use and only uploads the changed files when a sync is necessary, so it’s effective in saving bandwidth and time too. To run rsync, you need root or a properly privileged user which can access that specific path in the remote machine. And to setup this privilege, you can either use a should-never-be-used root account or an user chrooted using a jail shell. But if, by any chance, current machine is compromised then remote machine is compromised too. Because anyone can connect to your remote machine using those credentials from the current machine. To avoid plain text credentials (or the credentials written in a shell script), people usually use ssh keys to establish a connection between two machines. Still, your remote machine is unsecured if anything goes wrong in the current machine from where you’re taking the backup.

So a fullproof solution is to use ssh keys and properly chroot the remote user so that it can only access the backup files and nothing else. However, setting up a jailed shell is a not-for-everyone type task and takes time and experience to accomplish properly. So here is a quick work around that you can implement in your remote machine to prevent the connecting user from doing anything malicious but only tasks those are needed to perform the rsync backup. Let’s see how we can do that

Before continuing, let’s name our two machines. The one which should be backed up, lets name that Workstation. And the one which is storing the backups is BackupServer. Also for now, let’s assume that you are backing up complete “/var/www” folder in the WorkStation.

Step 1: Create SSH key in the BackupServer
Log into the BackupServer and run the following command in ssh terminal. But remember, if you already have a key in ~/.ssh/id_rsa.pub then IGNORE IGNORE IGNORE this step.

[sourcecode language=”shell”]
ssh-keygen -t rsa
[/sourcecode]

It will prompt for a passphrase, REMEMBER to just hit the enter without typing anything.

Step 2: Display and Copy the SSH key from BackupServer
Run the following command to display the ssh public key in the terminal, and then copy it.
(more…)

BucketAdmin – Our new dashboard for your next web application

01_bucketmin_preview.__large_preview

If you are a fan of beautiful dashboards and admin panels, then BucketAdmin might be a good choice for you with plenty of carefully selected javascript controls and plugins. Beside that, BucketAdmin’s documentation and clean structure will help you to implement it without a lot of pain. Purchase BucketAdmin today for $21 only from http://bit.ly/1e9TtGP.

Here is a collection of a few cool features of BucketAdmin

BucketAdmin Features

WordPress Plugin Boilerplate Code Generator from Tom Mcfarlin's Plugin Boilerplate

Tom Mcfarlin has written an excellent boilerplate for plugin developers. It is very easy to start writing your own plugins using his boilerplate. But if you want to personalize it to YourPluginName, you will have to modify all these files and replace hardcoded variables and class names which is a real pain in the ass.

So I have created a code generator which takes Tom Mcfarlin’s repository and replace everything (wherever necessary) by your plugin name, author name etc and personalize it so that you can download and start using it right away.

Check out this code generator at http://codegen.kickapz.com

You can download the source code of this code generator at https://github.com/hasinhayder/plugin-boilerplate-code-generator

Writing a new plugin is now painless 🙂

Create personalized phar files in PHP

Created a screencast to show how you can create phar files, most importantly personalized phar files to store some information inside it and protect it using user’s password. Those information is usable only when user providers a correct password.

For packaging, I used http://box-project.org which is an excellent phar packager. I’ve also used two functions from Josh Hartman’s blog to encrypt and decrypt data using Rijndael algorithm.

www.youtube.com/watch?v=V-1NgA5T4Bw