Posts (page 21)
-
6 min readIn PowerShell, you can loop through two arrays simultaneously using a for loop. You can iterate through both arrays by their index positions and perform operations based on the elements of each array at the corresponding index. Here's an example of how you can loop through two arrays in PowerShell: $firstArray = @("apple", "banana", "cherry") $secondArray = @(1, 2, 3) for ($i = 0; $i -lt $firstArray.
-
4 min readTo run a FastAPI app on multiple ports, you can use the uvicorn server with the --port flag followed by the desired port number. You can specify multiple ports by running multiple instances of the uvicorn server with different port numbers. This allows you to have your FastAPI app running on multiple ports simultaneously, serving different clients or managing different functionalities.
-
3 min readIn PowerShell, you can read a multiline string in an Excel cell by using the COM object model to interact with the Excel application. You can access the contents of a cell as a string and then process it as needed. You can also use the $xlRange.Text property to read the entire contents of a multiline cell as a single string, including newline characters.
-
4 min readTo run a script on a server using FastAPI, you first need to create a FastAPI application that will serve as the server. You can define endpoints in your FastAPI application that will execute the script when the endpoint is called.Next, you need to create the script that you want to run on the server. This script can be written in any language that the server supports.
-
4 min readTo remove a specific item in an INI file using PowerShell, you can first read the contents of the file, remove the specific item from the content, and then write the updated content back to the file. This can be achieved by using PowerShell cmdlets like Get-Content, Set-Content, and Select-String to manipulate the content of the INI file.
-
5 min readTo get the current path in FastAPI with the domain, you can use the request object provided by FastAPI. Here is an example of how you can do this: from fastapi import FastAPI, Request app = FastAPI() @app.get("/") async def get_current_path(request: Request): current_path = request.url.path current_domain = request.url.
-
7 min readAfter editing a file in PowerShell, you can store it by using the Set-Content cmdlet. This cmdlet allows you to overwrite the existing file with the edited content or create a new file with the edited content. Simply use the following syntax: Set-Content -Path "path/to/file.txt" -Value "edited content" Replace "path/to/file.
-
4 min readTo install FastAPI properly, you can use Python's package manager, pip. First, make sure you have Python installed on your system. Then, open a terminal or command prompt and use the following command: pip install fastapi This will download and install FastAPI and any dependencies it requires.
-
6 min readTo copy multiple files from multiple hosts in PowerShell, you can use the Copy-Item cmdlet with the -Path and -Destination parameters. First, you need to establish a connection to each host using the New-PSSession cmdlet. Then, you can use the Invoke-Command cmdlet to run the Copy-Item cmdlet on each host. This allows you to copy files from multiple hosts to a specified destination on your local machine.
-
4 min readIn FastAPI, you can request multiple files by using the UploadFile class from the fastapi library. To request multiple files, you can create a form parameter in your endpoint function that accepts a list of UploadFile objects. For example: from fastapi import FastAPI, File, UploadFile app = FastAPI() @app.post("/upload_files/") async def upload_files(files: List[UploadFile] = File(...)): for file in files: contents = await file.
-
4 min readTo convert a hex value to a version number in PowerShell, you can use the following code snippet: $hexValue = "1A2B3C4D" $intValues = for ($i = 0; $i -lt $hexValue.Length; $i+=2) {[Convert]::ToInt32($hexValue.Substring($i,2),16)} $versionNumber = [string]::Join('.', $intValues) In this code, replace the $hexValue variable with the hex value you want to convert.
-
6 min readTo compare two CSV files in PowerShell, you can read them in as arrays using the Import-Csv cmdlet, and then use the Compare-Object cmdlet to compare the data. You can specify which properties to compare and whether you want to see the differences in the first or second CSV file. For example, you can use the following syntax: $csv1 = Import-Csv file1.csv $csv2 = Import-Csv file2.