You are free to use the above codes, but they are provided without any warranty, meaning the author is not responsible for any issues that arise from the use of them. (MIT license)
If you find any issues with the codes, please let me know.
Both poles will be singular points by definition.
I have also derived equations for curvature on the spherical coordinate. If you are interested, please reach out to me (Satoru Okajima).