Skip to content

Instantly share code, notes, and snippets.

View Accudio's full-sized avatar

Alistair Shepherd Accudio

View GitHub Profile
@Accudio
Accudio / main.js
Created September 25, 2024 14:02
Shopify + Laravel Mix + Async Alpine for dynamic imports
/**
* This is added to your `main.js` file, the one that imports and runs Async Alpine. Make sure that
* it runs before any `import()` functions by putting as high as possible. That may mean adding it to
* a static import if your other static imports dynamically import immediately.
*/
__webpack_public_path__ = window.assetsPath;
/**
* If you want to automatically register all components within a certain directory as async, you can do
* that with `require.context()` and the fourth param as 'weak'. Add this to your main.js file and
@Accudio
Accudio / userscript.js
Created August 23, 2024 08:59
Cheating at mojiparty.io
// ==UserScript==
// @name New Userscript
// @namespace http://tampermonkey.net/
// @version 2024-08-22
// @description try to take over the world!
// @author You
// @match https://www.mojiparty.io/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=mojiparty.io
// @grant none
// ==/UserScript==
@Accudio
Accudio / api-auth.js
Created December 29, 2023 12:18
Basic authentication using Vercel edge functions
import bcrypt from 'bcrypt';
import { SignJWT } from 'jose';
import { serialize } from 'cookie';
export default async function (request, response) {
if (request.method !== "POST") {
return response.status(405).send('does not respond to GET requests');
}
// get all configured passwords
@Accudio
Accudio / middleware.js
Created April 10, 2023 09:07
Multiple currencies within cookies using Vercel Middleware
import { rewrite } from '@vercel/edge';
import { RequestCookies } from '@edge-runtime/cookies'
// only run middleware on home page
export const config = {
matcher: '/',
}
export default function middleware(req) {
const cookies = new RequestCookies(req.headers)
@Accudio
Accudio / add-to-diary.php
Created November 25, 2022 14:47
Class to generate Calendar URLs and files
<?php
/**
* Utility for adding an event to various calendars
*
* @package SMRC
*/
if (isset($_POST['smrc_add_to_diary'])) {
$event = new SMRC_Diary_Event($_POST);
@Accudio
Accudio / alpine-window-sync.html
Created June 10, 2022 11:55
Synchronising a property on `window` and an Alpine.js property
<div x-data="{
count: 4,
init() {
const self = this
Object.defineProperty(window, 'count', {
enumerable: true,
configurable: true,
get: function() {
return self.count
},
@Accudio
Accudio / colour-contrast.js
Created June 9, 2022 08:54
Basic JavaScript implementation of a WCAG 2.1 colour contrast algorithm that chooses between black or white depending on the colour provided
console.log(contrastingColour('#eee'))
function contrastingColour(colour) {
const rgb = hexToRGB(colour)
// luminance of inputted colour
const L = 0.2126 * colourMod(rgb.r) + 0.7152 * colourMod(rgb.g) + 0.0722 * colourMod(rgb.b)
// white has a luminance of 1
const whiteL = 1
@Accudio
Accudio / 1-usage.php
Last active January 26, 2022 15:25
Example PHP abstraction of an Image CDN. Built with CloudImage and an alias in mind, customise as your setup and provider.
<?php
echo image([
'image' => 'otter.jpg',
'alt' => 'an otter standing on a log looking majestic',
'srcset' => [300, 450, 600, 800, 1000, 1200],
'sizes' => '100vw',
'width' => 1200,
'height' => 800,
'loading' => 'lazy',
@Accudio
Accudio / 1-usage.php
Last active January 26, 2022 15:27
Example Advanced Custom Fields abstraction of an Image CDN. Built with CloudImage and an alias in mind, customise as your setup and provider.
<?php
echo image( [
'image' => get_field('image'),
'srcset' => [300, 450, 600, 800, 1000, 1200],
'sizes' => '100vw',
'loading' => 'lazy'
'class' => 'image-class'
] );
@Accudio
Accudio / wordle.js
Created January 14, 2022 09:46
Modify Wordle statistics. Modify object in `JSON.stringify` call and save as a bookmark, run on Wordle page.
javascript:(function(){ localStorage.setItem('statistics', JSON.stringify({ "currentStreak": 100, "maxStreak": 100, "guesses":{ "1": 99, "2": 0, "3": 1, "4": 0, "5": 0, "6": 0, "fail" :0 }, "winPercentage": 100, "gamesPlayed": 100, "gamesWon": 100, "averageGuesses": 1 }))})()