Skip to content

Instantly share code, notes, and snippets.

View paulund's full-sized avatar

Paulund paulund

View GitHub Profile
@paulund
paulund / Results--html.vue
Created December 26, 2017 14:53
Creating a Laravel, VueJS, Algolia real time search results box.
<template>
<section class="search-results" v-show="results.length > 0">
<div v-for="result in results" class="search-result">
<a :href="'/' + result.slug">{{ result.title }}</a>
</div>
</section>
</template>
@paulund
paulund / resize-image-keep-aspect-ratio.php
Last active November 5, 2021 10:33
Resize a image to a max width and height and keep aspect ratio.
<?php
public function getImageSizeKeepAspectRatio( $imageUrl, $maxWidth, $maxHeight)
{
$imageDimensions = getimagesize($imageUrl);
$imageWidth = $imageDimensions[0];
$imageHeight = $imageDimensions[1];
$imageSize['width'] = $imageWidth;
@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 / 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 / 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 / example-curl-request.php
Created June 25, 2013 18:39
Here is an example of a CURL request using PHP.
<?php
$request = "request=string of request";
// Send using curl
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $url); // URL to post
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 ); // return into a variable
curl_setopt( $ch, CURLOPT_HTTPHEADER, $header ); // headers from above
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_PORT, 8080);
/**
* Continents and Countries MySQL Tables compiled from Wikipedia, Braintree Payments documentation
* and a couple other places I don't recall at the moment. This data is compatible with the Braintree
* Payment API as of Dec 2011
*
* Compiled by Steve Kamerman, 2011
*/
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
@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 '{}' +
@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 / 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