Category: Development

  • Can a Git repository contain multiple .gitignore files in the root folder?

    No, a Git repository should only have one .gitignore file in the root folder. The .gitignore file in the root directory of your repository is meant to apply its rules to the entire repository. However, you can have multiple .gitignore files within different subdirectories of your repository, each applying only to the directory in which it is located and its subdirectories. This allows you to have specific ignore rules for different parts of your project.

    For example:

    • / (root directory)
      • .gitignore
      • /src
        • .gitignore
      • /docs
        • .gitignore

    Each .gitignore file can contain rules relevant to the files and directories at its level and below.

  • Resolving the Missing File Explorer Issue in VS Code

    The File Explorer in VS Code is a crucial feature that allows you to navigate through your files and directories effortlessly. However, due to reasons like unintended user actions, a glitch in the software, or a misbehaving extension, the File Explorer can sometimes disappear.

    The Solution: ‘View: Reset View Locations’

    To restore your missing File Explorer, VS Code provides a simple and effective command: ‘View: Reset View Locations’. This command resets the layout of the sidebar and panel, bringing back any missing view, including the File Explorer.

    How to Run ‘View: Reset View Locations’

    Here’s a step-by-step guide on how to execute this command:

    1. Open the Command Palette: The Command Palette is a feature in VS Code that allows you to access all available commands. You can open it by pressing Ctrl+Shift+P on Windows and Linux, or Cmd+Shift+P on macOS.

    2. Type the Command: In the Command Palette, start typing ‘View: Reset View Locations’. As you type, VS Code will suggest commands that match your input. Once the ‘View: Reset View Locations’ command appears, click on it or press Enter to execute it.

    3. Check the File Explorer: After running the command, the layout of your VS Code should reset to its default state. This means the File Explorer should now be visible in the sidebar.

  • Reducing HttpClient Logging in C# Application

    If you have an application code written in C# and use HttpClient in the code, you may encounter instances where HttpClient generates a significant amount of logging information, such as:

    • Start processing HTTP request
    • Sending HTTP request
    • Received HTTP response headers after … ms – 200
    • End processing HTTP request after … ms – 200

    These logs can be overwhelming and make it difficult to identify and troubleshoot issues. In this blog post, we’ll show you how to adjust the logging levels for HttpClient to reduce the amount of logging information generated by your application.

    To remove the logging that you’re seeing in your C# code, you can adjust the logging level for the System.Net.Http.HttpClient namespace in your appsettings.json file. By setting the logging level to Warning or higher, you can prevent the Info level logs from appearing.

    Here’s an example of how you can adjust the logging level in your appsettings.json file:

    {
      "Logging": {
        "LogLevel": {
          "Default": "Information",
          "System.Net.Http.HttpClient": "Warning"
        }
      }
    }
    

    In the above example, the logging level for System.Net.Http.HttpClient is set to Warning, which means that only Warning, Error, and Critical level logs will be displayed for that namespace. The Info level logs will no longer appear.

    After making these changes, restart your application for the new logging settings to take effect.

  • Fix the “Ports are not Available” Error in Docker

    You might encounter the error docker: Error response from daemon: Ports are not available: exposing port TCP 0.0.0.0:3000 -> 0.0.0.0:0: listen tcp 0.0.0.0:3000: bind: Only one usage of each socket address (protocol/network address/port) is normally permitted. when running a Docker command locally. This error means that Docker cannot bind to port 3000 on your host because it’s already in use by another application or service. Docker needs this port to be free to assign it to the container you’re trying to run. To resolve this issue, follow these steps:

    1. Find the Process Using Port 3000

    First, you need to identify which application is currently using port 3000. You can do this using the following commands, depending on your operating system:

    • On Linux or macOS:

      sudo lsof -i :3000
      

      or

      sudo netstat -tulnlp | grep :3000
      
    • On Windows:

      netstat -ano | findstr :3000
      

    2. Stop the Process Using Port 3000

    Once you’ve identified the process using port 3000, you can choose to stop it to free up the port. How you stop the process will depend on what the process is. For example, if it’s a web server, you might stop it through its control interface or by terminating the process directly.

    • On Linux or macOS, if the process ID (PID) is, for example, 1234, you can stop it using:

      sudo kill 1234
      

      If the process doesn’t stop, you can force it to stop using:

      sudo kill -9 1234
      
    • On Windows, if you’ve identified the PID and wish to stop it, you can use:

      taskkill /PID 1234 /F
      

    3. Run Your Docker Container Again

    Now that port 3000 is free, try running your Docker container again using the same command that previously resulted in the error.

    4. Consider Using a Different Port

    If you cannot stop the process using port 3000 or you need it to keep running, consider mapping your Docker container to a different port on your host. You can do this by modifying the port mapping argument in your Docker run command. For example, to use port 3001 instead, you might use:

    docker run -p 3001:3000 your_image_name
    

    This command tells Docker to map port 3000 inside the container to port 3001 on your host, effectively bypassing the conflict on port 3000.

  • Automatically Run Specific PowerShell Scripts at the Start of Every PowerShell Session

    To automatically run specific PowerShell scripts at the start of every PowerShell session, you can modify your PowerShell profile file. PowerShell profiles are scripts that run at the start of a new PowerShell session. Here’s how to add an external script to your PowerShell startup:

    1. Find or Create Your PowerShell Profile: First, you need to determine if you already have a profile and where it is. Open PowerShell and run the following command:

      $profile
      

      This command will show the path to your current user’s profile for the PowerShell console. If you want to add the script for all users or for the ISE, you might need a different profile path.

    2. Check if the Profile Exists: Check if the profile already exists by running:

      Test-Path $profile
      

      If this returns False, the profile does not exist, and you’ll need to create it.

    3. Create the Profile if Necessary: If the profile doesn’t exist, you can create it by running:

      New-Item -path $profile -type file -force
      
    4. Edit Your Profile: Open the profile file in a text editor. You can do this from PowerShell as well, for example, using Notepad:

      notepad $profile
      
    5. Add Your Script to the Profile: In the profile file, you can add commands to run at startup. To run an external script, use the following command:

      . C:\path\to\your\script.ps1
      

      Replace C:\path\to\your\script.ps1 with the actual path to your script. The dot sourcing operator (.) before the path ensures that the script runs in the current scope, so any functions or variables it defines will be available in your session.

    6. Save and Close the Profile: After adding your script, save the profile file and close the text editor.

    7. Test Your Profile: Open a new PowerShell window to test if your script runs as expected. If there are any errors in the script, they will show up when you start PowerShell.

    Keep in mind that running scripts from an external source can pose a security risk. Make sure you trust the scripts you’re adding to your PowerShell startup. Additionally, if your system’s execution policy is set to restrict script execution, you may need to adjust it to allow your profile and scripts to run. You can check the current execution policy by running Get-ExecutionPolicy, and set a new policy with Set-ExecutionPolicy, though changing execution policies should be done with understanding the security implications.null

  • Get the count of each column of Kusto Table

    In Kusto Query Language (KQL), you can’t directly get the count of each column in a single command. However, you can get the count of each column one by one using the count() function. Here’s an example:

    datatable | summarize count(Column1), count(Column2), count(Column3)

    Replace ‘datatable’ with your table name and ‘Column1’, ‘Column2’, ‘Column3’ with your column names.

    This will give you the count of non-null values in each of these columns. If you want to include null values in your count, you can use dcount() function instead.

    Please note that this will not provide the count of unique values. If you need count of unique values, you can use dcount() function.

  • Configure import order in a Next.js project

    To configure import order in a Next.js project, you can use ESLint with the “sort-imports” or “import/order” rules from the “eslint-plugin-import” plugin. Here’s how you can set it up:

    Install ESLint and the necessary plugins if you haven’t already

    npm install --save-dev eslint eslint-plugin-import

    Then, create a .eslintrc.json file in your project root if it doesn’t exist already. If it does, you can just add the rules to it. In your .eslintrc.json file, you can add the “import/order” rule like so:

    {
      "plugins": ["import"],
      "rules": {
        "import/order": [
          "error",
          {
            "groups": ["builtin", "external", "internal"],
            "pathGroups": [
              {
                "pattern": "react",
                "group": "external",
                "position": "before"
              }
            ],
            "pathGroupsExcludedImportTypes": ["react"],
            "newlines-between": "always",
            "alphabetize": {
              "order": "asc",
              "caseInsensitive": true
            }
          }
        ]
      }
    }

    This will enforce a specific order to your imports:

    • Built-in modules (like fs and path)
    • External modules (like react and axios)
    • Internal modules (your own project’s modules)


    The “newlines-between”: “always” option will enforce having blank lines between each group.

    The “alphabetize” option will sort the imports alphabetically within each group.

    The “pathGroups” option allows you to customize the position of certain modules within their group. In this case, it’s making sure react always comes before other external modules.

    Then, run ESLint to check your project:

    npx eslint --fix

    This will automatically fix any issues with import order in your project according to the rules you’ve set.




    1. Solving the “/app/.next/standalone not found” Error in Next.js

      While building your Nextjs application within Docker, you may encounter the following error if you’re using the Docker sample from the official Nextjs GitHub site:

      "ERROR: failed to solve: failed to compute cache key: failed to calculate checksum of ref 83cmddfvrmzj1u5evc3q6uxwx::7xxwejdn2kuni31k09czx9kpk: "/app/.next/standalone": not found"

      This blog post offers a straightforward solution to this problem.

      Understanding the Error

      Understanding the Error

      The error message suggests that the system couldn’t compute the cache key as it was unable to calculate the checksum of a specific reference, “/app/.next/standalone”, which it couldn’t find. This error typically arises when Next.js attempts to build your application but can’t locate the specified reference.

      The Solution

      The solution to this error is quite simple. You just need to add a line in your next.config.js file:

      output: 'standalone',

      This code instructs Next.js to output your application as a standalone app, meaning your application will contain all the necessary files and configuration settings to run independently, without relying on external resources.

      Here’s how to do it:

      1. Open your next.config.js file, which is usually located at the root of your project directory.
      2. Add the line output: ‘standalone’, to the configuration object. Ensure that you add this line within the module.exports object.
      3. Save the changes and close the file.
      4. Rebuild your Next.js application.

      Your next.config.js file should look like this after adding the line:

      const nextConfig = {
        // ...other configuration settings...
        output: 'standalone',
        // ...other configuration settings...
      }

      After following these steps, the error should no longer appear when you build your application. Your Next.js app should now build successfully and run as a standalone application.

    2. Resolve Vercel deploy Error: Found invalid Node.js Version: “>=20.9.0”.

      If you’re deploying an application on Vercel and encounter the following error:

      Error: Found invalid Node.js Version: ">=20.9.0". Please set "engines": { "node": "18.x" } in your package.json file to use Node.js 18.

      There’s no need to downgrade your application to Node.js 18. Here’s how you can fix the issue without downgrading:

      1. Navigate to Settings.
      2. Scroll down to the Node.JS Version section. From the dropdown list, select 2.0x.
      3. Click Save.
      4. Return to the failed deployment and click on Redeploy.

      Your new deployment should successfully launch this time.

    3. Solving the Angular Update Error: Conflicting peer dependency

      If you’re struggling to update your Angular version and encounter the following error when executing the command ‘npm install’:

      npm ERR! While resolving: angular-test-app@0.0.0
      npm ERR! Found: @angular-devkit/build-angular@16.2.11
      npm ERR! node_modules/@angular-devkit/build-angular
      npm ERR!   dev @angular-devkit/build-angular@"^17.2.0" from the root project
      npm ERR!
      npm ERR! Could not resolve dependency:
      npm ERR! dev @angular-devkit/build-angular@"^17.2.0" from the root project
      npm ERR!
      npm ERR! Conflicting peer dependency: @angular/compiler-cli@17.2.1
      npm ERR! node_modules/@angular/compiler-cli
      npm ERR!   peer @angular/compiler-cli@"^17.0.0" from @angular-devkit/build-angular@17.2.0
      npm ERR!   node_modules/@angular-devkit/build-angular
      npm ERR!     dev @angular-devkit/build-angular@"^17.2.0" from the root project
      npm ERR!
      npm ERR! Fix the upstream dependency conflict, or retry
      npm ERR! this command with --force or --legacy-peer-deps
      npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

      Here’s a potential solution:

      Delete the ‘node_modules’ folder and the ‘package-lock.json’ file, then reinstall npm. This could resolve your issue.

      To do this, execute the following commands:

      1. Delete ‘node_modules’
      2. Delete ‘package-lock.json’
      3. Run ‘npm install’