Skip to content

Instantly share code, notes, and snippets.

View wesleyduff's full-sized avatar

Wes Duff wesleyduff

  • Denver Colorado
View GitHub Profile
@wesleyduff
wesleyduff / javscript_singelton.js
Last active April 16, 2018 17:32
JavaScript Singleton Pattern
let logger_instance = null;
class Logger {
constructor() {
}
static instance(message, user, serviceError, note, code){
console.log('static instance called');
if(logger_instance === null){
console.log('==== create');
logger_instance = new Logger();
@wesleyduff
wesleyduff / encryptDecryptDataOverTheWire.js
Created May 1, 2018 15:46
Encrypt Decrypt data over HTTP calls | NODE.JS
const crypto = require('crypto');
const algorithm = 'aes-256-ctr';
const password = '<your password>';
class CryptoString {
static set(text){
const cipher = crypto.createCipher(algorithm, password);
let crypted = cipher.update(text, 'utf8', 'hex');
@wesleyduff
wesleyduff / longestPalindrome.js
Last active June 4, 2018 16:15
Get Longest Palindrome from a string using JavaScript : Node.js
/**
* Dynamic Programming example :
* break the problems down into individual methods that handle one thing
* Put together the solutions from all of the individual methods to come up with the answer.
* store
* - table bool [][] // storage data structure
* - palindrome
* - length of pongest palindrome
*
* methods: sub problems
@wesleyduff
wesleyduff / cleanCodeErrorHandling.js
Last active June 12, 2018 16:58
Separate Error Handling from your code : Clean Code : Error Handling
class CustomException extends Error {
constructor(message, errorCode) {
super(message);
this.name = 'MyError';
this.code = errorCode || 510;
}
}
class Logger {
constructor(error){
this.error = error;
@wesleyduff
wesleyduff / MOCK_RavenIngestLogger.js
Created January 7, 2019 20:45
Feature Flags : Example - Should have vault-<env>.json setup in the correct location and tests updated
/* Need this so tests will pass */
global.RavenIngestLogger = {
error: function(val){
console.log(`mock RavenIngestLogger -> Error : ${JSON.stringify(val)}`);
},
debug: function(val){
console.log(`mock RavenIngestLogger -> debug : ${typeof val === 'string' ? val : JSON.stringify(val)}`);
},
info: function(val){
console.log(`mock RavenIngestLogger -> info : ${JSON.stringify(val)}`);
@wesleyduff
wesleyduff / testLogger.js
Last active January 23, 2019 18:30
Node Logger Mock for JavaScript Testing - write to file not console
/**
Assumptions
- You have a folder in the same space named baseLogger
- - You can have other loggers if needed but with this code, you must have a baseLogger
Inside baseLogger
- should have but not limited to
- - debug.log.txt
**/
const fileWriter = ((fs) => {
@wesleyduff
wesleyduff / cores.scss
Created March 9, 2021 17:45
SASS cores.scss
/*----------------------------------------------------
@File: Core Styles
@Author: Wes Duff
Author E-mail: [email protected]
This is the core css for your application
- fonts
- base text sizes for h1-h6
---------------------------------------------------- */