Skip to content

Instantly share code, notes, and snippets.

View paulund's full-sized avatar

Paulund paulund

View GitHub Profile
@paulund
paulund / UtcDateTime.php
Last active June 30, 2020 15:04
Laravel UTC DateTime custom cast see tutorials on custom casts https://paulund.co.uk/laravel-custom-casts
<?php
namespace CustomCast;
use Carbon\Carbon;
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
class UtcDateTime implements CastsAttributes
{
/**
@paulund
paulund / composer
Last active November 17, 2019 11:01
Composer Version Cheatsheet
"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 October 20, 2019 07:25
WordPress Docker Compose
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 07:01
JavaScript GroupBy function
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 March 16, 2019 16:09
Command to delete all node modules on your computer
find . -name "node_modules" -exec rm -rf '{}' +
<?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 November 2, 2020 22:14
Run phpunit tests before push and error if the tests fail
#!/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 August 26, 2018 12:54
Copy variable contents to the user clipboard
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 August 25, 2018 12:08
Details of how to send a slack message when a job fails
public function boot()
{
Queue::failing(function (JobFailed $event) use ($slackUrl) {
Notification::route('slack', $slackUrl)->notify(new SlackFailedJob($event));
});
}
@paulund
paulund / .bash_profile
Created July 21, 2018 15:41
Alias to enable/disable xdebug
alias exd="sh enabled-xdebug.sh"
alias dxd="sh disable-xdebug.sh"