Skip to content

Instantly share code, notes, and snippets.

View oscaroceguera's full-sized avatar
🏠
Working from home

Oscar E. Oceguera Bibriesca oscaroceguera

🏠
Working from home
View GitHub Profile
@oscaroceguera
oscaroceguera / app-static.js
Created May 21, 2018 19:59
Load static app with react, react-router-4, express
const express = require('express')
const path = require('path')
const app = express()
const port = process.env.PORT || 8000
app.use(express.static(path.join(__dirname, '/public')))
app.get('*', function (req, res) {
res.sendFile(path.resolve(__dirname, 'public', 'index.html'))
})
const axios = require('axios')
const getGeoAddress = encodedAddress =>
axios.get(`https://maps.googleapis.com/maps/api/geocode/json?address=${encodedAddress}`)
.then(response => {
return {
lat: response.data.results[0].geometry.location.lat,
lng: response.data.results[0].geometry.location.lng,
formatted_address: response.data.results[0].formatted_address
}
const axios = require('axios')
const encodedAddress = encodeURIComponent('Av. Insurgentes Sur 601, Ciudad de México')
// console.log(encodedAddress) => Av.%20Insurgentes%20Sur%20601%2C%20Ciudad%20de%20M%C3%A9xico
const geocodeURL = `https://maps.googleapis.com/maps/api/geocode/json?address=${encodedAddress}`
axios.get(geocodeURL)
.then(response => {
if (response.data.status === 'ZERO_RESULTS') {
throw new Error('Unable to find that address')
const request = require('request')
const geocodeAddress = (address, callback) => {
// console.log(encodedAddress) => Av.%20Insurgentes%20Sur%20601%2C%20Ciudad%20de%20M%C3%A9xico
const encodedAddress = encodeURIComponent(address)
request({
url: `https://maps.googleapis.com/maps/api/geocode/json?address=${encodedAddress}`,
json: true
}, (error, response, body) => {
if (error) {
async function name ([param[, param[, ... param]]]) {
// statements
}
async function fetchCountriesWithStates() {
const countries = await fetchCountries()
const _states = await fetchStates()
return countries.map(country => ({
...country,
function greet() {
name = 'Hammad';
return function () {
console.log('Hi ' + name);
}
}
greet()(); // logs 'Hi Hammad'
function greet() {
name = 'Hammad';
return function () {
console.log('Hi ' + name);
}
}
greet(); // nothing happens, no errors
// the returned function from greet() gets saved in greetLetter
function grandFather () {
var name = 'Oscar'
// like no es accesible aqui
fucntion parent () {
// name es accesible desde aqui
// like no es accesible desde aqui
function child () {
// nivel mas profundo del scope
// name tambien es accesible desde aqui
var likes = 'React'
executionContextObject = {
'scopeChain': {}, // contiene su propio objeto variable y otros objetos variables de los contextos
'variableObject': {}, // contiene argumento de funciones, variables internas y declaraciones de funciones
'this': valueOfThis
}
'scopeChain': {
// contiene su propio objeto variable y otros objetos de los contextos de ejecución padre
}