Skip to content

Instantly share code, notes, and snippets.

View guilhermepontes's full-sized avatar
🪁

Guilherme Pontes guilhermepontes

🪁
  • PVH Corp.
  • Amsterdam
  • 08:56 (UTC +01:00)
View GitHub Profile
@tomhicks
tomhicks / InternalLink.tsx
Created July 24, 2020 11:09
Strongly-typed NextJS internal links
@nickytonline
nickytonline / async-await-promise-all.js
Last active August 12, 2018 07:43
async/await with Promise.all
// In response to https://twitter.com/housecor/status/930108010558640128
function doubleAfter2Seconds(x) {
return new Promise(resolve => {
resolve(x * 2);
}, 2000);
}
async function addAsync(x) {
const { a, b, c } = await Promise.all([
doubleAfter2Seconds(10),
@aliceklipper
aliceklipper / webpack.config.js
Last active November 30, 2019 16:16
Simplest config for just TS building
const { join } = require('path');
const webpack = require('webpack');
const DefinePlugin = webpack.DefinePlugin;
module.exports = {
target : 'web',
entry : './src/index.tsx',
output : {
chunkFilename : '[id].index.js',
filename : 'index.js',
@guilhermepontes
guilhermepontes / shuffle.js
Last active October 29, 2023 01:41
Shuffle Array - JavaScript ES2015, ES6
// original gist
const shuffleArray = arr => arr.sort(() => Math.random() - 0.5);
// fully random by @BetonMAN
const shuffleArray = arr => arr
.map(a => [Math.random(), a])
.sort((a, b) => a[0] - b[0])
.map(a => a[1]);
shuffleArray([1, 2, 3]) //[3, 1, 2]
@guilhermepontes
guilhermepontes / mocks.js
Created January 9, 2017 22:25
whatwg-fetch mocks
const fetchMock = (response) => {
window.fetch = jest.fn().mockImplementation(() =>
new Promise((resolve) => {
resolve({ json: () => response })
})
)
}
const fetchMockRejected = (response) => {
window.fetch = jest.fn().mockImplementation(() =>
@MarcoWorms
MarcoWorms / mini-redux.js
Last active June 3, 2024 04:42
Redux in a nutshell
function createStore (reducers) {
var state = reducers()
const store = {
dispatch: (action) => {
state = reducers(state, action)
},
getState: () => {
return state
}
}

This is a proposal for a lightning talk at the Reactive 2016 conference. If you like this, star the Gist.


Thinking metrics on React applications

In regular websites, it is common to send multiple events to track user clicks. Single Page Applications change the way you look at metrics. This is a talk about a simple pattern we created at Globo.com to manage a metrics layer for http://globoplay.globo.com. The talk will cover how to track user flow using Google Analytics and other services. We solved the challenge of tying metrics and components, keeping information across pages and having global data. Also some React, React Router and React Side Effects concepts like context, higher order components, history state will be covered.

@chadsmith
chadsmith / FaviconAwesome.js
Last active January 11, 2018 19:03
FontAwesome in Favicons
(function() {
var FaviconAwesome = function(icon, color, bg) {
'use strict';
var
container = document.createElement('div'),
span = document.createElement('span'),
body = document.body,
content,
canvas = document.createElement('canvas'),
getContext = function(w) {
@WebReflection
WebReflection / String.prototype.template.js
Last active August 17, 2022 04:04
ES6 Template like strings in ES3 compatible syntax.
// this is now a module:
// https://github.com/WebReflection/backtick-template#es2015-backticks-for-es3-engines--
var template = require('backtick-template');
// just string
const info = 'template';
`some ${info}` === template('some ${info}', {info});
@tsiege
tsiege / The Technical Interview Cheat Sheet.md
Last active December 3, 2024 15:06
This is my technical interview cheat sheet. Feel free to fork it or do whatever you want with it. PLEASE let me know if there are any errors or if anything crucial is missing. I will add more links soon.

ANNOUNCEMENT

I have moved this over to the Tech Interview Cheat Sheet Repo and has been expanded and even has code challenges you can run and practice against!






\