Skip to content

Instantly share code, notes, and snippets.

Jeff Ochoa jeffochoa

View GitHub Profile
@jeffochoa
jeffochoa / .php_cs
Created Feb 20, 2019 — forked from jannejava/.php_cs
PHPCS Fixer for VSCode and Laravel
View .php_cs
<?php
return PhpCsFixer\Config::create()
->setRules(array(
'@PSR2' => true,
'binary_operator_spaces' => true,
'blank_line_after_namespace' => true,
'blank_line_after_opening_tag' => true,
'blank_line_before_return' => true,
'braces' => true,
@jeffochoa
jeffochoa / Errors.js
Last active Nov 6, 2018
Vue Form and Error validator (Laracasts)
View Errors.js
class Errors {
/**
* Create a new Errors instance.
*/
constructor() {
this.errors = {};
}
/**
@jeffochoa
jeffochoa / event.js
Created Mar 4, 2018
Vue event dispatcher
View event.js
class Event {
constructor() {
this.vue = new Vue();
}
fire(event, data = null) {
this.vue.$emit(event, data);
}
listen(event, callback) {
@jeffochoa
jeffochoa / event.js
Last active Nov 19, 2018
VueJs global event dispatcher
View event.js
class Event {
constructor() {
this.vue = new Vue();
}
fire(event, data = null) {
this.vue.$emit(event, data);
}
listen(event, callback) {
@jeffochoa
jeffochoa / vcl-regex-cheat-sheet
Created Dec 21, 2017 — forked from dimsemenov/vcl-regex-cheat-sheet
Regular expression cheat sheet for Varnish (.vcl). Examples of vcl regexp. Found here http://kly.no/varnish/regex.txt (by Kristian Lyngstøl)
View vcl-regex-cheat-sheet
Regular expression cheat sheet for Varnish
Varnish regular expressions are NOT case sensitive. Varnish uses POSIX
regular expressions, for a complete guide, see: "man 7 regex"
Basic matching:
req.url ~ "searchterm"
True if req.url contains "searchterm" anywhere.
req.url == "searchterm"
@jeffochoa
jeffochoa / Response.php
Last active Apr 23, 2019
Laravel HTTP status code
View Response.php
<?php
// This can be found in the Symfony\Component\HttpFoundation\Response class
const HTTP_CONTINUE = 100;
const HTTP_SWITCHING_PROTOCOLS = 101;
const HTTP_PROCESSING = 102; // RFC2518
const HTTP_OK = 200;
const HTTP_CREATED = 201;
const HTTP_ACCEPTED = 202;
@jeffochoa
jeffochoa / img-async.html
Created Oct 13, 2017
Chrome image async API
View img-async.html
<!-- if possible: -->
<!-- the decode for this image may be deferred -->
<img async=on src="space-cats.jpg">
<!-- the decode for this image should not be deferred -->
<img async=off src="space-dogs.jpg">
<!-- the browser is free to do what it feels is best for the user -->
<img src="space-pizza.jpg">
@jeffochoa
jeffochoa / 1.ProcessClass.php
Last active Apr 4, 2019
Understanding Laravel pipelines
View 1.ProcessClass.php
<?php
namespace App\Features;
use App\Features\FirstTask;
use App\Features\SecondTask;
use Illuminate\Pipeline\Pipeline;
// *Naming things is hard* ... So, this is a class called `ProcessClass` that `run()` some text ¯\_(ツ)_/¯
class ProcessClass
@jeffochoa
jeffochoa / timer_helpers.php
Created Jul 31, 2017 — forked from calebporzio/timer_helpers.php
A simple helper function and macro for timing php scripts and eloquent queries
View timer_helpers.php
<?php
// Helper function.
if (! function_exists('timer')) {
function timer($expression)
{
$start = microtime(true);
if ($expression instanceof Closure) {
$expression();
@jeffochoa
jeffochoa / RouterServiceProvider.php
Created Jul 30, 2017
Get collection of available routes in Laravel
View RouterServiceProvider.php
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Route;
use Illuminate\Routing\Route as Router;
class RouterServiceProvider extends ServiceProvider
{
You can’t perform that action at this time.