Skip to content

Instantly share code, notes, and snippets.

@wishfoundry
wishfoundry / Laravel 4 Trailing slashes
Created January 17, 2013 20:45
Match any route with a trailing slash and redirect to the correct one
Route::get('{any}', function($url){
return Redirect::to(mb_substr($url, 0, -1), 301);
})->where('any', '(.*)\/$');
@wishfoundry
wishfoundry / gist:4126316
Created November 21, 2012 17:34
image resize
if ($image_w < $image_h)
{
//portrait
$height = $max_height;
$width = round( $height*($image_w/$image_h) );
}
if($image_w => $image_h)
{
//landscape
if($image_h < ($image_w/2))
@wishfoundry
wishfoundry / fork.js
Created August 24, 2012 18:56
Node unix socket worker process
if (cluster.isMaster) {
var cpus = os.cpus().length;
var worker;
/* start up the HTTP servers */
process.env.HTTP_WORKER = "1";
for (var i = 0; i < cpus; i++) {
worker = cluster.fork();
worker.isHTTP = true;
}