Skip to content

Instantly share code, notes, and snippets.

@lucas-pelton
lucas-pelton / main.js
Created October 20, 2019 14:10
CloudFlare worker promise race boilerplate
response = await Promise.race([
fetch('https://possibly.slow.io/' + options.token + '/get', {
method: 'POST',
body: JSON.stringify(data),
}),
new Promise((_, reject) =>
setTimeout(() => reject(new Error('Timeout')), options.timeout)
),
])
@lucas-pelton
lucas-pelton / get_original_images.php
Created March 19, 2020 19:23
Create array of uploaded images in WP Media Library
// https://wordpress.stackexchange.com/questions/243697/zip-all-original-images-from-media-gallery
$query_images_args = array(
'post_type' => 'attachment',
'post_mime_type' => 'image',
'post_status' => 'inherit',
'posts_per_page' => - 1,
);
$query_images = new WP_Query( $query_images_args );
@lucas-pelton
lucas-pelton / resize-images.js
Created November 20, 2021 15:12
Size all selected images to similar visual gravity
/*********
*
* resize logos in custom galleries.
*
*/
window.addEventListener("load", function() {
var images = document.querySelectorAll(".custom-gallery img");
var adjustImageWidth = function (image) {
var widthBase = 250;
@lucas-pelton
lucas-pelton / arrive.js
Created November 30, 2022 16:43
Wait for an element in the DOM
/*
* arrive.js
* v2.4.1
* https://github.com/uzairfarooq/arrive
* MIT licensed
*
* Copyright (c) 2014-2017 Uzair Farooq
*/
var Arrive = function (e, t, n) { "use strict"; function r(e, t, n) { l.addMethod(t, n, e.unbindEvent), l.addMethod(t, n, e.unbindEventWithSelectorOrCallback), l.addMethod(t, n, e.unbindEventWithSelectorAndCallback); } function i(e) { e.arrive = f.bindEvent, r(f, e, "unbindArrive"), e.leave = d.bindEvent, r(d, e, "unbindLeave"); } if (e.MutationObserver && "undefined" != typeof HTMLElement) { var o = 0, l = function () { var t = HTMLElement.prototype.matches || HTMLElement.prototype.webkitMatchesSelector || HTMLElement.prototype.mozMatchesSelector || HTMLElement.prototype.msMatchesSelector; return { matchesSelector: function (e, n) { return e instanceof HTMLElement && t.call(e, n); }, addMethod: function (e, t, r) { var i = e[t]; e[t] = function () { return r.length == arguments.length ? r.apply(this, arguments) : "function" == typeof i ? i.appl
@lucas-pelton
lucas-pelton / waitForObject.js
Created November 30, 2022 16:46
Wait for an object to be available in the DOM
var waitForJQuery = setInterval(function () {
if (typeof jQuery != 'undefined') {
//your code here
clearInterval(waitForJQuery);
}
}, 10);