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 / RegExp-Groups.js
Created Oct 7, 2019
Creates RegExp groups and keeps them in the `charGroups` object to be used in regular expressions.
View RegExp-Groups.js
var charGroups = {};
westc / YourJS.term.js
Last active Oct 10, 2019
YourJS Candidate Function: Creates a search term checking function. Allows for quotes, a regexp, musts (+), must not [AKA negation] (-) and normal terms.
View YourJS.term.js
* Creates a function that when called will try to match the given string
* against `strTerm`.
* @param strTerm {string}
* The string that will be parsed and used to test one or more strings.
* @param opt_options {?Object}
* Optional. An object containing all of the options to be used. The
* `ignoreCase` property (defaults to true) can be added specified to
* allow/disallow non-RegExp terms to match strings regardless of casing.
* The `matchWordStart` (defaults to false) can be added to allow plain words
westc / fuzzPath.js
Created Oct 4, 2019
Allow for fuzzy path matching.
View fuzzPath.js
// people[*]["firstName" | "lastName" | "fullName"]
// people[*][firstName | lastName | fullName]
// people[*][/^(first|last|full)Name$/]
// people.*[/^(first|last|full)Name$/]
// people.*./^(first|last|full)Name$/
// people[#0..9..2#]
// var RGX_REGEXES = /\/((?:[^\\\/]+|\\.)+)\/(i?)/; // match regexes (rgxBody, rgxFlags)
// var RGX_STRINGS = /("(?:[^\\"]+|\\.)*")/; // match strings (strRaw)
// var RGX_ASTERISKS = /(\*)/; // match * (isAsterisk)
westc / bgColorOf.js
Created Sep 28, 2019
Gets the background color of an element, making sure to get it from ancestors if not available (transparent or rgba(0,0,0,0)).
View bgColorOf.js
function bgColorOf(el) {
while (el) {
var bgColor = window.getComputedStyle(el).getPropertyValue('background-color').replace(/\s/g, '').toLowerCase();
if (!/^(transparent|rgba\(0,0,0,0\))$/.test(bgColor)) {
return bgColor;
el = el.parentNode;
return 'rgb(255,255,255)';
View step-example.js
// Allows for an array or an array like structure to be stepped through in the order specified
// after each iteration.
function step(array, callback, opt_stepValue, opt_startIndex) {
opt_stepValue = ~~opt_stepValue || 1;
var count = array.length;
var i = (opt_startIndex == undefined || isNaN(~~opt_startIndex))
? opt_stepValue < 0
? count - 1
: 0
: opt_startIndex;
westc / await-for-each.js
Last active Aug 29, 2019
Seeing the difference between using await with Array.prototype.forEach and using await with for...of.
View await-for-each.js
function testForEachReplies(maxSecs = 4) {
async function replyIn(secs) {
return await {
then(res, rej) {
_ => res(`I replied after ${secs} second${secs - 1 ? 's' : ''}`),
secs * 1e3
westc / wrapText.js
Last active Aug 28, 2019
Wrap text by splitting the lines based on whitespace and a maximum number of characters.
View wrapText.js
function wrapText(str, opt_max) {
opt_max = Math.min(Math.max(1, ~~opt_max || 80), 200);
let rgx = new RegExp(`\\S{1,${opt_max}}|\\s{1,${opt_max}}`, 'g');
let lastPart, wasNotWS;
return (str.match(rgx) || []).reduce(function (lines, part, partIndex, parts) {
let isNotWS = /\S/.test(part);
if (isNotWS) {
let lineCount = lines.length;
let lastLine = lines[lineCount - 1];
let newLastLine;
westc / getGitContents.js
Last active Aug 23, 2019
Get the contents of a file or directory in Git using this function on any web page.
View getGitContents.js
* Gets the GitHub contents of a file or directory.
* @param {string} user
* The GitHub user name.
* @param {string} repo
* The name of the repo. If you want to also specify the branch then you can
* append a colon to the repo name and then specify the branch name in this
* same field.
* @param {string} path
* The path to the file or directory whose contents should be retrieved.
westc / fromExcelDate.js
Created Aug 12, 2019
Function used to convert a numeric value (from Excel or Google Sheets) into a JavaScript Date object.
View fromExcelDate.js
* Converts a numeric value (from Excel or Google Sheets) into a JavaScript Date object.
* @param {number} numDate - The numeric value that will be converted into a date.
* @param {?number=} opt_tzMinOffset - Optional. Defaults to the minute offset of the
* local timezone. If given this should indicate how many minutes to offset the date
* by to correctly represent the desired timezone.
* @returns {Date} - The date representation of the numeric value passed in.
function fromExcelDate(num, opt_tzMinOffset) {
return new Date(
westc / GoogleSheetReader.js
Last active Aug 9, 2019
Provides an easy way to get Google Sheets data.
View GoogleSheetReader.js
var GoogleSheetReader = (function (document) {
var global = this;
function loadJSONP(url, paramName, callback) {
var fnName = ('_' + Math.random() + Math.random()).replace(/\./g, '');
var body = document.body;
var script = document.createElement('script');
global[fnName] = function (data) {
delete global[fnName];
You can’t perform that action at this time.