Skip to content

Instantly share code, notes, and snippets.

View croxton's full-sized avatar
💭
Up to my elbows, as usual

Mark Croxton croxton

💭
Up to my elbows, as usual
View GitHub Profile
@croxton
croxton / using-salesforce-files-externally.md
Last active May 26, 2020 13:02
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
croxton / google_cloud_storage_craft_3.md
Last active September 24, 2022 07:31
How to provision Google Cloud Storage buckets for Craft CMS 3.x

Create the bucket

  1. Open the console https://console.cloud.google.com
  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
a
about
an
are
as
at
be
by
com
de
@croxton
croxton / laravel_mix_setup.md
Last active October 1, 2020 19:00
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:

@croxton
croxton / keybase.md
Created January 23, 2019 15:42
Keybase proof

Keybase proof

I hereby claim:

  • I am croxton on github.
  • I am croxton (https://keybase.io/croxton) on keybase.
  • I have a public key ASDjR9AACOZeg9yOAcHVkU1DFp5dn_jbnl_0QCGwezco9go

To claim this, I am signing this object:

@croxton
croxton / pipeline.yml
Last active July 13, 2023 01:00
Buddy.works Craft 3 Atomic deployments
- pipeline: "Build and deploy to [environment]"
trigger_mode: "MANUAL"
ref_name: "master"
actions:
- action: "Execute: gulp build"
type: "BUILD"
docker_image_name: "library/node"
docker_image_tag: "6"
execute_commands:
- "npm install"
@croxton
croxton / post-deploy.md
Last active June 6, 2019 17:44
Buddy Works Craft 3 post-deployment atomic deployment action

atomic-deploy-pipeline

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
croxton / .env.php
Last active March 20, 2019 19:23
Craft 3 live previews across different root (or sub) domains
<?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
croxton / critical-css-with-js.twig
Last active November 3, 2020 08:30
Inline critical CSS with JS (Craft CMS)
{% set _inline_css_block = block('_inline_css') %}
{% if _inline_css_block is not empty %}
<script>
(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),l.media=o||"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,l.media="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={
@croxton
croxton / expresso_store_uk_postcodes.txt
Created November 27, 2017 10:30
Expresso Store match specific UK postcodes
Allow shipping rules to accept regex
***************************************************************
First, change the `postcode` column in `exp_store_shipping_rules` to type varchar(255).
./Store/src/Service/ShippingService.php
Change this:
/**