Skip to content

Instantly share code, notes, and snippets.

@FSharpCSharp
FSharpCSharp / Start-ExternalProcess.ps1
Created July 9, 2025 06:23
This script demonstrates how to execute an external program with arguments in PowerShell. It allows you to choose between inline execution and using Start-Process, and displays the exact command before running it.
<#
.SYNOPSIS
Example script to execute a program with arguments in PowerShell, supporting both inline call and Start-Process.
.DESCRIPTION
This script demonstrates how to build an argument array for a program call and execute it either inline or via Start-Process.
The execution method can be controlled using the -UseInline script parameter.
The script also displays the exact command as it will be executed.
.PARAMETER UseInline
@FSharpCSharp
FSharpCSharp / DownloadFileWithSpeedAndEstimatedTime.md
Created November 16, 2023 13:52
Calculating Download Speed and Estimated Remaining Time in C#

Calculating Download Speed and Estimated Remaining Time in C#

To calculate the download speed and the estimated remaining time of the download, you can follow these steps:

  1. Save the start time: Save the time when the download starts. This can be achieved with DateTime startTime = DateTime.Now;.

  2. Save the current download position: During the download, save the current download position. You can do this by saving the number of bytes already downloaded.

  3. Calculate download speed: The download speed can be calculated by dividing the number of downloaded bytes by the elapsed time since the start of the download. This can be achieved with double speed = downloadedBytes / (DateTime.Now - startTime).TotalSeconds;.

@FSharpCSharp
FSharpCSharp / Create-Repo.sh
Created April 7, 2020 07:46
Create Git Repository from Branch
# Create the new-repo in github.
# cd to your local copy of the old repo you want to extract from, which is set up to track the new-project branch that will become the new-repo's master.
# new-project = source branch
# master = destination branch
git push https://github.com/accountname/new-repo.git +new-project:master
@FSharpCSharp
FSharpCSharp / import files from other git repo.sh
Last active November 19, 2020 13:20 — forked from whistler/import.sh
Copy files to another repository while saving git history
# copied from http://gbayer.com/development/moving-files-from-one-git-repository-to-another-preserving-history/
git clone <git repository A url> # clone source repository
cd <git repository A directory>
git remote rm origin # to make sure it doesn't affect the original repository
git filter-branch --subdirectory-filter <directory 1> -- --all # remove all files other than the ones needed
mkdir <directory 1> # move them into another directory where they will be stored in the destination repository (if needed)
mv * <directory 1>
git add .
git commit
@FSharpCSharp
FSharpCSharp / SplitStringWithEscapeCharacter.cs
Created March 6, 2019 14:04
C# String.Split with Escape Character
public static IEnumerable<string> Split(string text, char separator, char escapeCharacter, bool removeEmptyEntries)
{
var buffer = string.Empty;
var escape = false;
var split = new System.Collections.Generic.List<string>();
foreach (var c in text)
if (!escape && c == separator)
{
if (!removeEmptyEntries || buffer.Length > 0) split.Add(buffer);