Skip to content

Instantly share code, notes, and snippets.

View adamcrampton's full-sized avatar
💪
Crushing it

Adam Crampton adamcrampton

💪
Crushing it
  • Sydney, Australia
View GitHub Profile
@adamcrampton
adamcrampton / sendRawEmailWithAttachment.php
Last active November 12, 2024 01:02
AWS PHP SDK v3 sendRawEmail with attachment
<?php
use Aws\Ses\SesClient;
use Aws\Exception\AwsException;
/**
* Send an email using the 'raw' version of the API.
* Use this when needing to send an attachment.
*
* @param array $addresses
@adamcrampton
adamcrampton / laravelCsvParseAndUpsert.php
Last active January 18, 2024 03:17
Laravel - Parse a CSV file, map to database columns and upsert
<?php
use Exception;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
final class CsvService {
/**
* CSV data from file into an array using the provided mappings, then insert to database.
*
@adamcrampton
adamcrampton / bootstrap-confirm-modal.vue
Created April 23, 2021 00:24
Bootstrap 4 confirm modal for VueJs 2
<template>
<div class="modal" id="confirmModal" tabindex="-1" aria-labelledby="confirmModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialogue-centered">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="confirmModalLabel"><slot name="modal-header"></slot></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
@adamcrampton
adamcrampton / Handler.php
Last active November 4, 2023 07:55
Custom error handling redirects for Laravel (App\Exceptions\Handler)
<?php
namespace App\Exceptions;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Symfony\Component\ErrorHandler\Exception\FlattenException;
use Throwable;
class Handler extends ExceptionHandler
@adamcrampton
adamcrampton / loading.html
Created August 11, 2020 22:32
Loading overlay with spinner
<style>
#overlay {
background: #000;
color: #fff;
position: fixed;
height: 100%;
width: 100%;
z-index: 5000;
top: 0;
left: 0;
@adamcrampton
adamcrampton / youTubeDurationParser.php
Created June 22, 2020 23:01
Parse YouTube duration string to seconds integer
<?php
/**
* Match pattern PT#H#M#S (leading PT, hours, minutes, seconds) and return seconds value.
*
* @param string $string
* @return int
*/
private static function convertDuration($string)
{
// Comprehensive regex that should match any value.
@adamcrampton
adamcrampton / JsonCheck.php
Created May 26, 2020 06:50
Determine if PHP string is valid JSON
<?php
/**
* Checks if string is valid JSON.
*
* @param string $string
* @return bool
*/
public function jsonCheck($string)
{
@adamcrampton
adamcrampton / ajaxFullPageSpinner.html
Created May 7, 2020 23:59
Full page CSS spinner useful for pages with AJAX
<div class="loading hidden"><i class="fa fa-spin fa-circle-o-notch" style="font-size: 48px;"></i></div>
<script type="text/javascript">
const formData = new FormData();
formData.append('key', 'value');
$.ajax({
async: true,
contentType: false,
processData: false,
@adamcrampton
adamcrampton / jqueryAjaxPostBoilerplate.js
Last active March 13, 2020 05:10
Boilerplate for jQuery AJAX POST request
const endpoint = 'https://api.some.endpoint.test';
const formId = 'this-form-id-value';
const data = new FormData(document.getElementById('formId'));
$.ajax({
async: true,
contentType: false,
processData: false,
url: endpoint,
method: 'POST',
@adamcrampton
adamcrampton / ttlArray.php
Created September 30, 2019 02:28
Handy array useful for configuring cache TTLs etc
<?php
/*
|--------------------------------------------------------------------------
| Cache TTL
|--------------------------------------------------------------------------
|
| Set commonly used TTL values.
|
*/
return [