Programming


“Mixed content blocked” when running an HTTP AJAX operation on an HTTPS page

Recently, we got a peculiar error on an HTTPS website while making Ajax requests.
Even though the website was full HTTPS, the Ajax request using a relative path was getting the “Mixed content blocked” error message.
To resolve this issue fast (without messing with the Javascript code), we added the following meta tag in the website’s header.

<meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests"> 


How to check if PyTorch is using the GPU?

The following basic code, will import PyTorch into a project and test if GPU capabilities are enabled and available.

import torch

# Should produce "True"
torch.cuda.is_available()

# Should produce the number of available devices, if you have one device it should produce the value "1"
torch.cuda.device_count()

# If there is a device and it is the first one, it should produce the "0"
torch.cuda.current_device()

# Assuming that there is at least one device, with the following two commands we will get some information on the first available device

# Should produce something similar to "<torch.cuda.device object at 0x7f12b1a298d0>"
torch.cuda.device(0)

# Should produce something similar to "'GeForce GTX 1050 Ti'"
torch.cuda.get_device_name(0)

We are using Ubuntu 20.04 LTS and the NVidia drivers were installed automatically during installation.


Quick note on setting up our programming environment for Coursera.org “DeepLearning.AI TensorFlow Developer Professional Certificate” on Ubuntu 18.04LTS

Recently we were working on some local Jupyter notebooks for the “DeepLearning.AI TensorFlow Developer Professional Certificate“.

To prepare for the setup with GPU, we followed the instructions at https://www.tensorflow.org/install/gpu. But as we were going through the notebooks we noticed the following error at the terminal:

W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'libcublas.so.10'; dlerror: libcublas.so.10: cannot open shared object file: No such file or directory

Even though libcublas.so.10 was installed it was not loading. Using find was saw that it was installed and available at the folder /usr/local/cuda-10.2/targets/x86_64-linux/lib/ but it was ignored.

To fix this, we added a new entry in ~/.profile as follows:

if [ -d "/usr/local/cuda-10.2/targets/x86_64-linux/lib/" ]; then
    export LD_LIBRARY_PATH=/usr/local/cuda-10.2/targets/x86_64-linux/lib/:${LD_LIBRARY_PATH}
fi

And then executed source ~/.profile from the terminal which we would start the jupyter-notebook command.

After this, library was loaded as expected.


Safari: ‘a.getTime’ is undefined

Recently, we were working with Google Charts at which we were presenting data from a timeline with some processing.
Our JavaScript code was formatted as follows to create Date objects:

$value = "2020-03-19 23:45:00";
var dateStrFormat = new Date($value);

The above code worked fine on Firefox and Chrome but it failed on Safari with the error:
a.getTime is not a function. (In 'a.getTime()', 'a.getTime' is undefined)
After some investigation we found that Safari does not support a Date() constructor that contains time as well so we had to change the code to the following block:

var dateStr = "2020-03-19";
var dateStrFormat = new Date(dateStr);
var hourStr = "23";
var minutesStr = "45";
dateStrFormat.setHours(hourStr, minutesStr);

The above works on all browsers!