npm live-server security/policy error

If you’re setting up your development environment on your windows machine for the first time, you may encounter the same security policy issue I bumped into. ( PSSecurityException )

The lazy way to remedy the issue:
run this command in power shell.

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

Javascript開発中にブラウザーを毎回F5でリフレッシュしてコードのアップデートをするのが面倒ということで、npmのlive-serverを使うことに。
Windowsユーザーならたぶんみんなが当たるポリシーエラー。

簡単な解決方法は上記のコマンドをPowerShellで実行するのみ。
詳細なもっとセキュリティを考慮した設定についてはMicrosoftの公式ドキュメントの参照を推奨。


Visual Studio + ReSharper private modifier

When writing in c#, I’m used to not writing the private modifier for anything.
But for some reason when using ReSharper with Unity, the default settings recommends using private. I found this annoying as microsoft suggests not writing private, due to anything being private should be the default.
I was going going through stackoverflow, and read comments about readability and clarity by adding the private, but for me I think it makes things more clutered and harder to read..
Also probably depends on what you were used to when starting off coding?

Anyways, let’s disable the private being added automatically.

1.) Extensions -> ReSharper -> Options…
2.) Category: Code Editing -> Modifiers
Prefer explicit/implicit private modifier for type members -> Implicit

Web app(bShare) progress (asp.net mvc) part 4

I completed my bShare web app. I should say nearly done, just need to go over each code again to do some cleaning or maybe even optimizing without breaking anything. Features are there, the web app is live and running (privately).

Updated ReadMe on github, going to take a day or two off while I plan on my next project, which should be way more challenging. Thinking of a private chat app using Blazor webassembly with SignalR and Asp.net backend API.

bShare github link

Web app(bShare) progress (asp.net mvc) part 3

I’m almost done with my file share web app project.
Still need to finalize some UI elements, and go over my code to do some cleaning up where I can. Progress from the prototype looking UI, to a little bit better one on the right.
My takeaway from this project so far is that to work with placeholder UI elements if the code behind is not completed yet.
You may add new features, or think of different ways to represent data. In this case, some of the work you have put in on the frontend side may become a waste.

Web app(bShare) progress (asp.net mvc) part 2

My app bShare is nearly complete for the coding side.
This is a temporary file upload web app. User can choose to have files removed after 12, 24, or 48 hours. Quick and easy way to share files in case someone doesn’t use any cloud storage platforms such as dropbox, google drive, etc.

Main features are functioning. I need to touch up the UI, and do some testing.
And then for the first time, I must work on the documentation/wiki. I doubt anyone would be using this template, but documentation is good for code review and building your skills on explaining your code? Or at least I believe so.

Almost forgot, before going on to the documentation, I need to work on the automation of MySQL database deletion based on datetime value, and configure a task schedule on Windows Server to remove expired/old files from the system.

Web app(bShare) progress (asp.net mvc) part 1

Steady progress on my mini web app BShare. My Goal is to finish this by the end of the month. I am stuck troubleshooting routing of view access towards random generated shortlinks.

http://site.com/link/{string}
The controller checks the database if the string exists, and if it exists, it will return the view with the same url. It’s good to take a few hours off, or continue the next day for a fresh clear mind.
This is usually the same with music production. But in case of music production, your ears need to take a break so it’s almost mandatory to wait until the next day to notice the slightest sound differences.

ShortLink Generator (random gen)

My current coding project is a temporary file store/share web app.
Now days everyone uses free coud services such as dropbox, google drive, and many others, but I remember the days where temp upload and share sites were a thing.
I still think it’s convenient for those that don’t use any cloud storage.
SO, one of the important functions is the shortlink generator. The link you share with your friends to access the temporary file you’ve uploaded.
Here’s the simple c# code I will be using.

The short link will be generated, and from there through DbContext, the app will make sure that the short link is in fact unique. If !unique, re-generate and check again. I highly doubt the app would have to re-generate though… But you always plan for the worst right.

static void Main(string[] args)
{
    // START OF MAIN /////////////////////


    Console.WriteLine(ShortLinkGenerator(6));


    // END OF MAIN /////////////////////
}

public static string ShortLinkGenerator(int length)
{
    Random random = new Random();
    const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz12345679";
    return new string(Enumerable.Repeat(chars, length).Select(s => s[random.Next(s.Length)]).ToArray());
}

Chrome, allowing localhost bad ssl cert

I recently rebuilt my comptuer with a fresh install of Windows. I’ve lost many small custom configs here and there. Including the one for Chrome where you can allow bad ssl certs to be loaded.
You need this to test out your apps via localhost using Chrome.

Solution, on image below. This is something you don’t do often, I’m pretty sure I’ll be looking this up again in a few years lol. Now i’ll just search my own blog for this.

Asp.net core, system environment variables

I started working on a new small project. I took some time in reading about my option on storing environment variables. (For like the 10th time..)
I am using AWS’s Secrets Manager for my NanisuruApp, but this time around I decided to simply utilize the System Environment Variables on Windows.

Steps taken (Asp.net Core 6.x+)
1.) Added my custom prefix to use.
builder.Configuration.AddEnvironmentVariables(prefix: “CustomPrefix_”);

example environtment variable:
CustomPrefix_DevConnectionString = value

2.) Created 2 profile in launchSettings.json for a “Development” and “Production” profile.
“ASPNETCORE_ENVIRONMENT”: “Production” and copy and paste for Development

3.) Create a cooresponding appsettings file for both Development and Production.
appsettings.Development.json
appsettings.Production.json

something like this (appsettings.Development.Json)

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*",
  "DevConnectionString": "connection"
}

4.) Then I did a sloppy job at loading different connection info based on the project’s environment.

(Program.cs)

// Enable custom environment variables.
builder.Configuration.AddEnvironmentVariables(prefix: "CustomPrefix_");

// Store database connection string
string? connectionString = null;

// Create environment variable to check dev/prod/staging status
IHostEnvironment currentEnvironment = builder.Environment;

// Load different database connection string depending on dev or prod environment
if (currentEnvironment.IsDevelopment())
{
    connectionString = builder.Configuration.GetValue<string>("DevConnectionString");
}
else if (currentEnvironment.IsProduction())
{
    connectionString = builder.Configuration.GetValue<string>("ProdConnectionString");
}

Something important. After adding/editing system environment variables, make sure to restart Visual Studio. These variables are only loaded during launch of the editor.

Doing another fundamental c# run

Touching up on the fundamentals of c# again by going over a few courses that I bought on Udemy, but never got around. Quick and dirty Tic Tac Toe, bare minimum functional.

internal class Board
{
    string[,] _board;
    bool _isPlayer1 = true;
    string _playerName = "Player1";
    string _playerTic = "O";
    string _playerSymbol;
    

    public char Selection { get; set; }

    public string[,] GameBoard
    {
        get => _board;
        set => _board = value;
    }

    public Board()
    {
        _board = new string[,]        
        {
            { "1", "2", "3" },
            { "4", "5", "6" },
            { "7", "8", "9" }
        };
    }

    public void Run()
    {
        Console.WriteLine("Welcome to your tic tac toe game.");
        for (int i = 0; i < GameBoard.GetLength(0); i++)
        {
            for (int j = 0; j < GameBoard.GetLength(1); j++)
            {
                Console.Write("_" + GameBoard[i, j] + "_|");
            }
            Console.WriteLine("");
        }
    }

    public void ShowBoard()
    {
        for (int i = 0; i < GameBoard.GetLength(0); i++)
        {
            for (int j = 0; j < GameBoard.GetLength(1); j++)
            {
                Console.Write("_" + GameBoard[i, j] + "_|");
            }
            Console.WriteLine("");
        }
    }

    public void Start()
    {
        Console.WriteLine($"{_playerName}: It's your turn (enter #): ");
        Selection = Console.ReadKey().KeyChar;
        Console.WriteLine("_____________________");
        Console.WriteLine();
        Console.WriteLine();
        Select();

    }

    public void Select()
    {
        for (int i = 0; i < GameBoard.GetLength(0); i++)
        {
            for (int j = 0; j < GameBoard.GetLength(1); j++)
            {
                if (GameBoard[i, j] == Selection.ToString())
                {
                    GameBoard[i, j] = _playerTic;
                }
            }
        }

        WinCheck();
        ShowBoard();

        _isPlayer1 = !_isPlayer1;

        if (!_isPlayer1)
        {
            _playerName = "Player2";
            _playerTic = "X";
        }
        else
        {
            _playerName = "Player1";
            _playerTic = "O";
        }
        
        Start();
    }

    public void WinCheck()
    {
        _playerSymbol = _isPlayer1 ? "O" : "X";

        if (GameBoard[0, 0] == _playerSymbol && GameBoard[0, 1] == _playerSymbol &&
            GameBoard[0, 2] == _playerSymbol ||
            GameBoard[1, 0] == _playerSymbol && GameBoard[1, 1] == _playerSymbol &&
            GameBoard[1, 2] == _playerSymbol ||
            GameBoard[2, 0] == _playerSymbol && GameBoard[2, 1] == _playerSymbol &&
            GameBoard[2, 2] == _playerSymbol ||

            GameBoard[0, 0] == _playerSymbol && GameBoard[1, 0] == _playerSymbol &&
            GameBoard[2, 0] == _playerSymbol ||
            GameBoard[0, 1] == _playerSymbol && GameBoard[1, 1] == _playerSymbol &&
            GameBoard[2, 1] == _playerSymbol ||
            GameBoard[2, 0] == _playerSymbol && GameBoard[1, 2] == _playerSymbol &&
            GameBoard[2, 2] == _playerSymbol ||

            GameBoard[0, 0] == _playerSymbol && GameBoard[1, 1] == _playerSymbol &&
            GameBoard[2, 2] == _playerSymbol ||
            GameBoard[0, 2] == _playerSymbol && GameBoard[1, 1] == _playerSymbol &&
            GameBoard[2, 0] == _playerSymbol)
        {
            if (_isPlayer1)
            {
                Console.WriteLine("=============");
                Console.WriteLine("Player1 Wins!");
                Console.WriteLine("=============");
                Environment.Exit(0);
            }
            else
            {
                Console.WriteLine("=============");
                Console.WriteLine("Player2 Wins!");
                Console.WriteLine("=============");
                Environment.Exit(0);
            }
        }
    }
}