Skip to content

Instantly share code, notes, and snippets.

View hailwood's full-sized avatar

Matthew Hailwood hailwood

View GitHub Profile
@hailwood
hailwood / EditableTablePage.php
Last active November 6, 2015 00:47
I needed a way to share one DataObject type between multiple has_many relations on the same page without the DataObject knowing how many links it had, this solution works using `AddNewInlineButton` and `GridFieldEditableColumns`. To add an additional table the only change required is another entry in the foreach on line 13.
<?php
class EditableTablePage extends Page {
private static $has_many = [
'TableRows' => 'TableRow'
];
public function getCMSFields(){
$fields = parent::getCMSFields();
@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 () {
@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()
{
/* This is the main layout component */
class Full extends Component {
static propTypes = {
viewer: React.PropTypes.object.isRequired
};
render() {
return (
null
java.lang.StackOverflowError
at com.intellij.openapi.util.Pair.hashCode(Pair.java:88)
at gnu.trove.TObjectCanonicalHashingStrategy.computeHashCode(TObjectCanonicalHashingStrategy.java:8)
at com.intellij.util.containers.RefHashMap$HardKey.set(RefHashMap.java:147)
at com.intellij.util.containers.RefHashMap$HardKey.access$500(RefHashMap.java:136)
at com.intellij.util.containers.RefHashMap.containsKey(RefHashMap.java:212)
at com.intellij.util.containers.WeakHashMap.containsKey(WeakHashMap.java:36)
at mobi.hsz.idea.gitignore.lang.IgnoreLanguage.getOuterFiles(IgnoreLanguage.java:223)
at mobi.hsz.idea.gitignore.indexing.ExternalIndexableSetContributor.getAdditionalFiles(ExternalIndexableSetContributor.java:90)
@hailwood
hailwood / example.php
Last active September 14, 2017 02:32
class Creature extends Model {
protected $with = [
'entity'
];
public function entity(){
return $this->morphTo();
}
<?php
namespace App\Http\Resources;
use App\Models\CropType;
use Illuminate\Http\Resources\Json\ResourceCollection;
class CropTypeCollectionResponse extends ResourceCollection
{
/**
@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;
}
version: '3'
services:
web:
image: brettt89/silverstripe-web
working_dir: /var/www
ports:
- 8080:80
volumes:
- .:/var/www/html
<?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
{
/**