Skip to content

Instantly share code, notes, and snippets.

View martinbean's full-sized avatar

Martin Bean martinbean

View GitHub Profile
@martinbean
martinbean / confirm.js
Created November 27, 2017 23:22
Vue.js confirm mixin
module.exports = {
methods: {
confirm(message, callback) {
if (window.confirm(message)) {
callback();
}
}
}
};
@martinbean
martinbean / test.php
Created February 6, 2018 18:34
Throw a validation exception with a plain array of errors
<?php
use Illuminate\Validation\ValidationException;
if ($coupon->cannotBeRedeemed()) {
throw ValidationException::withMessages([
'coupon' => [
'The coupon code is invalid.',
],
]);
@martinbean
martinbean / AppServiceProvider.php
Last active March 1, 2018 11:06
Disable Bugsnag in certain environments
<?php
namespace App\Providers;
use Bugsnag\BugsnagLaravel\Facades\Bugsnag;
use Illuminate\Support\ServiceProvider;
class AppServiceProvider extends ServiceProvider
{
public function boot()
vendor/bin/phpunit --printer="PHPUnit\TextUI\ResultPrinter"
@martinbean
martinbean / plugin.ajax_submit.js
Created April 1, 2015 11:41
jQuery AJAX submit plugin
// Submit a form via AJAX and return the request object
$.fn.ajaxSubmit = function (options) {
var settings = $.extend({
submittingText: 'Submitting...'
}, options);
var form = $(this);
var url = form.attr('action');
var data = form.serialize();
var type = form.attr('method');
var submitButton = form.find('[type="submit"]');
@martinbean
martinbean / webpack.mix.js
Created May 17, 2018 14:17
Vendor library extraction in Laravel Mix
let mix = require('laravel-mix');
mix.sass('resources/assets/sass/app.scss', 'public/css')
.js('resources/assets/js/app.js', 'public/js')
.js('resources/assets/js/channel-admin.js', 'public/js')
.js('resources/assets/js/video.js', 'public/js')
.extract(['jquery', 'bootstrap'])
.options({ processCssUrls: false })
.sourceMaps();
@martinbean
martinbean / Adapter.php
Last active July 9, 2018 08:32
Basic ORM sketch that uses value objects, data mappers that persists data to a data source, and adapters for data sources.
<?php
abstract class Adapter
{
protected $config;
protected $connection;
public function __construct($config)
{
$this->config = $config;
@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 / styles.css
Created March 2, 2019 19:38
End mark in HTML
p:last-of-type::after {
content: "\0020 \220E"
}
@martinbean
martinbean / LogNameHandler.php
Last active March 15, 2019 14:42
Mapping jobs to handler classes in Lumen
<?php
namespace App\Handlers\Jobs;
use App\Jobs\LogNameJob;
use Illuminate\Support\Facades\Log;
class LogNameHandler
{
public function __construct()