Topics

Solutions

Easy solutions and ideas found after long googling or hard coding

AWS PHP Service Discovery

Service Discovery is a simple PHP command to collect and store AWS information such as EC2s and RDSs in the current region and save them with their credentials into an encrypted JSON file on S3. The script later notifies each service via SSH and executes the service discovery client on each instance. Each client downloads the JSON file and uses it to configure different applications. It can easily be automated through Rundeck or Jenkins to be executed after each deploy.

Service Discovery is part of AWS PHP Commands.

Usage:

> php console.php aws:services:discover -h
Usage:
  aws:services:discover [options]

Options:
  -f, --forceNotify[=FORCENOTIFY]          Force Notify [default: false]
  -e, --notifyOnly[=NOTIFYONLY]            Notify only one of dev,prod [default: false]
  -c, --continueOnError[=CONTINUEONERROR]  Continue to next EC2 on client failure [default: false]
  -h, --help                               Display this help message
  -q, --quiet                              Do not output any message
  -V, --version                            Display this application version
      --ansi                               Force ANSI output
      --no-ansi                            Disable ANSI output
  -n, --no-interaction                     Do not ask any interactive question
  -v|vv|vvv, --verbose                     Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

Help:
 Discovers services information and credentials.

Simple MySQL migration bash script

#!/usr/bin/env bash

set -e


mkdir -p /root/tmp

#migrate "original db params" "new db params" "new db name"
function migrate(){
    mysqldump --skip-lock-tables --single-transaction --add-drop-table $1 > /root/tmp/${3}.sql
    echo "CREATE DATABASE IF NOT EXISTS ${3};" | mysql $2
    mysql --max_allowed_packet=1000M $2  $3 < /root/tmp/${3}.sql
    rm -f /root/tmp/${3}.sql
}


migrate "-uolduser -poldpassword -h oldhost olddbname" "-unewuser -pnewpassword -h newhost" "newdbname"

#more migrates here ...

Fork here

Keywords Highlighter

Simple keyword highlighter for your google searches. Enabling the extension will automatically highlight all keywords with different colors on all pages.

Screen Shot 2016-02-10 at 3.30.26 AM

Download from Chrome Store
Check Source Code

Fix W3 Total Cache W3_Plugin_TotalCache::ob_callback() expected to be a reference

Around a year ago I was playing with W3 Total Cache plugin on HHVM while I got an annoying warning

Warning: Parameter 1 to W3_Plugin_TotalCache::ob_callback() expected to be a reference, value given in /wp-includes/functions.php on line 3269

The funny part is that one of the functions was passing by reference which I still could not find the reason for it, maybe it was a limitation in PHP 4.3. Removing one character “&” fixed the issue so I submitted a pull request to the author although the repository currently does not accept pull request. Later on as PHP 7.0 was released, the issue started to show on PHP as well which brought more attention to this small fix. The users comments included anger such as user @kmob2 who said
this is becoming a running gag

Even more user @pratham2003 proposed a one line bash command to solve the problem

sed -i.bak 's/function ob_callback(&/function ob_callback(/g' /path/to/public_html/wp-content/plugins/w3-total-cache/lib/W3/Plugin/TotalCache.php

I hope that the developers will finally listen to the users and fix it soon!

AWS Client v1.1

AWS Client is an open source JavaFX GUI desktop application for Amazon EC2, providing monitoring and filtering controls over your EC2 server instances in different regions. It also allows you to easily interact with your instances via your SSH client. More functionality will be added soon so follow my blog and watch AWS Client code on GitHub

Screen Shot 2016-01-28 at 2.01.59 AM



Download for Mac OSX and Windows
Source Code