Skip to content

Instantly share code, notes, and snippets.

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
How to get the contents of a file attached to an Account with SOQL (Salesforce).
View using-salesforce-files-externally.md

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 Nov 4, 2020
How to provision Google Cloud Storage buckets for Craft CMS 3.x
View google_cloud_storage_craft_3.md

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 > Create credentials and choose the Service Account Key type
    • Set role to Owner (Choose Project and then select Owner)
    • Set key type to JSON
    • Set account name to craft-cms or similar
  6. The key will automatically download to your computer as a text file. Save this and the service account email shown on screen (e.g. craft-cms@my-client.iam.gserviceaccount.com) in a safe place.
View stopwords.txt
a
about
an
are
as
at
be
by
com
de
@croxton
croxton / laravel_mix_setup.md
Last active Oct 1, 2020
Laravel Mix 4.x standalone installation instructions
View laravel_mix_setup.md

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:

View keybase.md

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 Jul 19, 2019
Buddy.works Craft 3 Atomic deployments
View pipeline.yml
- 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 Jun 6, 2019
Buddy Works Craft 3 post-deployment atomic deployment action
View post-deploy.md

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 Mar 20, 2019
Craft 3 live previews across different root (or sub) domains
View .env.php
<?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 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 %}
<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 Nov 27, 2017
Expresso Store match specific UK postcodes
View expresso_store_uk_postcodes.txt
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:
/**
You can’t perform that action at this time.