Skip to content

Instantly share code, notes, and snippets.

Chris Houghton chrisjhoughton

  • Sauce
  • London, UK
Block or report user

Report or block chrisjhoughton

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@chrisjhoughton
chrisjhoughton / README.md
Last active Apr 16, 2019
Notify tray workflows "webhook style" from Salesforce using Apex triggers.
View README.md

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 Aug 29, 2015
Pass a user's email address to Sauce, after an email subscribe form has been submitted. Requires jQuery.
View sauce-identify.html
<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 Aug 9, 2017
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.
View fb-conversion.liquid
<!-- 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 Sep 10, 2019
Remove a Shopify cart attribute
View remove.liquid
{% 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 Sep 29, 2017
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.
View twitter-cards.liquid
{% 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
View enforce-http.liquid.js
/*
* 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 Sep 22, 2014
Get the video embed code from either a Vimeo or Youtube URL. Depends on Mout (moutjs.com)
View video_embed_code.js
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 Jan 3, 2016
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.
View crop-resize.js
/*
* 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 Aug 14, 2014
SailsJS Geo-encoding and lookup
View bootstrap.js
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 Aug 7, 2014
Get an avatar by a user's email address. Relies on Mout and MD5
View getAvatar.js
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;
};
You can’t perform that action at this time.