Skip to content

Instantly share code, notes, and snippets.

View guilhermepontes's full-sized avatar
🪁

Guilherme Pontes guilhermepontes

🪁
View GitHub Profile
@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(() =>
@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]
@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',
@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),
@tomhicks
tomhicks / InternalLink.tsx
Created July 24, 2020 11:09
Strongly-typed NextJS internal links