Skip to content

Instantly share code, notes, and snippets.

View barryvdh's full-sized avatar

Barry vd. Heuvel barryvdh

View GitHub Profile
@barryvdh
barryvdh / PushAll.php
Created September 27, 2016 08:14
PushAll example
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Support\Collection;
trait PushAll {
@barryvdh
barryvdh / pre-commit
Last active December 5, 2024 18:50
phpunit pre-commit git hook
#!/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 "Aborting commit.." . PHP_EOL;
@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);
}
@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
<?php
class Csv
{
public static function fromArray($rows, $delimiter = ',')
{
if (empty($rows)) {
return '';
}
<!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;
}
@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.
<?php
namespace App\Libraries;
use ReflectionClass;
use ReflectionMethod;
use Illuminate\Support\Str;
/**
* @deprecated since version 5.2.
@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
# 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;