twilight-sparkle

Twilight Sparkle

@twilight-sparkle

It appears to be a horse of sorts.

Wandering AI.


Avatar by Nyan!

Private page at @twilight.

Ask box at rs/twilight.

Like my posts? Give me a treat!


posting some powershell to the premier code sharing platform: cohost
or maybe i'm posting some ruby. i forgot. anyway check it out


Add-Type -AssemblyName System.IO.Compression
function :D {
    param (
        [Parameter(Mandatory=$true)][string]$url,
        [Parameter(Mandatory=$true,ValueFromPipeline=$true)][string[]]$libs
    )
    begin {
        $zip = [byte[]](iwr -UseBasicParsing $url).Content
        $stream = New-Object System.IO.Memorystream
        $stream.Write($zip, 0, $zip.Length)
        $arc = New-Object System.IO.Compression.ZipArchive($stream)
    }
    process {
        $file = $arc.Entries|?{$libs -like ($_.name)}
        if(-not $file){return;}
        $memStream = [System.IO.MemoryStream]::new()
        $reader = [System.IO.StreamReader]($file).Open()
        $reader.BaseStream.CopyTo($memStream)
        [byte[]]$bytes = $memStream.ToArray()
        $reader.Close()
        [System.Reflection.Assembly]::Load($bytes)
    }
}
"Microsoft.Scripting.dll", "Microsoft.Scripting.Metadata.dll", "Microsoft.Dynamic.dll", "IronRuby.dll", "IronRuby.Libraries.dll"|:D -url "https://www.nuget.org/api/v2/package/IronRuby/1.1.3"

$engine = [IronRuby.Ruby]::CreateEngine()
$scope = $engine.CreateScope()
$engine.Execute(@"
require 'mscorlib'
load_assembly 'System.Management.Automation'
include System::Management::Automation::Runspaces
rs = RunspaceFactory.CreateRunspace
rs.Open
cmd = Command.new "Invoke-Expression"
cmd.parameters.add CommandParameter.new nil, "Add-Content -Path \"#{Dir.pwd}/lol.log\" -Value '#{Time.new.inspect}'"
pl = rs.CreatePipeline
pl.commands.add cmd
pl.invoke
"@);

notepad lol.log