Skip to content

Instantly share code, notes, and snippets.

View Braunson's full-sized avatar

Braunson Yager Braunson

View GitHub Profile
@Braunson
Braunson / ClearBeanstalkdQueueCommand.php
Created November 18, 2016 02:23 — forked from lukaswhite/ClearBeanstalkdQueueCommand.php
Clear a Beanstalkd Queue in Laravel
<?php
use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
class ClearBeanstalkdQueueCommand extends Command {
/**
@Braunson
Braunson / routing_patterns.php
Created November 21, 2016 20:20 — forked from lucasdavies/routing_patterns.php
Routing patterns from laravel-tricks.com
<?php
// This is what you might have right now
Route::get('users/{id}', 'UserController@getProfile')->where('id', '[\d+]+');
Route::get('products/{id}', 'ProductController@getProfile')->where('id', '[\d+]+');
Route::get('articles/{slug}', 'ArticleController@getFull')->where('slug', '[a-z0-9-]+');
Route::get('faq/{slug}', 'FaqController@getQuestion')->where('slug', '[a-z0-9-]+');
// and many more, now imagine you'll have to change the rule
// Instead, you could have a handy list of patterns and reuse them everywhere:
@Braunson
Braunson / pwd-faas.md
Created January 11, 2017 02:55 — forked from alexellis/pwd-faas.md
pwd-faas-quickstart.md

This is a Quickstart guide for FaaS functions as a Service on Play-with-docker.com

Head over to http://play-with-docker.com/ and start a new session. Add one host to start with.

# docker swarm init # use --advertise-addr here and pick the 10.x IP address range

# git clone https://github.com/alexellis/faas
# cd faas
# ./deploy_stack.sh
layout title permalink
checklist_page
The Side Project Marketing Checklist
/marketing-checklist/

Pre-Launch

Market Research

@Braunson
Braunson / searchreplacedb2.php
Created October 23, 2017 02:05
interconnectit/Search-Replace-DB 2.0.1 - Migrated from the MySQL Extension to PDO
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
/**
*
* Safe Search and Replace on Database with Serialized Data v2.0.1
*
* This script is to solve the problem of doing database search and replace when
* developers have only gone and used the non-relational concept of serializing
* PHP arrays into single database columns. It will search for all matching
@Braunson
Braunson / migration_example.php
Created December 21, 2017 18:21
Need to loop through multiple Laravel models to do the same update on all of their results? In this example it's updating the address country id
<?php
// Models to run through
$models = collect([
'contact',
'business',
]);
// Loop through the models
$models->each(function ($value, $key) use ($keys) {
@Braunson
Braunson / jquery.google-autocomplete.js
Created February 4, 2018 19:46
jQuery Wrapper for @dericcain's google-address-autocomplete
/*!
* jQuery Google autocomplete plugin
* Description: THis is just a jQuery wrapper for @dericcain's method helper linked below
* Author: @braunson
* Requirements: https://github.com/dericcain/google-address-autocomplete
* Licensed under the MIT license
*/;
(function($) {
// Usage $('[data-google-autocomplete]').googleAutocomplete();
@Braunson
Braunson / gist.md
Created March 2, 2018 22:24
Laravel Mix - Making functions and variables accessible in the global scope/object

To explain why to use the window. notation a little more (because I was confused at some point with it too) Webpack wraps your code in functions to create scope, so that each file can act as an independent module. This keeps your various modules from polluting the global scope or each other and also means test is not available to the browser console. If you just want to call your test function from the browser console try assigning test to the window object.

There's a great answer at SO on options with several approaches for globals here https://stackoverflow.com/a/40416826/610880

@Braunson
Braunson / CollectCodeCoverage.php
Created August 15, 2019 13:52
app/Http/Middleware/CollectCodeCoverage.php + tests/Feature/xCoverage.php Test code coverage middleware for Laravel 5.8+
<?php
namespace App\Http\Middleware;
use Closure;
class CollectCodeCoverage {
/**
* Used for code coverage when running unit tests
@Braunson
Braunson / snippet.php
Last active October 24, 2019 20:40
Laravel Collection Macro trimEndWhile
Collection::macro('trimEndWhile', function ($callback) {
$collection = new static($this->items);
while ($collection->count() && $callback($collection->last()) {
$collection->pop();
}
return $collection;
});