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 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: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 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:

Keybase proof

I hereby claim:

  • I am nyagarcia on github.
  • I am nyachan (https://keybase.io/nyachan) on keybase.
  • I have a public key ASCX_KYHXdj9trZ43Hq4aShjNWxZxVQ-XNDJM8IMc9sV1go

To claim this, I am signing this object:

@NyaGarcia
NyaGarcia / dynamic-destructure-array.js
Last active September 21, 2019 15:39
Dynamically destructuring an array of properties with the spread operator
function dynamicDestructureMany(object, properties) {
return properties.map(property => {
const { [property]: value } = object;
return value;
});
}
console.log(dynamicDestructureMany(pokemon, ['name', 'type'])); //Result: ['Squirtle', 'Water']
@NyaGarcia
NyaGarcia / rest-parameter-destructuring.js
Created September 23, 2019 15:57
Destructuring with the rest parameter
const pokemon = {
id: 1,
name: 'Squirtle',
type: 'Water'
};
const { id, ...rest } = pokemon;
console.log(rest); //Result: { name: 'Squirtle', type: 'Water' }
@NyaGarcia
NyaGarcia / default-property.js
Last active September 23, 2019 16:43
Showing how the existing abilities property isn't modified
const pokemon = {
name: 'Squirtle',
type: 'Water',
abilities: ['Torrent', 'Rain Dish']
};
const { abilities = [], ...rest } = pokemon;
const fullSquirtle = { ...rest, abilities };
console.log(rest); //Result: { name: 'Squirtle', type: 'Water' }
@NyaGarcia
NyaGarcia / default-values-destructuring.js
Created September 24, 2019 16:00
Assigning default values to destructured variables
const pokemon = {
id: 1,
name: 'Squirtle'
};
const { type, name } = pokemon;
console.log(name); //Result: Squirtle
console.log(type); //Result: undefined
//Assigning default value to the type variable