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
@ericelliott
ericelliott / map-custom-data-type.js
Created January 4, 2017 00:20
Map with custom data type
const double = n => n.points * 2;
const doubleMap = numbers => numbers.map(double);
console.log(doubleMap([
{ name: 'ball', points: 2 },
{ name: 'coin', points: 3 },
{ name: 'candy', points: 4}
])); // [ 4, 6, 8 ]
@ericelliott
ericelliott / promise-chaining.js
Last active April 3, 2020 02:13
Promise chaining behaviors
const wait = time => new Promise(
res => setTimeout(() => res(), time)
);
wait(200)
// onFulfilled() can return a new promise, `x`
.then(() => new Promise(res => res('foo')))
// the next promise will assume the state of `x`
.then(a => a)
// Above we returned the unwrapped value of `x`
@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;
}, []);
@fgilio
fgilio / axios-catch-error.js
Last active April 11, 2024 19:02
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 😨
@praveenpuglia
praveenpuglia / shadow-dom.md
Last active March 28, 2024 15:06
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.

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');
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,
@Geoff-Ford
Geoff-Ford / composing-software.md
Last active May 31, 2024 22:32
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.

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 = {
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)
}