Skip to content

Instantly share code, notes, and snippets.

@barryvdh
barryvdh / deploy.php
Last active September 7, 2018 03:01 — forked from jakebathman/logslaravel.sh
Tail Laravel logs and filter out the stack traces using https://deployer.org/
desc('Tail your laravel.log file');
task('tail', function () {
$numLines = isVerbose() ? '100' : '1000';
$tail = "tail -n {$numLines} {{deploy_path}}/current/storage/logs/laravel*.log ";
if (!isVerbose()) {
// Change -P to -E, depending on OS or grep version.
$tail .= '| grep -i -P "^\[\d{4}\-\d{2}\-\d{2} \d{2}:\d{2}:\d{2}\]|Next [\w\W]+?\:" | tail -n 100 ';
}
$output = run($tail);
@barryvdh
barryvdh / imageoptim.sh
Created July 17, 2018 08:23
Optimize images in last 24 hours
#!/bin/bash
find ./media -mmin -1440 -type f -iname '*.gif' -exec sh -c 'gifsicle -b -O3 "{}"' \;
find ./media -mmin -1440 -type f -iname '*.png' -exec optipng -o7 -strip all -preserve '{}' \;
find ./media -mmin -1440 -type f -iname '*.jpg' -exec jpegoptim --strip-all -m85 -o -p {} \;
# FORGE CONFIG (DOT NOT REMOVE!)
include forge-conf/default/before/*;
upstream fastcgi_backend {
server unix:/var/run/php/php7.1-fpm.sock;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
@barryvdh
barryvdh / ForceHttps.php
Created August 22, 2017 09:47
Force HTTPS Middleware
<?php
namespace App\Http\Middleware;
use Closure;
class ForceHttps
{
/**
* Force non-local requests to be HTTPS
<?php
namespace App\Libraries;
use ReflectionClass;
use ReflectionMethod;
use Illuminate\Support\Str;
/**
* @deprecated since version 5.2.
@barryvdh
barryvdh / .htaccess
Last active August 4, 2017 10:20
Disable PHP execution
# Turn off all options we don't need.
Options None
Options +FollowSymLinks
# Set the catch-all handler to prevent scripts from being executed.
SetHandler Security_Do_Not_Remove_This_Line
<Files *>
# Override the handler again if we're run later in the evaluation list.
SetHandler Security_Do_Not_Remove_This_Line
</Files>
# If we know how to do it safely, disable the PHP engine entirely.
<!DOCTYPE html>
<html dir="ltr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>Google Doc viewer</title>
<style type="text/css">
body, html {
margin: 0; padding: 0; height: 100%; overflow: hidden;
}
<?php
class Csv
{
public static function fromArray($rows, $delimiter = ',')
{
if (empty($rows)) {
return '';
}
@barryvdh
barryvdh / Xml.php
Last active January 14, 2021 09:10
XML Helper (from/to array)
<?php
use SimpleXMLElement;
class Xml {
/**
* @param array $data
* @param string $root
* @return SimpleXMLElement
@barryvdh
barryvdh / pre-push
Created November 2, 2016 12:39
Git pre-push hook for PHPUnit
#!/usr/bin/env php
<?php
echo "Running tests.. ";
exec('vendor/bin/phpunit', $output, $returnCode);
if ($returnCode !== 0) {
// Show full output
echo PHP_EOL . implode($output, PHP_EOL) . PHP_EOL;
echo "Cannot push changes untill tests are OK.." . PHP_EOL;
exit(1);
}