Showing posts with label Others. Show all posts
Showing posts with label Others. Show all posts

Wednesday, September 9, 2020

Track your stock portfolio with Google Sheets

Recently I was learning about Google Sheets and came across "GOOGLEFINANCE" function. It is helpful to track your stock portfolio. This function helps us to get the real-time stock price and real time currency conversion rate.

Example:

Get real time google stock price =GOOGLEFINANCE("NASDAQ:GOOGL","price")

NASDAQ: This is the stock exchange name where company share listed

GOOGL: This is the name of google stock name

Price: It will give us the real time price of stock

Get real time currency conversion rate = GOOGLEFINANCE("CURRENCY:USDGBP")

This will give the “CURRENCY” conversion rate “USDGBP” USD to GBP. In same way you can use the function in Google Sheet based on your requirement.


With help of "GOOGLEFINANCE" function. I have created google sheet template to track stock portfolio. You can download this template and put your stocks details there hope it will help you track your stocks. 

You can download template from below link 

Make your template copy

Tuesday, June 25, 2019

Two location within radius

Some time we need to identify one location latitude and longitude with the radius of other  location. How to check is the location in the radius of other location?



I will show you how we can do with help of Google map Api.
    class Coordinate
    {
        public double Latitude { get; set; }
        public double Longitude { get; set; }
    }
    class Program
    {
        public static void Main()
        {
            //Get center location lat and lng
            Coordinate centerLatLong = GetLatLongForAddress("Delhi");
            //Get any location lat and lng
            Coordinate locationLatLong = GetLatLongForAddress("Noida");
            //Radius: Radius in meter
            int radius = 50000;
            //Check wheater  locations lat and long within  radius of a given  point.
            bool check = isInArea(centerLatLong, locationLatLong, radius);
            Console.Write(check);
         
            Console.ReadLine();
        }
        public static Coordinate GetLatLongForAddress(string location)
        {
            string result = string.Format("http://maps.googleapis.com/maps/api/geocode/xml?address={0}&sensor=true", location);
            Coordinate coordinate = new Coordinate();
            byte[] data;
            using (WebClient webClient = new WebClient())
                data = webClient.DownloadData(result);
            string str = Encoding.GetEncoding("Windows-1252").GetString(data);
            XDocument doc = XDocument.Parse(str);
            string status = doc.Element("GeocodeResponse").Element("status").Value;
            //no errors occurred; the address was successfully parsed and at least one geocode was returned.
            if (status.Equals("OK"))
            {
                var point = doc.Element("GeocodeResponse").Element("result").Element("geometry").Element("location");
                string lat = point.Element("lat").Value;
                string lng = point.Element("lng").Value;
                coordinate.Latitude = Convert.ToDouble(lat);
                coordinate.Longitude = Convert.ToDouble(lng);
            }
            else if (status.Equals("ZERO_RESULTS"))
            {
                //Geocode was successful but returned no results
                throw new ApplicationException("No maps found for this address");
            }
            else if (status.Equals("REQUEST_DENIED"))
            {
                //Request was denied
                throw new ApplicationException("Request Denied");
            }
            else if (status.Equals("INVALID_REQUEST"))
            {
                //Address is missing
                throw new ApplicationException("Address not found");
            }
            else if (status.Equals("UNKNOWN_ERROR"))
            {
                //The request could not be processed due to a server error
                throw new ApplicationException("Unknown Error. Try agian.");
            }
            return coordinate;
        }
        public static bool isInArea(Coordinate centerLatLong, Coordinate locationLatLong, int radius)
        {
            var R = 6371;
            var dLat = (centerLatLong.Latitude - locationLatLong.Latitude) * Math.PI / 180;
            var dLon = (centerLatLong.Longitude - locationLatLong.Longitude) * Math.PI / 180;
            var a = Math.Sin(dLat / 2) * Math.Sin(dLat / 2) +
            Math.Cos(locationLatLong.Latitude * Math.PI / 180) * Math.Cos(centerLatLong.Latitude * Math.PI / 180) *
            Math.Sin(dLon / 2) * Math.Sin(dLon / 2);
            var c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a));
            var d = R * c;
            return (d * 1000 <= radius);
        }
    }

Copied files and folder by DOS

If you want to copy files and foldes from one location to other location by just on one click.
You can make it with as simple .bat file in DOS.
Just copy the below code on notepad and  save it copyfolder.bat.


@echo off
:: variables
set SourceFolder=D:\Source
set TargetFolder=D:\Target
set FolderWithDate=%date:~10,4%_%date:~4,2%_%date:~7,2%
set backupcmd=xcopy /s /c /d /e /h /i /r /k /y
pause
echo ### Backing up source directory...
%backupcmd% "%SourceFolder%" "%TargetFolder%\%FolderWithDate%"
echo ## Backup Complete!
@pause



Once you copy the above code in notepad. you can change below things
Your  source folder which need to be copy: D:\Source
Your target folder where you want to copy it: D:\Target

I hope it will help  you. Thanks

Thursday, June 6, 2019

Carry On

It’s easy to fight when everything’s right,
And you’re mad with the thrill and the glory;
It’s easy to cheer when victory’s near,
And wallow in fields that are gory.
It’s a different song when everything’s wrong,
When you’re feeling infernally mortal;
When it’s ten against one, and hope there is none,
Buck up, little soldier, and chortle:

Carry on! Carry on!
There isn’t much punch in your blow.
You’re glaring and staring and hitting out blind;
You’re muddy and bloody, but never you mind.
Carry on! Carry on!
You haven’t the ghost of a show.
It’s looking like death, but while you’ve a breath,
Carry on, my son! Carry on!

And so in the strife of the battle of life
It’s easy to fight when you’re winning;
It’s easy to slave, and starve and be brave,
When the dawn of success is beginning.
But the man who can meet despair and defeat
With a cheer, there’s the man of God’s choosing;
The man who can fight to Heaven’s own height
Is the man who can fight when he’s losing.

Carry on! Carry on!
Things never were looming so black.
But show that you haven’t a cowardly streak,
And though you’re unlucky you never are weak.
Carry on! Carry on!
Brace up for another attack.
It’s looking like hell, but — you never can tell:
Carry on, old man! Carry on!

There are some who drift out in the deserts of doubt,
And some who in brutishness wallow;
There are others, I know, who in piety go
Because of a Heaven to follow.
But to labour with zest, and to give of your best,
For the sweetness and joy of the giving;
To help folks along with a hand and a song;
Why, there’s the real sunshine of living.

Carry on! Carry on!
Fight the good fight and true;
Believe in your mission, greet life with a cheer;
There’s big work to do, and that’s why you are here.
Carry on! Carry on!
Let the world be the better for you;
And at last when you die, let this be your cry:
Carry on, my soul! Carry on!


Robert Service
British-Canadian poet