Saturday, August 15, 2015

Guzzle 6 OAuth Issue for twitter authentication

There are is a major change has been made in Guzzle 6 and for this architecture changes in 6.0 have now broken most available OAuth plugin packages, including their own oauth-subscriber that hasn’t seen a new version since 5.* fixes in October 2014.

YAML configs must also be changed to handle the new middleware architecture.

Note for user-defined parameters, base_url has become base_uri to match changes to the Client constructor’s named arguments. To define this argument, 6.0 uses UriInterface which I believe doesn’t support placeholders so I’ve just placed the Twitter version directly in the base_uriconfiguration string.


// composer.json
{
    "require": {
        "guzzlehttp/guzzle": "~6.0",
        "guzzlehttp/oauth-subscriber": "dev-master"
    },
}


Changes from 5.*

Middleware HandlerStack::create() must be used for the OAuth1 instance and passed into the Client constructor.

Guzzle 5.* 

There were no major architectural changes in this version so you can keep the above configuration. However you must upgrade oauth-subscriber to 0.2.0 since 0.1.* is only compatible with 4.0.

// composer.json
{
    "require": {
        "guzzlehttp/guzzle": "^5.0",
        "guzzlehttp/oauth-subscriber": "0.2.*"
    },
}


To know more about the service/repository got to the following link

https://github.com/guzzle/oauth-subscriber

Tuesday, August 4, 2015

Nice way to copy the SSH Key using Alias in MAC

Here you can do it in easy way. Just run this following command from the terminal and you are good to go



cat ~/.ssh/id_rsa.pub | pbcopy && echo 'Copied to clipboard'


Saturday, October 18, 2014

MySQL - Reset a lost MySQL root password

Not the Server root user

A common issue is confusing the Server root user with the MySQL root user.
The Server root user is the server's main user. The MySQL root user has complete control over MySQL only. The two 'root' users are not connected in any way.

Stop MySQL

The first thing to do is stop MySQL. If you are using Ubuntu or Debian the command is as follows:
sudo /etc/init.d/mysql stop
For CentOS, Fedora, and RHEL the command is:
sudo /etc/init.d/mysqld stop

Safe mode

Next we need to start MySQL in safe mode - that is to say, we will start MySQL but skip the user privileges table. Again, note that you will need to have sudo access for these commands so you don't need to worry about any user being able to reset the MySQL root password:
sudo mysqld_safe --skip-grant-tables &
Note: The ampersand (&) at the end of the command is required.

Login

All we need to do now is to log into MySQL and set the password.
mysql -u root
Note: No password is required at this stage as when we started MySQL we skipped the user privileges table.
Next, instruct MySQL which database to use:
use mysql;

Reset Password

Enter the new password for the root user as follows:
update user set password=PASSWORD("mynewpassword") where User='root';
and finally, flush the privileges:
flush privileges;

Restart

Now the password has been reset, we need to restart MySQL by logging out:
quit
and simply stopping and starting MySQL.

On Ubuntu and Debian:

sudo /etc/init.d/mysql stop ... sudo /etc/init.d/mysql start

On CentOS and Fedora and RHEL:

sudo /etc/init.d/mysqld stop ... sudo /etc/init.d/mysql start

Login

Test the new password by logging in:
mysql -u root -p
You will be prompted for your new password.

How to Install Android 5.0 Lollipop in Nexus 5 form your MAC

I have a Nexus 5 and going to show you the most easy way to install Android 5.0 Lollipop in Nexus 5. I have installed it in my Nexus device and would like to share with you what I have done step by step..

You will need the newly updated Android L (or Android 5.0) factory images provided by Google to install on your device. In addition you will need to install the Android SDK or at least ADB and Fastboot.

The Android 5.0 System Image is a download that contains all the files needed to install a stock version of Android 5.0 on the Nexus 7 and Nexus 5. This is essentially everything that you would download as an OTA update for regular Android updates. However, this makes the phone stock like it was out of the box (aka factory image) and will wipe all user data and settings.

So please be careful before you do this.. backup your Data, Photos, Contact, SMS, MMS and Apps.

Now lets move step by step.

Step 1: Download Android 5 Image

Download the image of Android Lollipop from the following location.

http://storage.googleapis.com/androiddevelopers/finalpreview/hammerhead-lpx13d-preview-f7596f51.tgz

This was the final version when I download it but you can download the latest version going to the following link.

http://developer.android.com/preview/index.html

After download the Image(.tgz) please unzip to your desktop. Please make sure you run you command inside this folder.


Step 2: Install ADB on Mac, Linux & ChromeOS

Nexus Tools makes it easy to install ADB on a Mac, Linux or even ChromeOS. All you need to do is open Terminal on your computer and past in the code from xda. Open terminal by going to search, and simply typing Terminal and opening the program.

Nexus Tools is an installer for the Android debug/development command-line tools ADB (Android Device Bridge) and Fastboot for Mac OS X, Linux, and Google Chrome/Chromium OS. The script does not need to be downloaded, simply copy and paste this command into the terminal and run it to install Nexus Tools:

bash <(curl https://raw.githubusercontent.com/corbindavenport/nexus-tools/master/install.sh)

and this command to un-install Nexus Tools:

bash <(curl https://raw.githubusercontent.com/corbindavenport/nexus-tools/master/uninstall.sh)


Step 3: Next Step


If your Nexus 5 or Nexus 7 is not unlocked you should do that first. We could not install the Android 5.0 System image with the device locked.

Open a Terminal in the adb folder and type then hit enter.

adb reboot bootloader

In Fastboot type:

fastboot oem unlock

Then hit enter. Follow the on-screen instructions and choose to erase the device. Wait a minute or so for it to unlock. This removes everything on your device.

on a Mac or other computer you will need to type

sudo ./flash-all.sh

This will push all of the files to your Nexus 5 or Nexus 7. The files will start pushing and installing and your Nexus device may reboot and you will see an Android figure and then a moving Android logo. The logo screen may stay for a long time. Don’t unplug the device. This may last 15 minutes or longer. When Android prompts you to complete setup you can unplug the Nexus. It took less than two minutes for us.

Tuesday, September 16, 2014

Show a default image if one doesn’t exist!!!

Do you want to show default image if the image url doesn’t exist? Using jQuery it can be done. Please try the following code..

var img = $('img');
var default_url = "http://example.org/images/img.jpg";
var img_url = "http://example.org/images/" + some_variable + ".jpg";
img.error(function() {
  $(this).attr('src', default_url) 
});
img.attr('src', img_url);

Sunday, September 14, 2014

Installing PHP Mongo Driver on MAMP

To install latest Mongo driver on MAMP

1 - install autoconf using homebrew or Mac Ports
brew install autoconf
2 - Download php 5.4.10 source from php.net.
3 - rename uncompressed php source folder from php-5.4.10 to php and paste it in this folder
/Applications/MAMP/bin/php/php5.4.10/include/
4- using the terminal open php folder and run ./configure
cd /Applications/MAMP/bin/php/php5.4.10/include/php/ && ./configure
5 - Add MAMP bin to your ~/.bash_profile
echo "export PATH=/Applications/MAMP/bin/php/php5.4.10/bin:$PATH" >> ~/.bash_profile source ~/.bash_profile
6 - install latest mongo
pecl install mongo
7- restart MAMP server :).
8- Enable the extension Edit /Applications/MAMP/bin/php/php5.4.10/conf/php.ini Add the following line after the section named "; Extensions":
extension=mongo.so

Friday, September 12, 2014

Few tips on Wordpress and few Cheet Sheet


Improve Page Titles


If you want the page title to be the title of the post, edit header.php  file  and change the title tag as follows:

<title>
<?php if ( is_home() ) {  bloginfo('name'); echo(' — ');  bloginfo('description'); } else wp_title('',true); ?>
</title>


Improve Permalink Structure


If you want to have the page urls for each post as http://www.mysite.com/seo-title/

Follow

> Login
> Go to Options
> Then click on Permalinks
> Change the format to ‘Custom’ with the following format
/%postname%/
> Submit

You can also use post slugs to manually tweak the url. E.g. You might want to change:
http://www.mysite.com/long-and-very-long-title-might-not-good-looking/
http://www.mysite.com/short-one/


Date Problem solution for Post


When there are multiple posts on a page published under the SAME DAY, the_date() only displays the date for the first post (that is, the first instance of the_date()). To repeat the date for posts published under the same day, you should use the Template Tag the_time() or get_the_date() (since 3.0) with a date-specific format string.
Use <?php the_time( get_option( 'date_format' ) ); ?> to add the date set in the admin interface.

Wordpress : The Loop Visual Model



Tuesday, February 4, 2014

Bootstrap Pagination in CakePHP

<div class="pagination">
    <ul>
        <?php 
            echo $this->Paginator->prev( '<<', array( 'class' => '', 'tag' => 'li' ), null, array( 'class' => 'disabled myclass', 'tag' => 'li' ) );
            echo $this->Paginator->numbers( array( 'tag' => 'li', 'separator' => '', 'currentClass' => 'disabled pg_design' ) );
            echo $this->Paginator->next( '>>', array( 'class' => '', 'tag' => 'li' ), null, array( 'class' => 'disabled myclass', 'tag' => 'li' ) );
        ?>
    </ul>
</div>
CSS for which need to add
.pagination ul > li.pg_design {
    float: left;
    padding: 4px 12px;
    line-height: 20px;
    text-decoration: none;
    background-color: #ffffff;
    border: 1px solid #dddddd;
    border-left-width: 0;
    color: #999999;
    cursor: default;
    background-color: transparent;
}

.pagination ul > li.pg_design:first-child {
    border-left-width: 1px;
    -webkit-border-bottom-left-radius: 4px;
    border-bottom-left-radius: 4px;
    -webkit-border-top-left-radius: 4px;
    border-top-left-radius: 4px;
    -moz-border-radius-bottomleft: 4px;
    -moz-border-radius-topleft: 4px;
}

.pagination ul > li.pg_design:last-child {
    -webkit-border-top-right-radius: 4px;
    border-top-right-radius: 4px;
    -webkit-border-bottom-right-radius: 4px;
    border-bottom-right-radius: 4px;
    -moz-border-radius-topright: 4px;
    -moz-border-radius-bottomright: 4px;
}

Saturday, January 18, 2014

Some Useful Linux command to get Linux System Information

If you are developing an application Linux Environment and would like to automatically find out more information about the system, use the following commands in shell scripts to get information about system.

Find out KDE Desktop version:

konqueror --version
Find out Gnome Desktop version:

gnome-panel --version
Find out disk space usage:

df -h
Find/Estimate file space usage:

du -h
Find out version of Linux glibc:

ls -l /lib/libc-*.so /lib/libc.so*
Find out user limits:

ulimit -a
Find out installed device drivers (modules)

lsmod
Find out information about Linux CPU

cat /proc/cpuinfo
Find out information about Linux Memory

cat /proc/meminfo
OR
free -m
OR
free -g
Find out user shell name:

ps -p $$ | tail -1 | awk '{ print $4 }'
Dump Linux kernel variables
/sbin/sysctl -a
Find out running Linux kernel version:

uname -mrs
uname -a
cat /proc/version
Dump or display memory information and swap information:

free -m
Network card and IP address information:

ifconfig -a
ifconfig -a|less
Debian / Ubuntu Linux network configuration file (all interface eth0,eth1,...ethN)

more /etc/network/interfaces
Redhat / CentOS / Fedora Linux network configuration file (eth0)

more  /etc/sysconfig/network-scripts/ifcfg-eth0
Note replace eth1 for 2nd network card and so on.
Display routing information

route -n
route
Display list of all open ports

netstat -tulpn
View login related logs

tail -f /var/log/secure
vi /var/log/secure
grep 'something' /var/log/secure
View mail server related logs

tail -f /var/log/maillog
vi /var/log/maillog
grep 'something' /var/log/maillog
Find how long the system has been running

uname
w
Show who is logged on and what they are doing

w
who
Display list of tasks

top
Display all running process

ps aux
ps aux | grep process-name
Display list of all installed software on Redhat / CentOS / Fedora

rpm -qa
rpm -qa | grep 'software-name'
rpm -qa | less
Display list of all installed software on Debian / Ubuntu

dpkg --list







Friday, November 22, 2013

EC2 Ubuntu Apache PHP MySQL Setup


  1. In order to connect to the instance we need to assign an IP address. In the left menu in the EC2 Management Console select Elastic IPs under Network & Security. Allocate a new address and assign it to your instance. Elastic IPs are free as long as they are assigned to an instance, so remeber not to leave any unallocated IP addresses as you will get charged by the hour. Remember the assigned IP.
  2. On your local machine use the pem key to SSH into your instance. On OS X change the permission of the key to 600 and use following command in terminal:
    ssh -i yourkeyname.pem ubuntu@yourelasticip
    and boom you are in.
  3. Update the Ubuntu package manager and the installed packages:
    sudo apt-get update
    sudo apt-get dist-upgrade
  4. Install Apache:
    sudo apt-get install apache2
  5. Enable .htaccess files by editing the /etc/apache2/sites-available/default file, fx with vi or nano. Look for the /var/www directory and make sure it contains AllowOverride All.     <Directory /var/www/>
                    Options Indexes FollowSymLinks MultiViews
                    AllowOverride All
                    Order allow,deny
                    allow from all
    </Directory>
  6. Enable the rewrite module in Apache:
    sudo a2enmod rewrite
  7. Install PHP5:
    sudo apt-get install libapache2-mod-php5
  8. Restart Apache:
    sudo /etc/init.d/apache2 restart
  9. Ensure that Apache is running by typing the instance IP in your browser.
  10. Allow the Ubuntu user to work with the /var/www folder:
    sudo adduser ubuntu www-data
    sudo chown -R www-data:www-data /var/www
    sudo chmod -R g+rw /var/www
    Logout and login again to pick up the new user group. Test by creating a directory and deleting it again in www without having to sudo. This will make your life easier since permissions will get messed up less once you start adding frameworks and tools to your web service.
  11. Test PHP by cd into /var/www folder and typing sudo vi phptest.php. Hit i key to enter insert mode and just write a simple php script with a phpinfo() call.
    Hit ESC to exit insert mode and type :wq to save and quit the vi editor. Go to instanceIP/phptest.php in your browser and you should see the phpinfo displayed.
  12. Install MySQL:
    sudo apt-get install mysql-server
    sudo apt-get install php5-mysql
    Insert root password for the database and remember it.
  13. To test MySQL let’s install PHPMyAdmin:
    sudo apt-get install phpmyadmin
Next I think you need to install git.I don't prefer to use FTP client.
  1. sudo apt-get install git

Wednesday, August 28, 2013

How to run Composer autoload and CodeIgniter autoload simultaneously

Did you tried to install composer and then you existing CodeIgniter Autoload stop working!!! It happened because __autoload is the old, deprecated way of doing autoloading and you can have only one.

How to run it?
You should register your autoloader using spl_autoload_register.
How you will do it in your code..Here is an example below...

function MY_CI_Autoload($class)
{
 if(strpos($class, 'CI_') !== 0)
 {
  @include_once( APPPATH . 'core/'. $class . EXT );
 }
}

spl_autoload_register('MY_CI_Autoload');

This way your autoloader and composer's will coexist happily.