Skip to content

Instantly share code, notes, and snippets.

View hailwood's full-sized avatar

Matthew Hailwood hailwood

View GitHub Profile
@hailwood
hailwood / helpers.php
Last active December 4, 2022 23:30
HMR sass support for laravel mix
<?php
if (!function_exists('isHMR')) {
/**
* Get whether HMR is active.
*
* @return bool
*/
function isHMR()
{
@hailwood
hailwood / example.js
Created February 17, 2020 21:21
Promised Interval
const interval = new PromisedInterval(async () => {
//Do something here
}, 5000);
// Start the loop running
interval.start(); // you can await this if you'd like to pause until something stops the interval
// Pause the execution after the current loop finishes
@hailwood
hailwood / AlternateMailerServiceProvider.php
Created September 25, 2019 01:56
Laravel Alternative Mailer
<?php
namespace App\Services\AlternateMailer;
use Illuminate\Mail\Mailer;
use Swift_Mailer;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Swift_DependencyContainer;
use Illuminate\Support\ServiceProvider;
<?php
namespace App\Eloquent\Concerns;
use Illuminate\Support\Str;
use App\Eloquent\Relationships\LeaveableMorphToMany;
/**
* Trait HasCustomRelationships
*
<?php
/**
* Improved GridFieldExportButton that streams CSV data to the client instead of building
* the entire CSV in memory and sending that (which doesn't work for large data sets).
*/
class GridFieldStreamExportButton extends GridFieldExportButton
{
/**
version: '3'
services:
web:
image: brettt89/silverstripe-web
working_dir: /var/www
ports:
- 8080:80
volumes:
- .:/var/www/html
@hailwood
hailwood / example.ts
Created June 13, 2018 03:42
Typescript: Exclusive Or properties
type ExcludeXORIncludeXORNeither<T extends Serializer<T>> =
| { exclude: object; include?: never; }
| { exclude?: never; include: object; }
| { exclude?: never; include?: never; };
abstract class Serializer<T extends Serializer<T> & ExcludeXORIncludeXORNeither<T>> {
exclude?: object;
include?: object;
}
@hailwood
hailwood / .zshrc
Last active January 2, 2018 07:37
docker-connect/docker-ip function and autocomplete
#Setup the autocomplete
fpath=(~/.zsh/completion $fpath) #assuming the _docker-connect file is stored at ~/.zsh/completion/_docker-connect
autoload -Uz compinit && compinit -i
#The actual functions
docker-connect () {
docker exec -i -t $1 /bin/bash
}
docker-ip () {
<?php
namespace App\Http\Resources;
use App\Models\CropType;
use Illuminate\Http\Resources\Json\ResourceCollection;
class CropTypeCollectionResponse extends ResourceCollection
{
/**
@hailwood
hailwood / example.php
Last active September 14, 2017 02:32
class Creature extends Model {
protected $with = [
'entity'
];
public function entity(){
return $this->morphTo();
}