Posted on May 17, 2019
Say we have an API client with three methods, getItem(), updateItem(), and deleteItem(), each of which returns a Promise. There are only two functions you need to worry about: then() and catch().
Each call to then() creates another step in the Promise chain, and if there’s an error at any point in the chain, the next catch() block will be triggered. Both then() and catch() can either return a raw value or a new Promise, and the result will be passed to the next then() in the chain.
If a function doesn’t return a Promise but rather a callback, like Node’s fs.readile function,
then you can convert the call to a Promise as follows. The new function, called readFilePromise, converts the original function, called readFile, into a Promise.
To use the new promise function, do this.
If you have a function that needs to return a Promise, like fs.readFile, but handle certain cases synchronously, you can use Promise.resolve() and Promise.reject() to create Promises out of ordinary values, like this.
Promise.all is a convenient method for running an array of Promises concurrently, i.e. all at the same time. For instance, say we have a list of files we want to read from disk. Using the readFilePromise function we created above, it would look like this:
Here’s another example
And another example (from Kyle Simpson)
In the example above, we can use the new Promisified function in the chain as follows. We can also create a new Promise that returns a Promise of an ordinary value to keep the chain going.
Posted on May 9, 2019
When traveling, it’s super handy to be able to see a map of just the places you want to visit. This can easily be done with Google Maps. In addition, with Google Maps you can zoom in and out and get directions to each place of interest. Here’s how to create a custom Google Map with your choice of places.
1. Go to maps.google.com and log in
2. Click the hamburger menu icon and then “Your Places”
3. Click the “Maps” tab
3. At the bottom, click “Create Map”
4. In the search bar, enter the name or address of a place then click the search button.
5. Google Maps will place a balloon on the map where the place it along with a description box.
6. In the description box, click “Add to map”
7. Repeat steps 4-6 adding as many locations as you’d like
8. To make it easier to see the location, change the color and details of the base map.
9. To share or embed a map, click the hamburger menu icon and then “Share or embed map”
Posted on May 3, 2019
No matter what you eat or how much you exercise, the formula for losing weight is very simple. Burn more calories per day than you consume.
You can calculate how many calories you burn per day based on different types of activities.
To be safe, you can calculate your basal metabolic rate (BMR) which is how many calories you burn doing absolutely nothing and just doing the bare minimum to live (breathe, etc).
For me, my BMR is 1818 calories / day.
You can find nutrition facts for a wide variety of food at https://www.nutritionix.com
Total daily calorie consumption: 818
Net daily calorie gain/loss: 818-1818 = -1000 calories (-1/3 lb)
Posted on May 1, 2019
Posted on Apr 23, 2019
Place these large 9-1/2″ x 5-3/4″ sliders under your furniture and easily slide your furniture over carpet.
$10 for a pack of 4 sliders on Amazon
Posted on Apr 22, 2019
Posted on Mar 28, 2019
Lead-based paint and lead contaminated dust are the most hazardous sources of lead for U.S. children. Lead-based paints were banned for use in housing in 1978. All houses built before 1978 are likely to contain some lead-based paint. However, it is the deterioration of this paint that causes a problem.
If possible, buy a house built after 1978 to avoid lead paint.
Plaster walls were used to finish interior houses up until the 1950s at which time it was replaced with drywall. Plaster walls are like stucco. Since they are hard, cutting and drilling a hole for, say, hanging a picture is difficult.
If possible, buy a house after the 1950s to avoid having to deal with plaster walls.
Avoid Old Wiring Systems
Old homes used knob and tube wiring till around 1920. After that, flexible cables were used till the 1940s. After that, cables were run through metal conduit till around 1965. Around 1965, homes began using modern NM cable commonly called Romex.
If possible, buy a house after 1965 to avoid having to deal with old wiring systems.
Roofs are one of the most expensive parts of a house. Replacing the shingles on a roof can cost around $10,000. Shingle roofs commonly have a lifespan of 25 years.
If possible, find out when the roof was installed to determine whether the roof will need replacing soon or not.