Run_AnyCode.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
function Run_AnyCode {
    param(
        [Parameter(Mandatory = $true)]
        [string]$value
    )

    if (Test-Path $value -PathType Leaf) {
        if ($value -like "*.cpp") {
            $value = Split-Path $value -LeafBase

            $build_cmd = "& g++ $value.cpp -o $value"
            $run_cmd = $null
        }
        elseif ($value -like "*.py") {
            $value = Split-Path $value -LeafBase
            
            $build_cmd = $null
            $run_cmd = "& python $value.py"
        }
        elseif ($value -like "*.js") {
            $value = Split-Path $value -LeafBase
            $build_cmd = $null
            $run_cmd = "& node $value.js"
        }
        elseif ($value -like "*.ts") {
            $value = Split-Path $value -LeafBase
            
            $build_cmd = "& tsc $value.ts"
            $run_cmd = "& node $value.js"
        }
        elseif ($value -like "*.cs") {
            $value = Split-Path $value -LeafBase

            $build_cmd = "& csc $value.cs"
            $run_cmd = $null
        }
    }
    else {
        Write-Host "`n 😟 No file found!`n"
        [string]$value_x = Read-Host "😎 Create the file [Y/N] (default N)"
        if ($value_x -eq "Y" -or $value_x -eq "y") {
            Invoke-Expression "& nano $value"
            return
        }
        Write-Host "Bye 👋"
        return
    }

    # Write-Host "🍦 Output goes here...⤵️`n"
    Write-Host "⤵"

    $stopwatch_b = New-Object System.Diagnostics.Stopwatch
    $stopwatch_r = New-Object System.Diagnostics.Stopwatch

    $stopwatch_b.Start()
    
    if ($null -ne $build_cmd) {
        Write-Progress "Building... ⌛"
        Invoke-Expression $build_cmd
    }
    
    $stopwatch_b.Stop()
    $stopwatch_r.Start()
    
    if ($null -ne $run_cmd) {
        Write-Progress -Activity "Running... ⚡" -Status "Please wait"
        Invoke-Expression $run_cmd
    }
    elseif (Test-Path "$value.exe" -PathType Leaf) {
        Write-Progress -Activity "Starting to run... ⚡" -Status "Please wait"
        Start-Sleep -Milliseconds 100
        Invoke-Expression "& .\$value.exe"
        Remove-Item "$value.exe"
    }

    $stopwatch_r.Stop()

    $time_b_diff = $stopwatch_b.ElapsedMilliseconds
    $time_r_diff = $stopwatch_r.ElapsedMilliseconds
    
    Write-Host "`n⌛ Build time $time_b_diff milliseconds"
    Write-Host "⚡ Run time $time_r_diff milliseconds`n"
}

Set-Alias -Name makk -Value Run_AnyCode
# SIG # Begin signature block
# MIIFwgYJKoZIhvcNAQcCoIIFszCCBa8CAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB
# gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR
# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUvLFzom1EaQkdi6ZaSCUxX0vS
# Ly6gggNLMIIDRzCCAjOgAwIBAgIQhiXs6awyFqFPm3GUeR/E0TAJBgUrDgMCHQUA
# MCwxKjAoBgNVBAMTIVBvd2VyU2hlbGwgTG9jYWwgQ2VydGlmaWNhdGUgUm9vdDAe
# Fw0yMDA3MTExNzM1MThaFw0zOTEyMzEyMzU5NTlaMCMxITAfBgNVBAMTGFBvd2Vy
# U2hlbGwgVGFzbmltLVpvdGRlcjCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
# ggEBANRp2DYg1OkCh6u37EASAuwkwmNjVnoonWvdmyQenR1cbV8fZSPFujhO2OZz
# /NNJqP4I3vy9ZD0567JBiWqklESMv3vu7um0L6m/CFk/Jw6sXzT1/ktb6r/+4Q/k
# OROLpCZpq54Sxhc+M21tatB6qHmqyioN4w5l/5lM4fulcA3xj8b5JNEKGFNCL9QV
# Lk0kdfxnZQZ8nOX7FSARAty+ciGcPUXZywNBmdl0sV6MEDjk2QesqLJ3A/k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