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 / 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 = {};
"Common:0,1s,2j,2o,3f,4p,4r,55,57,5b,5z!6v!jd,kf,kl,kp,ks,lb,ok!oo,op,ou!ow,oz,p1!p3!p7!p9!pu!10w!11z,120,13d!13f,13g,13k!154,15b,163,166,16d,16n,16t!170!17f!17h!17j!18g!1ct!1e6!1fv,1fw,1iq,1j3,1kr,1ks,1m6,1m7,1mn!1ng,1nh,1nj!1nv,1pb,1px!1q6,1qq,1r6!1us,1ut,1vo!1vx,1vy,1w1,1w2,1wp!1wx!1wz,1x1,1x6,1x7,1xh,1xi,1xl,1xm,1xr,1xy,1y0,1y3,1y6!1yc,1yd,1z3,1z4,1z8!1zf,1zi,1zl,1zm,209!20h!20k!20n!20q,20r,20t!20z,212,215,216,21a,21c,21e,21k,21p!21r,21x,22f,22o,22s!232!236!23t!241!244!24a,24b,24m!24q!24u,24v,24x,25b,25g,25h,25u,260,268!26c!26l,26m,26p,26q,27d!27l!27o!27u,27v,285,286,289,28a,28e,28l,28o,28r,28u!290,291,29k,29t,29w!2a3,2a5,2a9!2ae,2ag,2aj!2al!2ao,2aq,2at,2av,2az,2b1,2be,2bh,2bn,2bp,2bt!2by,2bz,2c1,2c6,2c8,2cl,2d7,2db,2dp!2dt!2eh!2ey,2f0,2f9!2fd!2fi,2fo,2fr!2fv,2fz,2g4,2g5,2gg,2gn,2h9!2hd!2i1!2ic!2ii,2ij,2it!2ix!2j2,2j8,2jb,2jh,2jj!2jo,2jp,2k0!2k3,2kf,2kk!2kt!2kx!2md!2mh!2mo,2mr,2n8,2n9,2o0,2o1,2o4!2on,2op,2pe!2po!2pq,2pr,2pz,2q1,2q3,2q6,2qd!2qf!2qo,2qt,2r4,2r5,2r9,2rk,2t7,2tb,2u4,2v4,2
@westc
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
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
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
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) {
setTimeout(
_ => res(`I replied after ${secs} second${secs - 1 ? 's' : ''}`),
secs * 1e3
);
}
};
@westc
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
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
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
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.