Skip to content

Instantly share code, notes, and snippets.

View kirkbushell's full-sized avatar

Kirk Bushell kirkbushell

  • Tectonic Digital
  • Sydney
View GitHub Profile
@kirkbushell
kirkbushell / Post.php
Created August 27, 2023 12:31
Updated syntax for supporting caches in Eloquence
<?php
use Eloquence\Behaviours\CountCache\CountedBy;
use Eloquence\Behaviours\CountCache\HasCounts;
use Illuminate\Database\Eloquent\Model;
class Post extends Model {
use HasCounts;
#[CountedBy]
@kirkbushell
kirkbushell / XSSProtection.php
Last active November 5, 2021 06:08
Laravel 5 XSS protection middleware
class XSSProtection
{
/**
* The following method loops through all request input and strips out all tags from
* the request. This to ensure that users are unable to set ANY HTML within the form
* submissions, but also cleans up input.
*
* @param Request $request
* @param callable $next
* @return mixed
@kirkbushell
kirkbushell / Interceptor.js
Created January 7, 2016 22:41
Handling JWT, Vue JS and token refreshes
import Unauthorised from './Unauthorised'
export default function() {
return {
response: function(response) {
switch (response.status) {
case 401: return Unauthorised.handle();
}
return response;
<?php
'cloud' => env('FILESYSTEM_CLOUD', 'do'),
..
'do' => [
'driver' => 's3',
'key' => env('DO_ACCESS_KEY_ID'),
'secret' => env('DO_SECRET_ACCESS_KEY'),
@kirkbushell
kirkbushell / File1.php
Created March 11, 2016 14:43
The question is - does Player upgrade buildings, or does a service do this, or does the building upgrade itself and deduct costs from Player?
<?php
class Player
{
public function upgrade(Building $building)
{
if (!$this->canAfford($building)) {
throw new DamnImBroke;
}
$this->deduct($building->upgradeCosts());
@kirkbushell
kirkbushell / gist:aa60d05a39dba9288e25
Last active May 30, 2017 10:06
Value object usage within Laravel Eloquent example
<?php
// In model: Ensures values are consistent
class User extends Eloquent {
public function setEmailAttribute(Email $email) {
$this->attributes['email'] = $email;
}
}
// Value object
class Email {
@kirkbushell
kirkbushell / BuildingId.php
Last active March 9, 2016 23:53
Weirdness in PHPSpec?
<?php
namespace IronSteel\Construction;
use IronSteel\Library\Uuid;
class BuildingId extends Uuid
{
}
@kirkbushell
kirkbushell / paginator.js
Created March 28, 2013 04:07
Paginator module for AngularJS, in combination with Laravel's paginator class
/**
* Paginator
*
* The paginator can be used within any controller to easily set up
* some pagination options, including number of pages, page navigation
* and more. It is built to work with Laravel's own pagination library,
* which returns data in a particular format.
*
* Usage:
* Before you can use paginator, make sure you specify the URLs to your pagination
// parent
<template>
<header class="content-header">
<h1 class="h2 first">Track workout</h1>
</header>
<div>
<ul class="exercises">
<li class="exercise" v-for="exercise in exercises" track-by="$index" transition="item">
<div class="col-sm-6 col-xs-12 selector">
<button class="btn btn-default" v-on:click="selectExercise()">Select exercise</button>
@kirkbushell
kirkbushell / typeahead.js
Last active December 19, 2015 10:39
Typeahead (https://github.com/twitter/typeahead.js) in combination with angular + utilizing models
/**
* Typeahead directive for fields. Expects both a typeahead and location attribute.
*
* @param string typeahead - If a value is provided, this should be a two-way data binding to the model that you would like to utilize in partnership with this plugin.
* @param string location - Where the data can be found for remote queries.
*/
module.directive( 'typeahead', [ '$window', '$timeout', function( $window, $timeout ) {
return {
restrict: 'A',
scope: { model: '=typeahead', value: '@' },