Skip to content

Instantly share code, notes, and snippets.

Chris West westc

Block or report user

Report or block westc

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
@westc
westc / pardot.visitor_activity_types.sql
Created May 28, 2019
Create a simple table that indicates the different visitor activity types in Pardot.
View pardot.visitor_activity_types.sql
CREATE TABLE visitor_activity_type AS
SELECT id::INT, name::VARCHAR(100)
FROM (
SELECT 1 AS id, 'Click' AS name
UNION
SELECT 2 AS id, 'View' AS name
UNION
SELECT 3 AS id, 'Error' AS name
UNION
SELECT 4 AS id, 'Success' AS name
@westc
westc / get_url_params.sql
Last active May 21, 2019
Decodes simple URL parameters, getting all of the parameters or just the ones that you want.
View get_url_params.sql
CREATE OR REPLACE FUNCTION get_url_params (
in_url VARCHAR
)
RETURNS TABLE(
param_number INT,
raw_key VARCHAR,
raw_value VARCHAR,
"key" VARCHAR,
"value" VARCHAR
)
@westc
westc / getColNum.gs
Last active May 5, 2019
Gets the number of the column from the letter reference.
View getColNum.gs
/**
* Gets the number of the column from the letter reference
* (eg. A -> 1, B -> 2, G -> 7, AC -> 29, etc.).
* @param {string} letters
* The letters referring to column which will be converted to a number.
* @return {number}
* The column number represented by the given letters.
*/
function getColNum(letters) {
var num = 0;
@westc
westc / formatDate.gs
Last active May 5, 2019
Formats a JSON date string or a date object using the Google sheet's timezone or the timezone you specify.
View formatDate.gs
/**
* Formats a JSON date string or a date object using the spreadsheet's timezone
* or the timezone you specify.
* @param {Date|string} date
* The date object or the string that should be formatted as a date string.
* @param {string=} opt_format
* Optional. The format of the date as it should be returned. If not
* specified the format will be "yyyy-MM-dd'T'HH:mm:ss'Z'".
* @param {string=} opt_timeZone
* Optional. Timezone to use to format the date. Defaults to the
@westc
westc / Documentation - vueToHTML.md
Last active Apr 25, 2019
Takes an HTML string with Vue.js syntax and converts it to a normal HTML string.
View Documentation - vueToHTML.md

vueToHTML(…)

This function can be used to take an HTML string containing Vue Syntax and convert it to a regular HTML string.

Parameters

  1. vueHTML string

    The HTML string containing Vue Syntax that is to be converted to a regular HTML string.

  2. data Object|null

    The data object that can be referenced in order to render vueHTML with the specified data. If null is given a blank object will be used as the data source.

@westc
westc / getPathEntries.js
Created Apr 14, 2019
Get path-value pairs for an object. Doesn't support recursive objects.
View getPathEntries.js
function getPathEntries(obj) {
let result = [];
let arr = Object.keys(obj).map(key => ({ parent: obj, path: key, key }));
for (let i = 0; i < arr.length; i++) {
let { parent, path, key } = arr[i];
let value = parent[key];
result.push([path, value]);
if (!(value instanceof RegExp) && 'object' === typeof value) {
arr.push.apply(arr, Object.keys(value).map(key => ({ parent: value, path: path + `.${key}`, key })));
}
@westc
westc / toCSV.js
Last active Apr 8, 2019
Converts an array of arrays of values to a CSV string.
View toCSV.js
/**
* @preserve Copyright (c) 2019 Christopher West
* Licensed under the MIT license.
*/
/**
* Converts an array of arrays of values to a CSV string.
* @param rows {Array<Array>}
* An array of arrays of values that should be converted to a CSV string.
* @param opt_options {Object=}
* Optional. If this contains a `nullString` property the value will be used
@westc
westc / findPath.js
Last active Apr 4, 2019
Find the path to a specific value based on a callback function.
View findPath.js
/**
* Find the path to a specific value based on a callback function.
* @param {*} base
* The object in which you want to start looking to see if it a match
* according to `callback`.
* @param {function(*, Array<string>, *): boolean} callback
* The function that will be called for each value starting with `base` and
* traversing all of its descendants.
* @param {number=} opt_maxTimeMs
* Optional. Defaults to 3000ms. The maximum amount of time to check before
@westc
westc / getRandomTitleBlock.js
Last active Mar 7, 2019
Function to be used to generate random title blocks for the YourJS blog posts.
View getRandomTitleBlock.js
// Source: https://gist.github.com/westc/c4ea74893631e3733e264b230559139d
(function () {
function runner() {
getRandomTitleBlock = function (title, width, height, numberOfGradients, callback) {
var parent = document.createElement('div');
var targetHeight = Math.round(height / 2);
var fontSize = targetHeight;
var scale = roundRandom(75, 100) / 100;
@westc
westc / Sandbox.js
Last active Apr 16, 2019
A JavaScript sandbox which works by using a web worker.
View Sandbox.js
(function(undefined) {
var global = this;
var FUNC_PATHS = Object.keys(console).reduce(function (carry, name) {
if ('function' === typeof console[name]) {
carry.push(['console', name]);
}
return carry;
}, [['alert']]);
function WORKER_CODE() {
You can’t perform that action at this time.