Skip to content

Instantly share code, notes, and snippets.

@pryley
pryley / LocalValetDriver.php
Created December 27, 2023 05:46
LocalValetDriver which supports WordPress Multisite
<?php
use Valet\Drivers\Specific\WordPressValetDriver;
class LocalValetDriver extends WordPressValetDriver
{
/**
* Get the fully resolved path to the application's front controller.
*/
public function frontControllerPath(string $sitePath, string $siteName, string $uri): ?string
@pryley
pryley / MultisiteValetDriver.php
Last active December 27, 2023 05:25
File goes here: ~/Library/Application Support/Herd/config/valet/Drivers/MultisiteValetDriver.php
<?php
namespace Valet\Drivers\Custom;
use Valet\Drivers\Specific\WordPressValetDriver;
class MultisiteValetDriver extends WordPressValetDriver
{
/**
* Get the fully resolved path to the application's front controller.
@pryley
pryley / debounce.ts
Created September 23, 2021 09:34
Debounce function
export function Debounce (fn: Function, wait = 200) {
let timerId: number
let lastArgs: Array<any> | undefined
let lastCallTime: DOMHighResTimeStamp
let lastThis
let result
const startTimer = (pendingFunc: FrameRequestCallback) => {
cancelAnimationFrame(timerId)
return requestAnimationFrame(pendingFunc)
}
@pryley
pryley / breakpoints.js
Last active September 12, 2021 17:51
tiny-swiper plugin for breakpoints
import { SwiperInstance, SwiperPlugin } from '../core/index'
import { Options } from '../core/options'
export default <SwiperPlugin>function SwiperPluginBreakpoints (
instance: SwiperInstance,
options: Options,
) {
const isEnabled = Boolean(options.breakpoints)
if (!isEnabled) return
@pryley
pryley / GenerateImageKitJob.php
Last active March 1, 2021 04:18
ImageKit job for the Responsive Images Statamic addon (https://statamic.com/addons/spatie/responsive-images)
<?php
namespace App\Jobs;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use Spatie\ResponsiveImages\Jobs\GenerateImageJob;
class GenerateImageKitJob extends GenerateImageJob
{
@pryley
pryley / close-popup.antlers.html
Created August 30, 2020 01:26
alpinejs close popup
<div x-data="{ show: !localStorage.getItem('hide-popup') }">
<div x-show="show">
<button @click="localStorage.setItem('hide-popup', true); show = false">
close
</button>
</div>
</div>
@pryley
pryley / IsLocalUrl.php
Last active August 14, 2020 06:10
Add additional attribute to non-local links
<?php
namespace App\Modifiers;
use Illuminate\Support\Str;
use Statamic\Modifiers\Modifier;
class IsLocalUrl extends Modifier
{
/**
@pryley
pryley / _figures.antler.html
Last active August 6, 2020 05:51
Statamic 3 field for displaying multiple images
<div class="size-{{ grid_size }} gap-4 grid | md:grid-cols-12 | xl:gap-6">
{{ assets:images }}
<figure class="| md:{{ grid_columns }}">
{{ responsive:url glide:width="1200" :ratio="image_ratio" }}
{{ if alt }}
<figcaption>{{ alt }}</figcaption>
{{ /if }}
</figure>
{{ /assets:images }}
</div>
@pryley
pryley / debug.css
Last active August 5, 2020 00:43
[tailwindcss] Display screen breakpoints on the local environment
body.debug::before {
@apply .bg-gray-900;
@apply .fixed;
@apply .font-mono;
@apply .leading-none;
@apply .left-0;
@apply .pointer-events-none;
@apply .px-2;
@apply .py-1;
@apply .text-white;
@pryley
pryley / embed-pdf.php
Created July 4, 2020 17:01
Embed a PDF as a webpage
<?php
$copyright = 'Copyright 2020, Acme Inc.'; // copyright info of PDF file
$pdfPath = '/document.pdf'; // path to PDF file
$pdfTitle = 'Embedded PDF'; // title of PDF document
?><!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">