JavaScript Promises

Using Promises

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.

Convert callback to Promises

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.

To create Promises out of ordinary values, use Promise.resolve() and Promise.reject().

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.

Running concurrently

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.

How to Use a Ratchet Strap

Hook both ends of the ratchet strap to something.

Fold the ratchet as shown in the picture below. Then insert the open end of the other strap “through” the ratchet cylinder. Read More

Create a Custom Google Map with Placemarkers

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

Losing Weight By Counting Calories

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.

Calorie Calculator

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.

Weight loss facts
  • You should not lose more than 2 lbs / week.
  • 1 pound (~0.45 kg) of fat = 3500 calories
  • To achieve a 2 lb weight loss per week, you’d need to lose 1000 calories per day.
Nutrition data

You can find nutrition facts for a wide variety of food at

Example calorie calculation
  • Breakfast:
    • Banana Nut Crunch Cereal: 1 cup – 230 calories
    • 2% Reduced Fat Milk: 1 cup – 130 calories
      • Subtotal = 360 calories
  • Lunch: 
    • Something: 177 calories
  • Dinner:
    • Roasted tomatoes: 4 – 88 calories
    • Roasted creamer potatoes: 1 cup – 180 calories
    • Roasted broccoli: 1 spear – 13 calories
      • Subtotal = 281 calories

Total daily calorie consumption: 818
BMR: 1818
Net daily calorie gain/loss: 818-1818 = -1000 calories (-1/3 lb)

Additional Information

Galayet Bandora with Beef Recipe

  • 2 medium size onions,finely sliced.
  • 4 Tablespoons of olive oil.
  • 1 serrano pepper, diced
  • 300gm beef meat (cubes or minced).
  • 3 cups of chopped tomatoes.
  • 1 green bell pepper, finely sliced.
  • Salt and black pepper to taste.
  1. In a heavy skillet like cast iron add olive oil over medium heat.
  2. Add onions and cook them until soft.
  3. Add meat and stir using a wooden spoon tell it is almostly cooked.
  4. Add tomatoes, serrano pepper, and bell pepper let simmer until the tomato mixture begins to reduce,taste and adjust the seasoning to your liking. cover the skillet, and cook on low heat tell completely cooked.
  5. Serve immediately with warm bread

Strongest Epoxy: JB Weld – Original

Here’s an interesting video comparing the bond strengths of various epoxies. Overall, the JB Weld – Original wins the test. Don’t get JB Weld – KwikWeld or ExtremeHeat as they are weak.

Easily Move Furniture and Carry Heavy or Large Objects

Slide Furniture on Carpet
SuperSliders 4724095N

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

Read More

Healthy Yet Tasty Steamed Vegetables Recipe

  • Frozen vegetables (Costco)
  • Salt
  • Pepper
  • Pre-minced garlic in olive oil
  • Water
  1. Add water to a steamer pot half an inch below the surface of the holed steamer tray
  2. Boil until you see steam
  3. Add vegetables and baste on minced garlic
  4. Sprinkle on salt and pepper to taste

Juicy Baked (Roasted) Chicken

  • chicken breast (Costco)
  • oregano flakes
  • smoked paprika
  • garlic powder
  • extra virgin olive oil
  • salt
  • pepper

Read More

House-Buying Tips

Avoid Lead Paint

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.

Avoid Plaster Walls

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.