Skip to content

Instantly share code, notes, and snippets.

View guilhermepontes's full-sized avatar
🪁

Guilherme Pontes guilhermepontes

🪁
  • PVH Corp.
  • Amsterdam
  • 13:01 (UTC +01:00)
View GitHub Profile
var app = app || {};
//object literal
app = {
init: function(){
this.cache();
this.bind();
},
cache: function(){
const Application = ((d) => {
const privateVariable = 'Private content'
const __private = {
cache: () => {
this.link = d.querySelector('.link')
},
bind: () => {
this.link.addEventListener('click', this.showContent, false)
@guilhermepontes
guilhermepontes / debounce.js
Last active May 28, 2018 11:45
Simple debounce in javascript
const debounce = function(fn, delay = 450) {
let timeout = null;
return () => {
timeout && clearTimeout(timeout);
timeout = setTimeout(fn.bind(this), delay, arguments);
};
};
// debounce(fn, 300)
@guilhermepontes
guilhermepontes / reduce1.js
Last active December 5, 2016 11:47
Reduce
var votes = [
'angular',
'angular',
'react',
'react',
'react',
'angular',
'ember',
'react',
'vanilla'
@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]
@guilhermepontes
guilhermepontes / ItemListView.js
Last active October 13, 2017 12:48
react - flatList + gingle big datalist
import React, { Component } from 'react'
import { FlatList, Text } from 'react-native'
class ItemListView extends Component {
state = {
currentPage: 1,
perPage: 3,
items: [
{ name: 'A', id: 1 }, { name: 'B', id: 2 }, { name: 'C', id: 3 },
{ name: 'D', id: 4 }, { name: 'E', id: 5 }, { name: 'F', id: 6 },
@guilhermepontes
guilhermepontes / lodash-merge.js
Created June 6, 2017 12:56
Merge 2 array of objects with Lodash Raw
import { map, assign, mapKeys } from 'lodash'
const state = [
{ id: 1, coords: [4, 5, 6] },
{ id: 2, coords: [4, 5, 6] },
{ id: 6, coords: [4, 5, 6] },
{ id: 7, coords: [4, 5, 6] },
{ id: 8, coords: [4, 5, 6] }
]
@guilhermepontes
guilhermepontes / readme.md
Last active November 27, 2022 21:02
Get the old VSCode back on macOS

Get the old VSCode icon back!! 🔥 🔥

First download the new old icon: https://cl.ly/mzTc (based on this)

You can also use the icon you want, but you need to convert it to .icns. You can use this service to convert PNG to ICNS.

Go to Applications and find VSCode, right click there and choose Get Info. Drag 'n drop the new icon.

@guilhermepontes
guilhermepontes / actionTypes.js
Last active October 20, 2017 12:29
Redux Promise Middleware - Auto suffix the actions with: `_PENDING`, `_FULFILLED` and `_REJECTED`
/**
* This method auto add to a list of actions the suffixes
* provided by `redux-promise-middleware`.
*
* Example:
*
* export default createActionTypes(['GET_USER', 'CREATE_USER'])
*
* [object Object] {
* CREATE_USER: "CREATE_USER",