Skip to content

Instantly share code, notes, and snippets.

View martinbean's full-sized avatar

Martin Bean martinbean

View GitHub Profile
@martinbean
martinbean / Article.php
Created January 3, 2017 16:41
Request-driven development
<?php
namespace App\News;
use Illuminate\Database\Eloquent\Model;
class Article extends Model
{
public function publish()
{
@martinbean
martinbean / BladeServiceProvider.php
Last active October 26, 2016 11:32
Laravel Blade directive for FontAwesome icons.
<?php
namespace App\Providers;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
class BladeServiceProvider extends ServiceProvider
{
/**
@martinbean
martinbean / ValidationServiceProvider.php
Last active July 23, 2018 14:23
Sum (of an array) validation in Laravel
<?php
namespace App\Providers;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\ServiceProvider;
use InvalidArgumentException;
class ValidationServiceProvider extends ServiceProvider
{
@martinbean
martinbean / macros.php
Created July 30, 2016 10:48
Laravel Request startsWith and endsWith macros
<?php
use Illuminate\Support\Facades\Request;
use Illuminate\Support\Str;
Request::macro('startsWith', function () {
return Str::startsWith(func_get_args());
});
Request::macro('endsWith', function () {
@martinbean
martinbean / convert-seconds.js
Created July 13, 2016 08:03
Convert seconds to HH:MM:SS format in JavaScript.
new Date(seconds * 1000).toISOString().substr(11, 8)
@martinbean
martinbean / VerifySnsMessageCameFromAmazon.php
Created July 8, 2016 21:01
Laravel 5.x middleware to verify an SNS request came from Amazon.
<?php
namespace App\Http\Middleware;
use Aws\Sns\Message;
use Aws\Sns\MessageValidator;
use Closure;
class VerifySnsMessageCameFromAmazon
{
@martinbean
martinbean / function.js
Created June 8, 2016 09:36
Lambda function to send Slack notification on deployment
'use strict';
const https = require('https');
const querystring = require('querystring');
String.prototype.capitalizeFirstLetter = function () {
return this.charAt(0).toUpperCase() + this.slice(1);
}
exports.handler = function (event, context) {
@martinbean
martinbean / replace-dots.js
Created June 1, 2016 14:37
Converts dotted notation (`some.dotted.string`) to HTML format (i.e. `some[dotted][string]`).
key.replace(/\.(\w+)/g, '[$1]');
@martinbean
martinbean / pre-commit
Last active December 19, 2023 22:14
Pre-commit hook to detect if any .php files contain dd()
#!/usr/bin/php
<?php
$files = shell_exec('git diff-index --name-only --cached --diff-filter=ACMR HEAD | grep "\.php$"');
$files = explode("\n", trim($files));
$exitCode = 0;
foreach ($files as $file) {
if (empty($file)) {
@martinbean
martinbean / after.sh
Created January 22, 2016 11:29
Per-project Homestead after.sh and aliases
#!/bin/sh
cd 'project-dir'
composer install
php artisan migrate
php artisan db:seed
npm install --loglevel error
export DISABLE_NOTIFIER=true
gulp