Skip to content

Instantly share code, notes, and snippets.

View EricHech's full-sized avatar

Eric Hechavarria EricHech

View GitHub Profile
export const getGmtDiff = (timeZone: typeof IANNA_TIME_ZONES[number]["key"]) => {
const date = new Date();
const GMT_TIME_UTC_DATE = date.getUTCDate();
const GMT_TIME_HOURS = date.getUTCHours();
const GMT_TIME_MIN = date.getUTCMinutes();
const timeZoneDate = new Date(new Date().toLocaleString("en-US", { timeZone }));
const h = timeZoneDate.getHours();
@EricHech
EricHech / createLUT.js
Created January 6, 2019 04:48
Pass it an object and it will console.log a new object with the reverse key/val pairs added to it.
const createLUT = (obj) => {
const copy = { ...obj };
Object.entries(copy).forEach((each) => (copy[each[1]] = each[0]));
console.log(JSON.stringify(copy));
};
@EricHech
EricHech / numberOfPathsInDiagonalGrid.js
Created December 2, 2018 08:57
An answer to a version of the "find the number of paths" CC
// If a square is divided diagonally so that you have an isosceles right triangle,
// this function will find how many paths may be taken to get from one corner to the given index
function numberOfPathsInDiagonalGrid(x, y) {
if (x === 1 || y === 1) return 1;
if (x > y) return numberOfPathsInDiagonalGrid(x - 1, y);
else return (
numberOfPathsInDiagonalGrid(x - 1, y) +
numberOfPathsInDiagonalGrid(x, y - 1)
);
@EricHech
EricHech / consoleLogStyling.js
Last active November 28, 2018 04:39
console.log tips
console.log('%c A log in green' + '%c A log in red', 'font-size: 40px; font-weight: 600; color: green;', 'font-size: 40px; font-weight: 600; color: red;');
// another trick: console.assert will print the second value only if the first one is falsey