Skip to content

Instantly share code, notes, and snippets.

View DeanHickerson's full-sized avatar

Dean Hickerson DeanHickerson

View GitHub Profile
@DeanHickerson
DeanHickerson / nodejs.code-snippets
Last active April 15, 2022 20:18
NodeJS Snippets for VSCode
"NodeJS base64 encode unction": {
"scope": "javascript",
"prefix": "base64 encode function",
"body": [
"function toBase(string) {",
"\treturn Buffer.from(string).toString('base64');",
"}"
],
"description": "Function to Base64 encode a string in NodeJS"
},
@DeanHickerson
DeanHickerson / encrypt.js
Created November 12, 2021 15:40
NodeJS Text Encryption Example
const crypto = require('crypto');
const algorithm = 'aes-256-ctr';
let key = 'asupersecretpassword';
key = crypto.createHash('sha256').update(key).digest();
const encrypt = (buffer) => {
// Create an initialization vector
const iv = crypto.randomBytes(16);
// Create a new cipher using the algorithm, key, and iv
const cipher = crypto.createCipheriv(algorithm, key, iv);

MongoDB Cheat Sheet

Show All Databases

show dbs

Show Current Database

@DeanHickerson
DeanHickerson / README.md
Last active August 22, 2023 11:35
Gmail Mail Manager MailMan v2.0

MailMan Gmail Mail Manager v2.0

This is an overhauled approach to an older script that I was running for a while to clean up my Gmail. This script can delete old emails automatically and sort old emails from the inbox to folders (labels).

Setup

  1. Create a new Google Apps Script at https://script.google.com and overwrite the placeholder content with the javascript below.
  2. Create a google spreadsheet which will be used to store and easily update your configurations.
  3. In the Spreadsheet create a table with the same headers from the following example.
@DeanHickerson
DeanHickerson / BigDater.js
Last active December 20, 2021 03:35
A date class module with a few more props that I use frequently.
class BigDater {
constructor() {
this.date = new Date();
this.weekStart = this.dateGetter(this.date,-(this.date.getDay()));
this.nextWeek = this.dateGetter(this.weekStart,7);
this.nextWeekEnd = this.dateGetter(this.nextWeek,7);
this.lastWeek = this.dateGetter(this.weekStart,-7);
this.weekBeforeLast = this.dateGetter(this.lastWeek,-7);
}
dateGetter(dateObj,adjust) {
@DeanHickerson
DeanHickerson / code.js
Created August 20, 2020 01:29
Google sheet get distance function
const START_ADDRESS = '1600 Pennsylvania Avenue NW, Washington, DC 20500' // replace with the starting address you want
/**
* Return the driving distance from a specified start location.
* The argument passed to the function can be an address or a place or array of those things.
*
* @param {string|array} location - Address or name of place. This can also be an array.
* @returns {string|array} distance - The travel distance by car in one direction.
* @customfunction
*/
@DeanHickerson
DeanHickerson / README.md
Last active August 16, 2023 22:28 — forked from jamesramsay/README.md
Gmail: delete old emails automatically

Gmail: delete old emails automatically

Automatically deletes old emails that match the specified label.

Get started

  • Create a new Google Apps Script at https://script.google.com
  • Overwrite the placeholder with the javascript below
  • Update the following constants:
  • LABEL_TO_DELETE: the label that should be have old messages deleted