Skip to content

Instantly share code, notes, and snippets.

<?php
namespace App\Notifications\Channels;
use Illuminate\Notifications\Notification;
class Broadcast extends \Illuminate\Notifications\Channels\BroadcastChannel
{
/**
* Send the given notification.
@jaggy
jaggy / tap.js
Created August 28, 2017 14:07
Higher order tap for javascript
function tap (object) {
return new Proxy(object, {
get: function (target, attribute) {
return function (...args) {
target[attribute].apply(target, args);
return target;
};
},
});
@jaggy
jaggy / phpv
Last active December 19, 2017 23:27
*sh snippet for switching PHP versions.
function phpv() {
brew unlink php$(php -v | head -n1 | grep -o -E '\d\.\d' | tr -d '.')
brew link php$1
valet restart
}
FROM elixir:latest
RUN mix local.hex --force
RUN mix local.rebar --force
RUN mix archive.install https://github.com/phoenixframework/archives/raw/master/phoenix_new.ez --force
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash -
RUN apt-get update && apt-get install -y postgresql-client inotify-tools nodejs
RUN mkdir /app
<?php
namespace App;
trait HasPersonName
{
public function getNameAttribute($name)
{
return new PersonName($name);
<?php
namespace App;
trait Tappable
{
public function tap($callback)
{
return tap($this, $callback);
}
<?php
use Illuminate\Database\Eloquent\Builder;
protected function registerWhereLikeMacro()
{
Builder::macro('whereLike', function ($attributes, $searchTerm = null) {
$this->where(function (Builder $query) use ($attributes, $searchTerm) {
foreach (array_wrap($attributes) as $attribute) {
$query->when(
@jaggy
jaggy / HigherOrderIfProxy.php
Last active January 14, 2020 19:57
An exercise of implementing a higher order if.
<?php
namespace App;
use Illuminate\Support\Traits\ForwardsCalls;
class HigherOrderIfProxy
{
use ForwardsCalls;
<?php
protected function invalidJson($request, ValidationException $exception)
{
return response()->json([
'message' => $exception->getMessage(),
'errors' => Collection::make($exception->errors())->mapWithKeys(function ($value, $key) {
return [Str::camel($key) => $value];
}),
], $exception->status);
<?php
namespace Tests\SetupTraits;
trait SetupTraits
{
protected function setUpTraits()
{
$this->setupAdditionalTraits(
parent::setUpTraits()