Skip to content

Instantly share code, notes, and snippets.

View jeffochoa's full-sized avatar

Jeff Ochoa jeffochoa

View GitHub Profile
@jeffochoa
jeffochoa / ProgressBarCallback.php
Last active May 28, 2019 16:10
ProgressBar callback trait for Laravel commands
<?php
namespace App\commands;
trait ProgressionBarOutput
{
public function runProcess(\Countable $countable, callable $callback)
{
$bar = $this->output->createProgressBar(count($countable));
$bar->start();
@jeffochoa
jeffochoa / .php_cs
Last active March 11, 2024 20:21 — forked from jannejava/.php_cs
PHPCS Fixer for VSCode and Laravel
<?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 February 9, 2022 09:52
Vue Form and Error validator (Laracasts)
class Errors {
/**
* Create a new Errors instance.
*/
constructor() {
this.errors = {};
}
/**
@jeffochoa
jeffochoa / event.js
Created March 4, 2018 22:53
Vue event dispatcher
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 April 13, 2023 19:55
VueJs global event dispatcher
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 December 21, 2017 20:07 — 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)
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 November 13, 2024 14:18
Laravel HTTP status code
<?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 October 13, 2017 22:10
Chrome image async API
<!-- 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 October 1, 2024 02:07
Understanding Laravel pipelines
<?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 July 31, 2017 12:51 — forked from calebporzio/timer_helpers.php
A simple helper function and macro for timing php scripts and eloquent queries
<?php
// Helper function.
if (! function_exists('timer')) {
function timer($expression)
{
$start = microtime(true);
if ($expression instanceof Closure) {
$expression();