This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// example MySQL DATETIME | |
const dateTime = '2017-02-04 11:23:54'; | |
let dateTimeParts= dateTime.split(/[- :]/); // regular expression split that creates array with: year, month, day, hour, minutes, seconds values | |
dateTimeParts[1]--; // monthIndex begins with 0 for January and ends with 11 for December so we need to decrement by one | |
const dateObject = new Date(...dateTimeParts); // our Date object |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
location.search.substr(1) | |
.split('&') | |
.reduce((ac, cur) => { | |
if (cur) { | |
const kv = cur.split('=') | |
ac[kv[0]] = decodeURIComponent(kv[1].replace(/\+/g, ' ')) | |
} | |
return ac | |
}, {}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function *fibonacci(n) { | |
const infinite = !n && n !== 0; | |
let current = 0; | |
let next = 1; | |
while (infinite || n--) { | |
yield current; | |
[current, next] = [next, current + next]; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
element.addEventListener('click', function cb(event) { | |
// ...one-time handling of the click event... | |
event.target.removeEventListener(event.type, cb); | |
}); | |
// or: | |
element.addEventListener('click', function(event) { | |
// ...one-time handling of the click event... | |
}, {once: true}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.querySelector('iframe#abc123').contentDocument | |
.querySelectorAll('a') | |
.forEach(a => a.addEventListener('click', () => console.log('CLICK!'))); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git tag new old # create new tag | |
git tag -d old # remove old tag | |
git push origin :refs/tags/old # remove old tag from remote repository | |
git push --tags # push tags |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git branch -m old_branch new_branch # Rename branch locally | |
git push origin :old_branch # Delete the old branch | |
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Add (or remove) some time from current date. Returns new Date | |
* | |
* @param {string} elapsedTime | |
* @param {Date|null} dateObject | |
* @returns {Date} | |
* @private | |
*/ | |
function getNewTime(elapsedTime, dateObject) { |