Skip to content

Instantly share code, notes, and snippets.

@andyj
andyj / calculateColorFromRange.js
Last active September 9, 2024 09:33
Colour (Color) Gradient Hues on table row to mimic Excel Heatmap style
/**
* Calculates a colour based on the current value, relative to a given range (minValue to maxValue).
* The hue is calculated in HSL format, transitioning from Green (at high values) to Red (at low values).
*
* @param {number} currentValue - The current value for which the colour is calculated.
* @param {number} minValue - The minimum value of the range.
* @param {number} maxValue - The maximum value of the range.
* @returns {string} - The calculated HSL colour as a string (e.g., "hsl(120, 100%, 80%)").
*/
function calculateColor(currentValue, minValue, maxValue) {
@andyj
andyj / exploring-jS-array-methods.js
Last active July 17, 2024 10:09
Exploring JS array methods
// This is the code that prompted / created the blog post
// https://www.andyjarrett.com/posts/2024/exploring-array-methods-including-push-pop-shift-unshift-map-filter-reduce-and-others/
// push()
["🥶","🥶","🥶","🥶"].push('🥵') // = ["🥶","🥶","🥶","🥶","🥵"]
// pop()
["😎","🥵","🥶","🤢"].pop() // = ["😎","🥵","🥶"]
// shift()
["😎","🥵","🥶","🤢"].shift() // = ["🥵","🥶","🤢"]
@andyj
andyj / shortcut-differences-when-moving-between-macos-sublime-text-and-vscode.md
Last active June 18, 2024 08:31
Shortcut differences when moving between MacOS Sublime Text and VSCode

Sublime Text to VSCode Shortcuts on MacOS

General

Action Sublime Text Shortcut VSCode Shortcut
Open Recent Cmd+E Cmd+R
Toggle Sidebar Cmd+K, Cmd+B Cmd+B

Editing

| Action | Sublime Text Shortcut | VSCode Shortcut |

@andyj
andyj / graphically-represent-a-directory-structure-using-find-and-sed.sh
Created August 15, 2023 11:31
Graphically represent a directory structure using Find and Sed
#!/bin/bash
# Use FIND over TREE when you want to exclude folders like node_modules
find /path/to/folder -type d -name "node_modules" -prune -o -print | sed -e 's;[^/]*/;|____;g;s;____|; |;g'
@andyj
andyj / graphically-represent-a-directory-structure-using-tree.sh
Created August 15, 2023 11:29
Method 1: Graphically represent a directory structure from the CLI
#!/bin/bash
tree /path/to/folder -L 2
@andyj
andyj / generateMarkdown.js
Created July 21, 2023 11:35
Turn a GHOST.db posts in to mark down
// Import required modules
const sqlite3 = require('sqlite3').verbose(); // SQLite3 module for database operations
const fs = require('fs').promises; // File System module for file operations
const { promisify } = require('util'); // Util module to convert callback-based functions to promises
/**
* Generates Markdown files from data in the SQLite database and sets their metadata.
* The Markdown files are organized in folders based on the "posted" date from the database.
*/
(async () => {
#!/bin/bash
# This script is provided "as is" and without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the author be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the script or the use or other dealings in the script. Use at your own risk.
# This is a bash script that checks the HTTP response of a list of top-level domain names
# every 1 minute. If a domain returns an HTTP status code other than 200 OK, the script
# sends a callback to a specified URL with the name of the domain that failed.
#
# The list of domains and callback URL can be edited
#
# You could also use CRON to ensure this file is alway running e.g.
@andyj
andyj / docker_commands.sh
Last active July 22, 2019 14:15
Essential Docker commands for .bash_profiles wrapped up as terminal functions
MY_IP=127.0.0.1
#Ubuntu
#MY_IP=$(wget -qO- icanhazip.com)
#MAC
#MY_IP=$(ifconfig en0 | grep "inet 1" | awk '/inet/ { print $2 } ')
echo Current IP: $MY_IP
@andyj
andyj / Sv4Util.cfc
Created March 6, 2017 12:04 — forked from Leigh-/Sv4Util.cfc
Amazon Web Services Signature 4 Utility for ColdFusion (Alpha)
/**
* Amazon Web Services Signature 4 Utility for ColdFusion
* Version Date: 2016-04-12 (Alpha)
*
* Copyright 2016 Leigh (cfsearching)
*
* Requirements: Adobe ColdFusion 10+
* AWS Signature 4 specifications: http://docs.aws.amazon.com/general/latest/gr/signature-version-4.html
*
* Licensed under the Apache License, Version 2.0 (the "License");
@andyj
andyj / bash_script_to_back_up_mysql_to_s3.sh
Last active April 2, 2019 08:54
Bash script to backup a MySQL RDS dump to S3
# From Andy Jarretts post:
# http://www.andyjarrett.co.uk/2016/08/02/secured-bash-script-to-backup-a-mysql-rds-dump-to-s3/
#!/bin/bash
SQLDUMP="$(date +'%Y%m%d%H%M').sql.gz"
echo "Creating backup of database to $SQLDUMP"
mysqldump --login-path=local --databases YourDatabaseName | gzip -9 > $SQLDUMP
echo "Dump Zipped up"