Skip to content

Instantly share code, notes, and snippets.

View elpuas's full-sized avatar
💻
coding

Alfredo Navas-Fernandini elpuas

💻
coding
View GitHub Profile
@elpuas
elpuas / element-ready.js
Last active June 28, 2021 19:38
Waits for Element to exist on the DOM
/**
* Waits for an element satisfying selector to exist, then resolves promise with the element.
* Useful for resolving race conditions.
*
* @param selector
* @returns {Promise}
*/
function elementReady(selector) {
return new Promise((resolve, reject) => {
let el = document.querySelector(selector);
@elpuas
elpuas / counter.js
Created May 20, 2021 14:21
counter with intersection observer
// How long you want the animation to take, in ms
const animationDuration = 2000;
// Calculate how long each ‘frame’ should last if we want to update the animation 60 times per second
const frameDuration = 1000 / 60;
// Use that to calculate how many frames we need to complete the animation
const totalFrames = Math.round( animationDuration / frameDuration );
// An ease-out function that slows the count as it progresses
const easeOutQuad = t => t * ( 2 - t );
// Variables
app.use("/", (req, res, next) => {
console.log("I am a middleaware")
next()
})
...
"scripts": {
"start": "nodemon index.js"
}
document.addEventListener("DOMContentLoaded", function(event) {
console.log( 'Hello From Public' );
});
body {
background-color: beige
}
<link rel="stylesheet" href="css/styles.css">
<script src="js/index.js"></script>
const express = require('express')
const app = express()
// path is a built in module in Node
// It Helps get the specific path to the files
const path = require('path')
// Add the Public Folder for Assets
app.use(express.static('public'))
app.listen( 3000, () => {
@elpuas
elpuas / .bash
Last active April 6, 2021 21:20
mkdir public && cd public
# Create the sub folders
mkdir css js
# Create the style file
cd css && touch styles.css
# Create the script file
cd ../js && touch index.js
const express = require('express')
const app = express()
// path is a built in module in Node
// It Helps get the specific path to the files
const path = require('path')
app.listen( 3000, () => {
console.log('App listening on port 3000')
})