Skip to content

Instantly share code, notes, and snippets.

View brunormferreira's full-sized avatar
:octocat:
coding and learning

Bruno Ramires brunormferreira

:octocat:
coding and learning
View GitHub Profile
@origamid
origamid / smooth-scroll.js
Last active July 21, 2022 15:23 — forked from clemlatz/smooth-scroll.js
Smooth Scroll Animation - JavaScript
/**
* Smooth scroll animation
* @param {int} endX: destination x coordinate
* @param {int} endY: destination y coordinate
* @param {int} duration: animation duration in ms
*/
function smoothScrollTo(endX, endY, duration) {
const startX = window.scrollX || window.pageXOffset;
const startY = window.scrollY || window.pageYOffset;
const distanceX = endX - startX;
@bradtraversy
bradtraversy / sample.md
Created March 23, 2018 18:17
Markdown Cheat Sheet

Heading 1

Heading 2

Heading 3

Heading 4

Heading 5
Heading 6

This text is italic

import React, { Component } from 'react';
import Candidate from './Candidate.js';
import Button from 'react-uikit-button';
export default class CandidateList extends Component {
constructor(props) {
super(props);
this.handleClick = this.handleClick.bind(this)
}
import React, { Component } from 'react';
import CandidateList from './Views/CandidateList.js';
import Candidate from './Views/Candidate.js';
import fetch from 'isomorphic-fetch';
import { Route, Switch } from "react-router-dom";
class ParentComponent extends Component {
constructor(props) {
super(props);
this.state = {
@Geoff-Ford
Geoff-Ford / composing-software.md
Last active May 30, 2025 17:26
Eric Elliott's Composing Software Series

Eric Elliott's "Composing Software" Series

A collection of links to the excellent "Composing Software" series of medium stories by Eric Elliott.

Edit: I see that each post in the series now has index, previous and next links. However, they don't follow a linear flow through all the articles with some pointing back to previous posts effectively locking you in a loop.

function maximizeFontSize(elem, maxWidth, maxHeight, opt_dontChangeFontSize) {
var canBeBigger,
display = elem.style.display,
fontSize = elem.style.fontSize,
font = elem.style.font,
computedFont = window.getComputedStyle(elem, null).getPropertyValue('font'),
doc = elem.ownerDocument,
parentNode = elem.parentNode,
tempParent = doc.createElement('div'),
nextSibling = elem.nextSibling,
function getVideoImage(path, secs, callback) {
var me = this, video = document.createElement('video');
video.onloadedmetadata = function() {
if ('function' === typeof secs) {
secs = secs(this.duration);
}
this.currentTime = Math.min(Math.max(0, (secs < 0 ? this.duration : 0) + secs), this.duration);
};
video.onseeked = function(e) {
var canvas = document.createElement('canvas');
@praveenpuglia
praveenpuglia / shadow-dom.md
Last active May 3, 2025 10:03
Everything you need to know about Shadow DOM

I am moving this gist to a github repo so more people can contribute to it. Also, it makes it easier for me to version control.

Please go to - https://github.com/praveenpuglia/shadow-dom-in-depth for latest version of this document. Also, if you find the document useful, please shower your love, go ⭐️ it. :)

Shadow DOM

Heads Up! It's all about the V1 Spec.

In a nutshell, Shadow DOM enables local scoping for HTML & CSS.

@fgilio
fgilio / axios-catch-error.js
Last active June 18, 2025 11:09
Catch request errors with Axios
/*
* Handling Errors using async/await
* Has to be used inside an async function
*/
try {
const response = await axios.get('https://your.site/api/v1/bla/ble/bli');
// Success 🎉
console.log(response);
} catch (error) {
// Error 😨
@ericelliott
ericelliott / filter.js
Last active December 22, 2020 17:19
Filter implemented with reduce
const filter = (fn, arr) => arr.reduce((newArr, item) => {
return fn(item) ? newArr.concat([item]) : newArr;
}, []);