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 / cores.scss
Created March 9, 2021 17:45
SASS cores.scss
/*----------------------------------------------------
@File: Core Styles
@Author: Wes Duff
Author E-mail: wes.duff.dev@gmail.com
This is the core css for your application
- fonts
- base text sizes for h1-h6
---------------------------------------------------- */
@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 / 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 / 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 / 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 / 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 / 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 / testing.jest.reduxactions.thunks.js
Created March 11, 2018 14:55
Testing with JEST : Redux Actions and Thunks
/* =============== CONSTANTS ============================ */
export const AWS_SIGN_UP_SAVING = 'AWS_SIGNUP_SAVE';
export const AWS_SIGN_UP_FAIL = 'AWS_SIGN_UP_FAIL';
export const AWS_SIGN_UP_SUCCESS = 'AWS_SIGN_UP_SUCCESS';
export const THROW_ERROR = 'THROW_ERROR';
export const CLEAR_ERROR = 'CLEAR_ERROR';
@wesleyduff
wesleyduff / getNumber_s_Missing_From_array.cs
Created March 11, 2018 03:20
Get the number(s) missing from an array. C#. XOR. : Working example : https://dotnetfiddle.net/PKpGEm
using System;
public class Program
{
public static int GetMissingNumberFromArray(int[] arr)
{
Console.WriteLine("=======================");
int totalXor = 0;
int totalArrXor = 0;
@wesleyduff
wesleyduff / nock.superagent.post.jest.test.js
Last active March 11, 2018 02:07
Mock a call to a service with npm nock and npm superagent using a POST
import nock from 'nock';
import request from 'superagent';
describe('Calling AWS SDK to sign up a user', () => {
let postData = {username: 'fake@fake.com', password: '@Password1'};
let _request = null;
beforeEach(() => {
nock('http://aws-sdk.aws.com/', {