Skip to content

Instantly share code, notes, and snippets.

View panphora's full-sized avatar
🎯
Focusing

David Miranda panphora

🎯
Focusing
View GitHub Profile
@mikberg
mikberg / connection.js
Last active December 29, 2021 16:57
MongoDB connection with async/await
import { MongoClient } from 'mongodb';
import promisify from 'es6-promisify';
let _connection;
const connect = () => {
if (!process.env.MONGO_CONNECTION_STRING) {
throw new Error(`Environment variable MONGO_CONNECTION_STRING must be set to use API.`);
}
@Daniel-Hug
Daniel-Hug / delegate-event.js
Last active September 14, 2020 05:05
Vanilla JS equivalent of jQuery's .live(): use event delegation to handle events whose target matches a selector, closest(): get nearest parent element matching selector
// get nearest parent element matching selector
var closest = (function() {
var el = HTMLElement.prototype;
var matches = el.matches || el.webkitMatchesSelector || el.mozMatchesSelector || el.msMatchesSelector;
return function closest(el, selector) {
return matches.call(el, selector) ? el : closest(el.parentElement, selector);
};
})();
@egardner
egardner / deepequal.js
Created May 22, 2017 00:21
Simple deep equality comparison in Javascript (ES5+)
// Deep Equality comparison example
//
// This is an example of how to implement an object-comparison function in
// JavaScript (ES5+). A few points of interest here:
//
// * You can get an array of all an object's properties in ES5+ by calling
// the class method Object.keys(obj).
// * The function recursively calls itself in the for / in loop when it
// compares the contents of each property
// * You can hide a "private" function inside a function of this kind by
var $activeEpisodes = $(".episodecell");
var episodesReversedElements = $activeEpisodes.toArray().reverse();
var lastPodcastName;
episodesReversedElements.forEach(function (elem) {
var $activeEpisode = $(elem);
var podcastName = $activeEpisode.find(".titlestack div:first-child").text();
var podcastImgSrc = $activeEpisode.find(".art").attr("src");
if (podcastName !== lastPodcastName) {
//
// <button> reset
//
// 1. Remove default browser appearance for buttons.
// 2. Remove margins.
// 3. Remove borders for IE.
// 4. Normalize font and color not inherited by `button`.
// 5. Address `overflow` in IE
// 6. Normalize cursor style