Skip to content

Instantly share code, notes, and snippets.

View jameswomack's full-sized avatar
📈

James J. Womack jameswomack

📈
View GitHub Profile
@jameswomack
jameswomack / _jewel.js
Last active July 15, 2021 00:30
Configurably generating a "jewel" board in which no 3 consecutive jewels are allowed in a given column or row
/* eslint-disable no-console, no-param-reassign */
/**
* Returns a filled in board such that there are no 3 consecutive
* jewels (vertically/horizontally) of the same type.
*
* @param widthOfBoard int which provides width of board
* @param heightOfBoard int which provides height of board
* @param jewels array providing valid jewels for board
*/
@jameswomack
jameswomack / scope.js
Created July 14, 2021 16:34
Looking at the difference between function & block scope in JavaScript
const console = require("console");
(function () {
console.log(foo); // undefined
{
var foo = 'foo';
}
})();
(function () {
@jameswomack
jameswomack / palindromes.js
Last active December 14, 2021 21:43
Determining if a string is a palindrome—or becomes a palindrome by dropping one of its characters
function isArrayPalindrome (array) {
const forward = [...array].join();
const reversed = [...array].reverse().join();
if (reversed == forward) {
return true;
}
return false;
}
const getArraySansIndex = (a, _index) => a.filter((item, index) => index !== _index);
@jameswomack
jameswomack / scopev.js
Last active July 7, 2021 23:28
A CLI script for syncing versions of all a scope's dependencies within a monorepo. Supports CLI args & environment variables
#!/usr/bin/env node
const argv = require('yargs-parser')(process.argv.slice(2));
function getEnvVarForScopeVConfigKey(keyName) {
const {env} = require('process');
return env[`MONOREPO_${keyName.toUpperCase()}`];
}
const ScopeVConfiguration = Object.create({
@jameswomack
jameswomack / index.js
Last active July 6, 2021 19:38
Does an array contain a particular sum? Performant edition.
/* Begin cache-related code */
const sumCache = new Map();
function getCachedSumResult (array, sum) {
return sumCache.get(`${array}{${sum}`);
}
function cacheSumResult (array, sum, result) {
sumCache.set(`${array}{${sum}`, result);
return result;
@jameswomack
jameswomack / managebac-class-students-api-usage.js
Created March 1, 2021 03:32
Using the ManageBac API to retrieve a set of students across multiple classes
const fetch = require('node-fetch');
function classFetch (classId) {
return fetch(`https://api.managebac.com/v2/classes/${classId}/students`, {
headers: {
'auth-token': '{{}}'
}
})
.then(response =>
response.json()
@jameswomack
jameswomack / knutshell.sh
Created February 26, 2021 00:58
Function composition in a Knut shell
> foo = (...s) => `foo${s.join()}`
[Function: foo]
> bar = (...s) => `${s.join()}bar`
[Function: bar]
> qux = s => Math.ceil(Number(s))
[Function: qux]
> compose(foo, bar, qux)(1.27890)
'foo2bar'
> fooBarQux = compose(foo, bar, qux)
undefined
@jameswomack
jameswomack / diff.diff
Created January 14, 2020 18:25
Looked into unused dependencies & wanted to see if this looks right
diff --git a/package.json b/package.json
index 40439456..96cd7f13 100644
--- a/package.json
+++ b/package.json
@@ -18,7 +18,6 @@
]
},
"resolutions": {
- "mux.js": "^5.5.1",
"@material-ui/icons": "^4.5.1",
@jameswomack
jameswomack / application_ld-json.html
Created December 15, 2017 13:23
Example implementation of the Schema.org spec for Google/Bing to display a search bar to users to search our site from within Google
<!-- Schema.org spec for Google/Bing to display a search bar to users to search our site from within Google -->
<!-- See: https://developers.google.com/webmasters/structured-data/slsb-overview -->
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "WebSite",
"url": "http://www.showtimeanytime.com",
"potentialAction": {
"@type": "SearchAction",
"target": "http://www.showtimeanytime.com/#search/{search_term_string}",