Skip to content

Instantly share code, notes, and snippets.

Up to my elbows, as usual

Mark Croxton croxton

Up to my elbows, as usual
View GitHub Profile
croxton / base.twig
Last active Jul 30, 2021
Sprig / htmx full page transitions
View base.twig
{# _layouts/base.twig #}
<!DOCTYPE html>
<meta charset="utf-8">
<title>{{ entry.title }}</title>
<link href="^2/dist/tailwind.min.css" rel="stylesheet">
croxton /
Last active May 26, 2020
How to get the contents of a file attached to an Account with SOQL (Salesforce).

Files attached to Accounts in Salesforce are not publicly addressable. This gist explains how to use them in another context, so that they can be accessed by non-authenticated users. It assumes you are able to query Salesforce with the REST API connected via OAuth 2.0.

  1. Get an account record identified by {id} and return any attached files:
SELECT Id, Name, (ContentDocumentid FROM AttachedContentDocuments) FROM Account WHERE Id = {id}
  1. Use (one of) the returned ContentDocumentids to retrieve the a link to latest version of the file you're interested in. This will return an API URL that can be used to retrieve the file contents:
SELECT VersionData FROM ContentVersion WHERE ContentDocumentId = 'XXXXXXXXX' AND IsLatest = true
croxton /
Last active Sep 1, 2021
How to provision Google Cloud Storage buckets for Craft CMS 3.x

Create the bucket

  1. Open the console
  2. If you haven't already, setup your Cloud billing account
  3. From the drop down at the top of the screen, create new project for your client, e.g. my-client
  4. Make a note of the Project number on the project Home screen (Craft refers to this as the Project ID)
  5. In the sidebar go to APIs & Services > Credentials, click the + Create credentials button and choose the Service Account type
  • Set account name to craft-cms or similar
  • Set role to Owner
  • Save
  1. Click on the newly created service account email to edit it, then click the Keys tab and click Add key > Create new key and select the JSON format
View stopwords.txt
croxton /
Last active Oct 1, 2020
Laravel Mix 4.x standalone installation instructions

First make sure you are using the latest stable version of Node.js. These intructions were tested with 11.9.0.

Setup a new project with Laravel Mix:

mkdir my-app && cd my-app
npm init -y
npm install laravel-mix --save-dev
cp node_modules/laravel-mix/setup/webpack.mix.js ./

Take a look at webpack.mix.js and see if you want to change any of the paths to your src and dist. Then create some initial source files:


Keybase proof

I hereby claim:

  • I am croxton on github.
  • I am croxton ( on keybase.
  • I have a public key ASDjR9AACOZeg9yOAcHVkU1DFp5dn_jbnl_0QCGwezco9go

To claim this, I am signing this object:

croxton / pipeline.yml
Last active Jul 19, 2019 Craft 3 Atomic deployments
View pipeline.yml
- pipeline: "Build and deploy to [environment]"
trigger_mode: "MANUAL"
ref_name: "master"
- action: "Execute: gulp build"
type: "BUILD"
docker_image_name: "library/node"
docker_image_tag: "6"
- "npm install"
croxton /
Last active Jun 6, 2019
Buddy Works Craft 3 post-deployment atomic deployment action


if [ -d "releases/${execution.to_revision.revision}" ] && [ "${execution.refresh}" = "true" ]; then echo "Removing: releases/${execution.to_revision.revision}" && rm -rf releases/${execution.to_revision.revision}; fi
if [ ! -d "releases/${execution.to_revision.revision}" ]; then echo "Creating: releases/${execution.to_revision.revision}" && cp -dR deploy-cache releases/${execution.to_revision.revision}; fi
echo "Creating: persistence directories"
mkdir -p storage/craft
mkdir -p storage/cpresources
mkdir -p storage/uploads
croxton / .env.php
Last active Mar 20, 2019
Craft 3 live previews across different root (or sub) domains
View .env.php
// In general.php define an alias:
'aliases' => [
'@baseUrl' => getenv('CRAFTENV_BASE_URL')
// In the CP, set the Base URL for each site to @baseUrl/
// When previewing, the CP will therefore always use the hostname the editor logged into as the base url for the preview
// (that happens with 'new' entries anyway regardless of base url, but existing entries use base url).
croxton / critical-css-with-js.twig
Last active Nov 3, 2020
Inline critical CSS with JS (Craft CMS)
View critical-css-with-js.twig
{% set _inline_css_block = block('_inline_css') %}
{% if _inline_css_block is not empty %}
(function() {
/*! loadCSS. [c]2017 Filament Group, Inc. MIT License */
!function(e){"use strict";var n=function(n,t,o){function i(e){return a.body?e():void setTimeout(function(){i(e)})}function r(){l.addEventListener&&l.removeEventListener("load",r),||"all"}var d,a=e.document,l=a.createElement("link");if(t)d=t;else{var s=(a.body||a.getElementsByTagName("head")[0]).childNodes;d=s[s.length-1]}var f=a.styleSheets;l.rel="stylesheet",l.href=n,"only x",i(function(){d.parentNode.insertBefore(l,t?d:d.nextSibling)});var u=function(e){for(var n=l.href,t=f.length;t--;)if(f[t].href===n)return e();setTimeout(function(){u(e)})};return l.addEventListener&&l.addEventListener("load",r),l.onloadcssdefined=u,u(r),l};"undefined"!=typeof exports?exports.loadCSS=n:e.loadCSS=n}("undefined"!=typeof global?global:this);
!function(t){"use strict";t.loadCSS||(t.loadCSS=function(){});var e=loadCSS.relpreload={