Skip to content

Instantly share code, notes, and snippets.

@paulund
paulund / UtcDateTime.php
Last active Jun 30, 2020
Laravel UTC DateTime custom cast see tutorials on custom casts https://paulund.co.uk/laravel-custom-casts
View UtcDateTime.php
<?php
namespace CustomCast;
use Carbon\Carbon;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
class UtcDateTime implements CastsAttributes
{
/**
@paulund
paulund / composer
Last active Nov 17, 2019
Composer Version Cheatsheet
View composer
"require": {
// Exact version to 1.5.4
"vendor/package": "1.5.4",
// Greater or lower bounds
"vendor/package": ">=1.5.0", // Anything above 1.5.0
"vendor/package": "<1.5.0", // Anything below 1.5.0
// Wildcard
"vendor/package": "1.5.*", // >=1.5 <1.6
@paulund
paulund / docker-compose.yml
Created Oct 20, 2019
WordPress Docker Compose
View docker-compose.yml
version: '3.3'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
@paulund
paulund / groupby.js
Created May 27, 2019
JavaScript GroupBy function
View groupby.js
const groupBy = function (data, key) {
return data.reduce(function (carry, el) {
var group = el[key];
if (group === null) {
group = 'General'
}
if (carry[group] === undefined) {
carry[group] = []
}
@paulund
paulund / delete-all-node-modules.sh
Created Mar 16, 2019
Command to delete all node modules on your computer
View delete-all-node-modules.sh
find . -name "node_modules" -exec rm -rf '{}' +
View AppServiceProvider.php
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Translation\Translator;
use App\Translator\JsonTranslator;
class AppServiceProvider extends ServiceProvider
{
@paulund
paulund / pre-push
Last active Nov 2, 2020
Run phpunit tests before push and error if the tests fail
View pre-push
#!/bin/bash
git diff --cached --name-only | while read FILE; do
if [[ "$FILE" =~ ^.+(php|inc|module|install|test)$ ]]; then
echo "Running tests..."
cd "${0%/*}/.."
phpunit 1> /dev/null
if [ $? -ne 0 ]; then
echo -e "\e[1;31m\tUnit tests failed ! Aborting commit.\e[0m" >&2
exit 1;
@paulund
paulund / javascript-copy-paste.js
Created Aug 26, 2018
Copy variable contents to the user clipboard
View javascript-copy-paste.js
copyText (textToCopy) {
this.copied = false
// Create textarea element
const textarea = document.createElement('textarea')
// Set the value of the text
textarea.value = textToCopy
// Make sure we cant change the text of the textarea
@paulund
paulund / AppServiceProvider.php
Created Aug 25, 2018
Details of how to send a slack message when a job fails
View AppServiceProvider.php
public function boot()
{
Queue::failing(function (JobFailed $event) use ($slackUrl) {
Notification::route('slack', $slackUrl)->notify(new SlackFailedJob($event));
});
}
@paulund
paulund / .bash_profile
Created Jul 21, 2018
Alias to enable/disable xdebug
View .bash_profile
alias exd="sh enabled-xdebug.sh"
alias dxd="sh disable-xdebug.sh"