Skip to content

Instantly share code, notes, and snippets.

Avatar

Nya NyaGarcia

View GitHub Profile
@NyaGarcia
NyaGarcia / docker-compose.yml
Created Apr 16, 2019
docker-compose.yml file for dockerizing mongoDB
View docker-compose.yml
version: "3.1"
services:
db:
container_name: mongoDB
image: mongo:latest
restart: always
volumes:
- ./pokeData:/data/db
environment:
@NyaGarcia
NyaGarcia / async Array.map
Last active Apr 29, 2019
Using async await inside of Array.map()
View async Array.map
function getCalculatedRoutes(routes: Array<any>): Promise<any> {
return Promise.all(
routes.map(async (route: any) => {
const distance = await getDistance();
route.distance = distance;
route.cost = calculateCost(distance);
return route;
})
);
}
@NyaGarcia
NyaGarcia / docker-compose.yml
Last active Sep 5, 2019
MongoDB Compose file with environment variables
View docker-compose.yml
version: '3.1'
services:
db:
container_name: Mongo-db
image: mongo:latest
restart: always
volumes:
- ./myData:/data/db
environment:
@NyaGarcia
NyaGarcia / docker-compose.yml
Last active Sep 2, 2019
MongoDB Compose file with named .env file
View docker-compose.yml
version: '3.1'
services:
db:
container_name: Mongo-db
image: mongo:latest
restart: always
volumes:
- ./myData:/data/db
env_file:
@NyaGarcia
NyaGarcia / docker-compose.yml
Last active Sep 5, 2019
MongoDB Compose file using string interpolation to assign values to the environment variables
View docker-compose.yml
version: '3.1'
services:
db:
container_name: Mongo-db
image: mongo:latest
restart: always
volumes:
- ./myData:/data/db
environment:
@NyaGarcia
NyaGarcia / merge-arrays.js
Last active Sep 12, 2019
Merging arrays with the spread operator
View merge-arrays.js
const pokemon = ['Squirtle', 'Bulbasur', 'Charmander'];
const morePokemon = ['Totodile', 'Chikorita', 'Cyndaquil'];
const pokedex = [...pokemon, ...morePokemon];
console.log(pokedex); //Result: [ 'Squirtle', 'Bulbasur', 'Charmander', 'Totodile', 'Chikorita', 'Cyndaquil' ]
@NyaGarcia
NyaGarcia / merge-object-arrays.js
Created Sep 12, 2019
Merging object arrays with spread operator
View merge-object-arrays.js
const pokemon = [
{ name: 'Squirtle', type: 'Water' },
{ name: 'Bulbasur', type: 'Plant' }];
const morePokemon = [{ name: 'Charmander', type: 'Fire' }];
const pokedex = [...pokemon, ...morePokemon];
console.log(pokedex); //Result: [ { name: 'Squirtle', type: 'Water' }, { name: 'Bulbasur', type: 'Plant' }, { name: 'Charmander', type: 'Fire' } ]
@NyaGarcia
NyaGarcia / add-array-element.js
Last active Sep 14, 2019
Adding an element to an array with the spread operator
View add-array-element.js
const pokemon = ['Squirtle', 'Bulbasur'];
const charmander = 'Charmander';
const cyndaquil = 'Cyndaquil';
const pokedex = [...pokemon, charmander, cyndaquil];
console.log(pokedex); //Result: [ 'Squirtle', 'Bulbasur', 'Charmander', 'Cyndaquil' ]
@NyaGarcia
NyaGarcia / spread-array-examples.js
Created Sep 12, 2019
Three examples of how the spread operator works with arrays
View spread-array-examples.js
const numbers = [1, 2, 3];
console.log(...numbers); //Result: 1 2 3
const pokemon = ['Squirtle', 'Bulbasur', 'Charmander'];
console.log(...pokemon); //Squirtle Bulbasur Charmander
const pokedex = [
{ name: 'Squirtle', type: 'Water' },
{ name: 'Bulbasur', type: 'Plant' },
{ name: 'Charmander', type: 'Fire' }
@NyaGarcia
NyaGarcia / add-object-property.js
Last active Sep 14, 2019
Adding object properties with the spread operator
View add-object-property.js
const basicSquirtle = { name: 'Squirtle', type: 'Water' };
const fullSquirtle = {
...basicSquirtle,
species: 'Tiny Turtle Pokemon',
evolution: 'Wartortle'
};
console.log(fullSquirtle); //Result: { name: 'Squirtle', type: 'Water', species: 'Tiny Turtle Pokemon', evolution: 'Wartortle' }
You can’t perform that action at this time.