Skip to content

Instantly share code, notes, and snippets.

View mrandrewmills's full-sized avatar

Andrew Mills mrandrewmills

View GitHub Profile
@mrandrewmills
mrandrewmills / queryToArrStruct.cfm
Created April 28, 2024 12:52
queryToArrStruct
/**
* Converts a ColdFusion query into an array of structures.
*
* @param query The ColdFusion query to be converted.
* @return An array of structures representing the query data.
*/
function queryToArrStruct(query) {
// Serialize the query into JSON with "struct" as the second parameter
var serializedQuery = serializeJSON(query, "struct");
function bionicizeText(str) {
let phrase = str.split(" ");
let results = [];
results.push(phrase.map(word => bionicizeWord(word)));
return results.join(" ");
function bionicizeWord(w) {
let strong = document.createElement('strong');
@mrandrewmills
mrandrewmills / isPrime.js
Created December 16, 2023 22:15
isPrime - function to test whether given number is a prime
function isPrime(thisNum){
if ( thisNum <= 1 )
return false;
for ( x = 2; x <= Math.sqrt(thisNum); x++ ){
if ( thisNum % x == 0 )
return false;
}
return true;
@mrandrewmills
mrandrewmills / ChineseZodiac.js
Last active December 18, 2022 13:50
JS Object that finds Chinese Zodiac animal based on the birthyear provided.
/**
* ChineseZodiac.js - JavaScript object, find Chinese Zodiac animal based on birthyear provided
* @type {Object}
* @namespace
*/
var ChineseZodiac = {
/**
* animals, array of all 12 animals in the Chinese Zodiac
@mrandrewmills
mrandrewmills / multiSortArrayStruct.js
Last active July 4, 2022 02:22
JS to sort an array of structures by one or more properties
function propComparator(sortBy){
return function(a,b){
let fieldsToSortBy = sortBy.split(",");
for ( x = 0; x < fieldsToSortBy.length; x++ ) {
let results = 0;
@mrandrewmills
mrandrewmills / knapsackSolved.js
Last active August 9, 2021 00:40
Solving The Knapsack Problem
// inspired by Academind's "JavaScript Algorithms Crash Course"
// see https://www.youtube.com/watch?v=JgWm6sQwS_I for more like this
// Imagine you have a list of items, and each item has a value and a weight associated with it.
items = [
{ id: "b", val: 6, w: 8 },
{ id: "a", val: 10, w: 3 },
{ id: "c", val: 3, w: 3 },
];
@mrandrewmills
mrandrewmills / titleAnnoyance.js
Created July 5, 2021 15:51
JS object for toggling document.title text between current value and a temporary one at a specified interval. Also a method to stop/clear.
function titleToggle( currTitle, tmpTitle, msInterval){
var currTitle = currTitle;
var tmpTitle = tmpTitle;
var msInterval = msInterval;
var timerID = -1;
this.stop = function() {
if ( timerID != -1) {
clearInterval(timerID);
@mrandrewmills
mrandrewmills / LuckyNumberGameTrials.js
Created September 16, 2020 09:06
quick and dirty JS to see if low to high, high to low, or random approach is best for lucky number games
// gets a random number between min and max, inclusive. Source: Mozilla Developer Network
function getRandomIntInclusive(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1) + min);
}
// find lucky number, going from 1 to 100, in sequence
function runLowToHighTrial(){
@mrandrewmills
mrandrewmills / inspectAllTables.cfm
Created September 17, 2019 12:09
When you don't have DB access, but need to see the tables & field names with which you are working.
<!--- change datasource as needed --->
<cfset thisDatasource = "example">
<!--- retrieve and display all table names in order --->
<cfquery name="getAllTableNames" datasource="#thisDatasource#">
SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE'
ORDER BY Table_Name
</cfquery>
<cfdump var="#getAllTableNames#" label="getAllTableNames" expand="false">
@mrandrewmills
mrandrewmills / waybackThis.js
Created July 15, 2019 12:55
JS Bookmarklet which shows the current page in the Internet Archive's Wayback machine.
javascript: (function () { /* finds current URL in Wayback Machine */ document.location = "https://web.archive.org/web/*/" + document.location; }());