Getting input from stdin during composer installation

By adding a “post-install-cmd” option to your scripts section of composer.json you can setup commands to run after “composer install”, however, these won’t wait for input if you want to collect something (like a username)Β in a php script.

You can have the exact same effect though by calling the function like so —

"post-install-cmd": [
"MyApp\\Commands\\Class::function"
]

Where Class is your classname and function is a static function that uses stdin to get information.

Laravel redirect HTTP to HTTPS

Add this to your filters.php to automatically redirect HTTP traffic to HTTPS on your Laravel install.

App::before(function($request)
{
if( ! Request::secure())
{
return Redirect::secure(Request::getRequestUri());
}
});

Disable all browser page caching in Laravel

Sometimes you don’t want to allow any content coming out of Laravel to be cached. The easiest way of doing this is a filter to send no cache headers. Add this snippet to the bottom of your filters.php file.

Route::filter('after', function($response)
{
// No caching for pages
$response->header("Pragma", "no-cache");
$response->header("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0");
});

HAProxy SSL cipher list

This is the haproxy cipher list Snapt is most likely going to roll out next:

ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-RC4-SHA:ECDHE-RSA-RC4-SHA:ECDH-ECDSA-RC4-SHA:ECDH-RSA-RC4-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:RC4-SHA

If you are using haproxy for SSL termination it’s a good idea to manually specify a cipher list to prevent attacks like BEAST, or other protocol weaknesses.

Show signs on PHP numbers

PHP automatically shows a negative sign for negative numbers but getting it to show a positive sign (e.g. when you are showing growth/loss) can be a mess of if statements. Rather, use this —

sprintf("%+d", $number);

You’ll then get +1234 instead of just 1234.