Skip to content

Instantly share code, notes, and snippets.

View NyaGarcia's full-sized avatar
🐈

Nya NyaGarcia

🐈
View GitHub Profile
@NyaGarcia
NyaGarcia / docker-compose.yml
Created April 16, 2019 14:28
docker-compose.yml file for dockerizing mongoDB
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 April 29, 2019 15:32
Using async await inside of 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 September 5, 2019 14:35
MongoDB Compose file with environment variables
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 September 2, 2019 19:32
MongoDB Compose file with named .env file
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 September 5, 2019 14:42
MongoDB Compose file using string interpolation to assign values to the environment variables
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 December 20, 2021 13:44
Merging arrays with the spread operator
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 September 12, 2019 11:47
Merging object arrays with spread operator
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 December 20, 2021 13:44
Adding an element to an array with the spread operator
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 September 12, 2019 12:07
Three examples of how the spread operator works with arrays
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 December 20, 2021 13:44
Adding object properties with the spread operator
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' }