Skip to content

Instantly share code, notes, and snippets.

View johnhutchins's full-sized avatar

John Hutchins johnhutchins

View GitHub Profile
@johnhutchins
johnhutchins / logGridOfAnySize.js
Last active September 20, 2019 12:47
create grid of any size, where each line is offset
function chessBoard(sizeOfBoard){
const board = sizeOfBoard;
for(let i=0;i<board;i++){
let evenPrintout = '#';
let oddPrintOut = ' #';
if(i === 0){
oddPrintOut = oddPrintOut;
}
if(i % 2 != 0){
@johnhutchins
johnhutchins / compareNumberToArrayItems.js
Created September 19, 2019 14:06
Find the array index where a passed in number should be between (IE, [1,2,4] with a 3 passed in should = [1,2,3,4]
function getIndexToIns(arr, num) {
let arrCopy = arr.sort(function(a, b){return a-b});
let lastIndexOfLowerNum = 0;
for(let i=0;i<arrCopy.length;i++){
if(num>arrCopy[i]){
lastIndexOfLowerNum = i + 1;
}
if(num === arrCopy[i]){
lastIndexOfLowerNum = i;
@johnhutchins
johnhutchins / upperCaseFirstLetter.js
Created September 18, 2019 13:53
uppercase first letter of each word in a string
function titleCase(str) {
//split to array of words
let wordArr = str.split(' ');
let newArr = [];
wordArr.forEach(function(e){
e = e.toLowerCase();
e = e.replace(e[0], e[0].toUpperCase());
newArr.push(e);
})
arrayName[arryName.length - 1];
@johnhutchins
johnhutchins / isNum.js
Last active September 13, 2019 01:31
is a character in a string an integer, useful in for loop, ie if(isNum(someArr[i]))...
function isNum(arg){
if(arg <= 9 && arg >= 1){
return true;
} else {
return false;
}
}
// return masked string where only last 4 digits are shown
function maskify(cc) {
if (cc.length>4){
var masked = '';
for(i=0;i<cc.length-4;i++){
masked += cc[i].replace(cc[i], '#');
}
masked += cc.substring(cc.length-4, cc.length);
return masked;
} else {
@isTest
private class SOQLExamples {
//Return Contact (name, email) with (Account (name, type) with (Owner (name, Profile)). Limit of 1
@isTest
private static void num1() {
Profile p = [SELECT Id, Name FROM Profile WHERE Name='Standard User'];
User userObject = new User(Alias='SysAdmin',
ProfileId=p.Id,
Username='[email protected]',
LastName='Hutchins',
public with sharing class MapExercises {
// Given a list of Accounts, create and return a map where the KEY is the Account Id and the values are the Account
public static Map<Id, Account> getAccountMap(Account[] accs){
Map<Id, Account> accounts = new Map<Id, Account>();
for (Account ac : accs){
accounts.put(ac.Id, ac);
}
//System.debug('Get Account map from passed in data accounts === ', accs);
return accounts;
}
InputCleaner = function() {
var start;
start = function() {
var onKeyUp;
onKeyUp = function () {
var text = $(this).val();
if (text.indexOf("<") !== -1 || text.indexOf(">") !== -1 || text.indexOf('"') !== -1 || text.indexOf("'") !== -1) {
text = text.replace(/</g, "");
@johnhutchins
johnhutchins / .bash_profile
Created February 27, 2018 16:45
mac osx terminal/bash profile
export CLICOLOR=1
RED="\[\033[0;31m\]"
BLACK="\[\033[0;37m\]"
PS1="$\u \e[34;1m\]\w \n $ -—> "
#PS1=“\e[47m\u@\h \w \e[m ”