Skip to content

Instantly share code, notes, and snippets.

View coreymcmahon's full-sized avatar

Corey McMahon coreymcmahon

View GitHub Profile
@coreymcmahon
coreymcmahon / random.sh
Created November 26, 2021 03:17
1-liner cryptographically secure random string (Node)
# Using node
node -e 'require("crypto").randomBytes(48, (e, b) => console.log(b.toString("hex")))'
@coreymcmahon
coreymcmahon / gatsby-typescript-tailwind.sh
Created November 20, 2021 07:45
Set up Gatsby + TypeScript + Tailwind CSS
# Install Gatsby starter w/ TypeScript support
gatsby new project-name https://github.com/jpedroschmitz/gatsby-starter-ts
# Install Tailwind
npm install -D gatsby-plugin-postcss tailwindcss@latest postcss@latest autoprefixer@latest && npx tailwindcss init -p
# Update gatsby-config.js to include:
# plugins: ['gatsby-plugin-postcss'],
# Create global.css:
@coreymcmahon
coreymcmahon / 0000_00_00_000000_alter_failed_jobs_add_uuid.php
Created November 8, 2021 14:06
Migration to add missing `uuid` column to `failed_jobs` table when upgrading Laravel.
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Ramsey\Uuid\Uuid;
class AlterFailedJobsAddUuid extends Migration
{
public function up()
@coreymcmahon
coreymcmahon / FilesController.php
Created October 26, 2021 12:47
Stream a handle (Laravel + Flysystem)
<?php
namespace Controllers;
class FilesController
{
/**
* Add a route definition:
* $router->get("assets/{any}", "FilesController@index")->where('any', '.*');
*/
@coreymcmahon
coreymcmahon / orders.completed.json
Created August 13, 2021 03:34
Payload structure for "orders.completed" webhook
{
"data": {
"id": 546395,
"completed_at": "2021-08-13 03:30:38"
},
"timestamp": 1628825438,
"environment": "develop",
"type": "orders.completed",
"webhook_version": "1"
}
@coreymcmahon
coreymcmahon / customers.registered.json
Created August 13, 2021 03:33
Payload structure for "customers.registered" webhook
{
"data": {
"id": 461606,
"email": "james_smith@fakedomain.org",
"phone_number": "+1122334455",
"creation_channel": "customer_service"
},
"timestamp": 1628825494,
"environment": "develop",
"type": "customers.registered",
@coreymcmahon
coreymcmahon / HmacVerifier.php
Created June 18, 2021 08:55
Hmac webhook verification
<?php
namespace App;
use Illuminate\Http\Request;
class HmacVerifier
{
public function isValid(Request $request, string $secret): bool
{
<?php
/**
* In routes/api.php
*/
$router->get('api/v2/users', 'UsersController@index');
/**
@coreymcmahon
coreymcmahon / helpers.php
Last active April 4, 2021 07:42
Generate a "version number" for a PHP/Laravel application
<?php
use Carbon\Carbon;
use Illuminate\Support\Arr;
if (!function_exists('version')) {
/**
* Attempts to determine the current version of the application, based on `version` set in config/app.php and either
* the file public/version.html (which should be created during the build process) or by exec'ing Git commands directly
* at runtime. This results in a string of the format `<app-version>-<hash> (<last-modified>)`
@coreymcmahon
coreymcmahon / SignInWithApple.php
Created March 17, 2021 04:28
Generate a client_secret for "Sign in with Apple"
<?php
declare(strict_types=1);
use Lcobucci\JWT\Signer\Ecdsa\Sha256;
use Lcobucci\JWT\Signer\Key\InMemory;
use Lcobucci\JWT\Encoding\UnixTimestampDates;
use Lcobucci\JWT\Decoder;
use Lcobucci\JWT\Encoder;
use Lcobucci\JWT\Encoding\CannotDecodeContent;