Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View chrisjhoughton's full-sized avatar

Chris Houghton chrisjhoughton

  • Beacon
  • London, UK
View GitHub Profile
@chrisjhoughton
chrisjhoughton / README.md
Last active May 19, 2023 04:36
Notify tray workflows "webhook style" from Salesforce using Apex triggers.

Salesforce Apex trigger notifications for tray.io

Salesforce's Apex triggers allow you to trigger tray workflows in real-time, based on events that occur in Salesforce. Events include things like:

  • New lead creations
  • Opportunity updates, such as the status moving from "open" to "closed"

Salesforce doesn't support webhooks out of the box, so we'll need to add some Apex code to your Salesforce account to notify tray at the right time.

@chrisjhoughton
chrisjhoughton / sauce-identify.html
Last active August 29, 2015 14:26
Pass a user's email address to Sauce, after an email subscribe form has been submitted. Requires jQuery.
<script>
/*
* Key things to change:
* 1. The class `form.my-subscribe-form` to match your own
* 2. The input `input[name='email']` to match the real `name` of the input
*/
$(function () {
$('form.my-subscribe-form').on('submit', function () {
var email = $(this).find("input[name='email']").val();
@chrisjhoughton
chrisjhoughton / fb-conversion.liquid
Last active February 19, 2022 04:57
Facebook's conversion pixel code, ready to go for Shopify with liquid variables. Change the `youraccountid` and add this to the "additional content and scripts" section of your checkout settings.
<!-- Facebook Conversion code -->
{% assign fb_pixel_id = 'yourpixelid' %}
<script>(function() {
var _fbq = window._fbq || (window._fbq = []);
if (!_fbq.loaded) {
var fbds = document.createElement('script');
fbds.async = true;
fbds.src = '//connect.facebook.net/en_US/fbds.js';
var s = document.getElementsByTagName('script')[0];
@chrisjhoughton
chrisjhoughton / remove.liquid
Last active September 9, 2023 07:56
Remove a Shopify cart attribute
{% if cart.attributes.yourCartAttribute %}
<script>
$.ajax({
type: 'POST',
url: '/cart/update.js',
data: 'attributes[yourCartAttribute]=',
dataType: 'json'
});
</script>
{% endif %}
@chrisjhoughton
chrisjhoughton / twitter-cards.liquid
Last active March 2, 2023 07:39
Twitter Card meta tags for Shopify. Add this as a snippet called "twitter-cards.liquid" in your theme, and then add {% include 'twitter-cards' %} to your theme.liquid file.
{% comment %}
This snippet renders meta data needed to create a Twitter card
for products and articles.
IMPORTANT: change @your_twitter_username with your actual twitter username!
Your cards must be approved by Twitter to be activated
- https://dev.twitter.com/docs/cards/validation/validator
@chrisjhoughton
chrisjhoughton / enforce-http.liquid.js
Last active February 14, 2024 07:49
How to build an ajax form on Shopify. See http://inside.sauce.ly/how-to-build-an-ajax-login-form-on-shopify/ for the full blog post.
/*
* Ensure the http protocol is always used on the myshopify.com domains.
* Uses liquid to input the correct URL.
*/
if (window.location.href.match(/https:\/\/.*.myshopify.com/) && top === self) {
window.location.href = window.location.href.replace(/https:\/\/.*.myshopify.com/, 'http://{{ shop.domain }}');
}
@chrisjhoughton
chrisjhoughton / video_embed_code.js
Created September 22, 2014 13:45
Get the video embed code from either a Vimeo or Youtube URL. Depends on Mout (moutjs.com)
var getParam = require("mout/queryString/getParam");
module.exports = function (url) {
if (!url) {
return "";
}
// Youtube
if (url.indexOf("youtube.com") !== -1) {
@chrisjhoughton
chrisjhoughton / crop-resize.js
Last active January 9, 2021 05:19
Given an image URL or path, crop and resize it to be exactly a specific size. Crops centrally to force enforce the correct aspect ratio, and then resizes as per normal. Depends on the `when` and `gm` NPM modules. Returns a promise that resolves with an image buffer in a .PNG format.
/*
* Given an image URL or path, crop and resize it to be exactly a specific size.
* Crops centrally to force enforce the correct aspect ratio, and then resizes as per normal.
* Depends on the `when` and `gm` NPM modules.
* Returns a promise that resolves with an image buffer in a .PNG format.
*/
var when = require('when');
var gm = require('gm');
var im = gm.subClass({ imageMagick: true }); // use `im` in place of `gm` for heroku compatibility
@chrisjhoughton
chrisjhoughton / bootstrap.js
Created August 14, 2014 10:56
SailsJS Geo-encoding and lookup
module.exports.bootstrap = function (cb) {
// Ensure we have 2dsphere index on Property so GeoSpatial queries can work!
sails.models.YOURMODEL.native(function (err, collection) {
collection.ensureIndex({ coordinates: '2dsphere' }, function () {
// It's very important to trigger this callack method when you are finished
// with the bootstrap! (otherwise your server will never lift, since it's waiting on the bootstrap)
cb();
@chrisjhoughton
chrisjhoughton / getAvatar.js
Created August 7, 2014 16:58
Get an avatar by a user's email address. Relies on Mout and MD5
var md5 = require("MD5");
var trim = require("mout/string/trim");
module.exports = function (email) {
var hash = md5(trim(email).toLowerCase());
return "http://www.gravatar.com/avatar/" + hash;
};