Default Apache on Heroku Redirects From https to http for Links Without Trailing Slash

I recently set up a Heroku app using the Apache and PHP buildpack. The Apache configuration on Heroku was most likely the default which, if it receives a request to a URL without a trailing slash, e.g.

http://www.foobar.com/about

it’ll redirect to

http://www.foobar.com/about

That alone is fine. However, I was getting redirected from https to http, which was not fine. This is likely due to the presence of a load balancer in front of the Heroku app server with SSL/TLS being terminated at the load balancer. When a request to an https URL without a trailing slash like

https://www.foobar.com/about

the request was secure to the Heroku load balancer but from the load balancer to the Heroku app server, it must have been insecure, e.g.

http://www.foobar.com/about

At that point, Apache would redirect to

http://www.foobar.com/about

and the user would end up going from https to http. To resolve this, and as a best practice, just force https on all URLs. This is easily done on Heroku using a .htaccess file with a redirect rule, in case your chosen server is Apache.

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,

https://nodejs.org/api/fs.html#fs_fs_readfile_path_options_callback

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.

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

If you want to make your location markers stand out more, you can change their color and icon, e.g. from default blue to red.

To show routes, click the “Add directions button and then add an address for each location.

Or, click on the Draw a Line button and choose “Add driving route”.

You can then drag the blue route line to follow the paths or roads you want.

To add a picture to each location, click the camera icon. You can upload or add one or more pictures by URL from Google Images.

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.

https://www.calculator.net/calorie-calculator.html

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 https://www.nutritionix.com

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

Ingredients:
  • 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.
Directions:
  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