Skip to content

Instantly share code, notes, and snippets.

View smoothness's full-sized avatar

Mauricio Poveda smoothness

  • Costa Rica
View GitHub Profile
@smoothness
smoothness / fetch-data-in-useeffect.js
Created September 3, 2021 01:03
Fetching data in a useEffect that might be triggered several times.
useEffect(() => {
let isSubscribed = true;
// declare the async data fetching function
const fetchData = async () => {
// get the data from the api
const data = await fetch(`https://yourapi.com?param=${param}`);
// convert the data to json
const json = await response.json();
export default connect (
({planeteers}) => console.log(planeteers) || ({capPlanet: planeteers.captain})
)
@smoothness
smoothness / debounce function
Created June 11, 2015 15:04
The debounce function will not allow a callback to be used more than once per given time frame. This is especially important when assigning a callback function to frequently-firing events.
// Returns a function, that, as long as it continues to be invoked, will not
// be triggered. The function will be called after it stops being called for
// N milliseconds. If `immediate` is passed, trigger the function on the
// leading edge, instead of the trailing.
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
var later = function() {
timeout = null;
@smoothness
smoothness / Self Executing function
Created January 14, 2015 20:53
JavasScript Self Executing function
(function() {
console.log('loaded!');
var triggerBttn = document.getElementById( 'trigger-overlay' ),
overlay = document.querySelector( 'div.overlay' ),
closeBttn = overlay.querySelector( 'button.overlay-close' );
transEndEventNames = {
'WebkitTransition': 'webkitTransitionEnd',
'MozTransition': 'transitionend',
'OTransition': 'oTransitionEnd',
@smoothness
smoothness / isPalindrome function
Created January 14, 2015 18:29
isPalindrome recursive function from Secrets of the JavaScript Ninja
function isPalindrome(text) {
if (text.length <= 1) return true;
if (text.charAt(0) != text.charAt(text.length - 1)) return false;
return isPalindrome(text.substr(1, text.length - 2));
}
var cycle = setInterval(function() {
if(condition) {
clearInterval(cycle);
}else{
// do something
}
}, 1000);
@smoothness
smoothness / hack-download-site
Last active December 27, 2015 16:29
Hack-Download a complete site on terminal.
wget --limit-rate=600k --no-clobber --convert-links --random-wait -r -p -E -e robots=off -U mozilla https://www.the-site-to-hack.com/