Skip to content

Instantly share code, notes, and snippets.

View gil00pita's full-sized avatar
💭
I may be slow to respond.

Gil Álvaro gil00pita

💭
I may be slow to respond.
View GitHub Profile
@gil00pita
gil00pita / class_properties.jsx
Last active February 8, 2019 23:17 — forked from gisderdube/class_properties.jsx
https://levelup.gitconnected.com/9-tricks-for-kickass-javascript-developers-in-2019-eb01dd3def2a ### Class properties & binding Binding functions in JavaScript is a common task. With the introduction of arrow functions in the ES6 spec, we now have
class Counter extends React.Component {
constructor(props) {
super(props)
this.state = { count: 0 }
}
render() {
return(
<div>
<h1>{this.state.count}</h1>
@gil00pita
gil00pita / default.js
Last active February 8, 2019 23:15 — forked from gisderdube/default.js
https://levelup.gitconnected.com/9-tricks-for-kickass-javascript-developers-in-2019-eb01dd3def2a ### Destructuring & default values Let’s return to our previous example where we do the following: ``` const result = axios.get(`https://ironhack-pok
function calculate({operands = [1, 2], type = 'addition'} = {}) {
return operands.reduce((acc, val) => {
switch(type) {
case 'addition':
return acc + val
case 'subtraction':
return acc - val
case 'multiplication':
return acc * val
case 'division':
@gil00pita
gil00pita / async_promise_all.js
Last active February 8, 2019 23:14 — forked from gisderdube/async_promise_all.js
https://levelup.gitconnected.com/9-tricks-for-kickass-javascript-developers-in-2019-eb01dd3def2a Promise.all What if you want to fetch all of the Pokemon in parallel? Since you can await all of Promises, simply use Promise.all :
import axios from 'axios'
let myData = [{id: 0}, {id: 1}, {id: 2}, {id: 3}]
async function fetchData(dataSet) {
const pokemonPromises = dataSet.map(entry => {
return axios.get(`https://ironhack-pokeapi.herokuapp.com/pokemon/${entry.id}`)
})
const results = await Promise.all(pokemonPromises)
@gil00pita
gil00pita / forOf.js
Last active February 8, 2019 23:13 — forked from gisderdube/forOf.js
https://levelup.gitconnected.com/9-tricks-for-kickass-javascript-developers-in-2019-eb01dd3def2a Often times, it is necessary to fetch multiple datasets and do something for each of those or complete a task after all of the async calls have returned
import axios from 'axios'
let myData = [{id: 0}, {id: 1}, {id: 2}, {id: 3}]
async function fetchData(dataSet) {
for(entry of dataSet) {
const result = await axios.get(`https://ironhack-pokeapi.herokuapp.com/pokemon/${entry.id}`)
const newData = result.data
updateData(newData)
@gil00pita
gil00pita / async.js
Last active February 8, 2019 23:12 — forked from gisderdube/async.js
https://levelup.gitconnected.com/9-tricks-for-kickass-javascript-developers-in-2019-eb01dd3def2a If you’re still stuck in callback hell, 2014 wants its code back. Just don’t use callbacks, unless it is absolutely necessary, for example required by a
async function getData() {
const result = await axios.get('https://dube.io/service/ping')
const data = result.data
console.log('data', data)
return data
}
getData()

Moving from jQuery

Events

// jQuery
$(document).ready(function() {
  // code
})
@gil00pita
gil00pita / brew-install-script.sh
Last active August 13, 2021 08:02 — forked from CliffordAnderson/brew-install-script.sh
Brew install script for OSX
#!/bin/sh
# Homebrew Script for OSX
# To execute: save and `chmod +x ./brew-install-script.sh` then `./brew-install-script.sh`
echo "Installing brew..."
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
echo "Installing brew cask..."
brew tap homebrew/cask