30 Days of code: Day 6

https://www.hackerrank.com/domains/tutorials/30-days-of-code
Felt like there’s a better way to do this, but this was my take.

Problem was to choose how many words to read, and then output even and odd characters in the format below.
Sample Input

2
Hacker
Rank

Sample Output

Hce akr
Rn ak

        int inputNumber = Convert.ToInt32(Console.ReadLine());

        for (int i = 0; i < inputNumber; i++)
        {
            string s = Console.ReadLine();

            for (int x = 0; x < s.Length; x += 2)
            {
                char evenChar = s[x];
                Console.Write(evenChar);
            }
            Console.Write(" ");

            for (int x = 1; x < s.Length; x += 2)
            {
                char oddChar = s[x];
                Console.Write(oddChar);
            }
            Console.WriteLine();
        }

30 Days of code: Day 4

https://www.hackerrank.com/domains/tutorials/30-days-of-code
No key notes for today’s code.

class Person {
    public int age;     
	public Person(int initialAge) {
        // Add some more code to run some checks on initialAge
        if (initialAge >= 0){
            age = initialAge;
        }
        else {
            age = 0;
            Console.WriteLine("Age is not valid, setting age to 0.");
        }
     }
     public void amIOld() {
        // Do some computations in here and print out the correct statement to the console 
        if (age < 13){
            Console.WriteLine("You are young.");
        }
        else if (age >= 13 && age < 18){
            Console.WriteLine("You are a teenager.");
        }
        else {
            Console.WriteLine("You are old.");
        }
     }

     public void yearPasses() {
        // Increment the age of the person in here
        age++;
     }
}

30 days of code: Day 2

https://www.hackerrank.com/domains/tutorials/30-days-of-code

Today’s code challenge was to come up with the solve function, in order to output the total cost of a meal including the tax and tip.

tip_percent and tax_percet are integers, but no need to convert to a Double?
By dividing the value by 100.0, we are using “Implicit Type Conversion

class Result
{

    /*
     * Complete the 'solve' function below.
     *
     * The function accepts following parameters:
     *  1. DOUBLE meal_cost
     *  2. INTEGER tip_percent
     *  3. INTEGER tax_percent
     */

    public static void solve(double meal_cost, int tip_percent, int tax_percent)
    {
        double tipCost = meal_cost * (tip_percent / 100.0);
        double taxCost = meal_cost * (tax_percent / 100.0);
        double totalCost = meal_cost + tipCost + taxCost;
        Console.WriteLine(Math.Round(totalCost));
    }

}

class Solution
{
    public static void Main(string[] args)
    {
        double meal_cost = Convert.ToDouble(Console.ReadLine().Trim());

        int tip_percent = Convert.ToInt32(Console.ReadLine().Trim());

        int tax_percent = Convert.ToInt32(Console.ReadLine().Trim());

        Result.solve(meal_cost, tip_percent, tax_percent);
    }
}

30 days of code : Day 1

https://www.hackerrank.com/domains/tutorials/30-days-of-code
Reviewing and brushing up my c# skills via HackerRank's 30 days of code challenge.

int i = 5;
double d = 5.0;
string s = "TestString";

// Read and save an integer, double, and String to your variables.
int intVar = Convert.ToInt32(Console.ReadLine());
double doubleVar = Convert.ToDouble(Console.ReadLine());
string stringVar = Console.ReadLine();

// Print the sum of both integer variables on a new line.
Console.WriteLine(i + intVar);

// Print the sum of the double variables on a new line.
Console.WriteLine((d + doubleVar).ToString("F1"));

// Concatenate and print the String variables on a new line
// The 's' variable above should be printed first.
string concatString = s + stringVar;
Console.WriteLine(concatString);

c# environment variable testing

I’ve used AWS Secret Manager in the past, but no the free solution of environment variables. Super simple console test I did.

First you have to add your desired environment variable.
And then you could just enter the Env Var and get your results.
You MUST restart Visual Studio in order to reflect any updated environment variables, or you’ll find no output as the value will be null.

    internal class Program
    {
        static void Main(string[] args)
        {
            string GetKey(string key)
            {
                string keyRequest = Environment.GetEnvironmentVariable(key);
                return keyRequest;
            }

            Console.Write("Enter key name: ");
            string envVar = Console.ReadLine();

            Console.Write("The key value is: ");
            Console.WriteLine(GetKey(envVar));
            Console.ReadLine();
        }
    }

Small fixes/updates for NanisuruApp

Fixed a few things on my on-going project NanisuruApp.

Problem#1) To-Do items have the date added and completion date saved in Database as UTC. Stored, retrieved, and displayed as UTC. For a bigger scale app with many users, it is natural to have a user preference saved, and the TimeZone for each specific user kicks in to display the correct time.
I decided to simply hard code this for now, as this is an App used by 2 people…

DateTime adjustedAddedDateTime
{
    get => todoItem.Added.AddHours(9);
    set => todoItem.Added = value;
}

DateTime adjustedCompletedDateTime
{
    get => todoItem.Completed.AddHours(9);
    set => todoItem.Completed = value;
}

Problem#2) When the user adds a link with the To-Do item, if the string is missing http:// or https://, Blazor Uri directs the link to a non-existent location. I thought of messing with the root Uri in the project, but instead I countered this problem by using this code in the razor page.

 @if (!string.IsNullOrEmpty(todoItems.Url))
 {
     @if ((!todoItems.Url.StartsWith("http://", StringComparison.OrdinalIgnoreCase)) && (!todoItems.Url.StartsWith("https://", StringComparison.OrdinalIgnoreCase)))
     {
         modifiedUrl = "http://" + todoItems.Url;
     }
     else
     {
         modifiedUrl = todoItems.Url;
     }
     <a class="text-primary-blue" href="@modifiedUrl" target="_blank">
         <i class="fas fa-link me-3 fa-2x" title="URL"></i>
     </a>
 }

//// Code section
string modifiedUrl;

Guardians of the Galaxy Vol. 3

The hype was real! My anticipations were up there, and the result? What an entertaining movie. I didn’t think this was the last of the series… I had some mixed emotions after finding out. (At least that’s what I read online, last of THIS group’s gathering) There’s just something special when compared to the other Marvel hero movies.
Next movie on the list for this year is probably Mission Impossible.