-
-
Save ajorpheus/bca005db4a633450d651f0c99653018d to your computer and use it in GitHub Desktop.
Temp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add-Type -TypeDefinition @' | |
using System.Runtime.InteropServices; | |
[Guid("5CDF2C82-841E-4546-9722-0CF74078229A"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] | |
interface IAudioEndpointVolume | |
{ | |
// f(), g(), ... are unused COM method slots. Define these if you care | |
int f(); int g(); int h(); int i(); | |
int SetMasterVolumeLevelScalar(float fLevel, System.Guid pguidEventContext); | |
int j(); | |
int GetMasterVolumeLevelScalar(out float pfLevel); | |
int k(); int l(); int m(); int n(); | |
int SetMute([MarshalAs(UnmanagedType.Bool)] bool bMute, System.Guid pguidEventContext); | |
int GetMute(out bool pbMute); | |
} | |
[Guid("D666063F-1587-4E43-81F1-B948E807363F"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] | |
interface IMMDevice | |
{ | |
int Activate(ref System.Guid id, int clsCtx, int activationParams, out IAudioEndpointVolume aev); | |
} | |
[Guid("A95664D2-9614-4F35-A746-DE8DB63617E6"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] | |
interface IMMDeviceEnumerator | |
{ | |
int f(); // Unused | |
int GetDefaultAudioEndpoint(int dataFlow, int role, out IMMDevice endpoint); | |
} | |
[ComImport, Guid("BCDE0395-E52F-467C-8E3D-C4579291692E")] class MMDeviceEnumeratorComObject { } | |
public class Audio | |
{ | |
static IAudioEndpointVolume Vol() | |
{ | |
var enumerator = new MMDeviceEnumeratorComObject() as IMMDeviceEnumerator; | |
IMMDevice dev = null; | |
Marshal.ThrowExceptionForHR(enumerator.GetDefaultAudioEndpoint(/*eRender*/ 0, /*eMultimedia*/ 1, out dev)); | |
IAudioEndpointVolume epv = null; | |
var epvid = typeof(IAudioEndpointVolume).GUID; | |
Marshal.ThrowExceptionForHR(dev.Activate(ref epvid, /*CLSCTX_ALL*/ 23, 0, out epv)); | |
return epv; | |
} | |
public static float Volume | |
{ | |
get { float v = -1; Marshal.ThrowExceptionForHR(Vol().GetMasterVolumeLevelScalar(out v)); return v; } | |
set { Marshal.ThrowExceptionForHR(Vol().SetMasterVolumeLevelScalar(value, System.Guid.Empty)); } | |
} | |
public static bool Mute | |
{ | |
get { bool mute; Marshal.ThrowExceptionForHR(Vol().GetMute(out mute)); return mute; } | |
set { Marshal.ThrowExceptionForHR(Vol().SetMute(value, System.Guid.Empty)); } | |
} | |
} | |
'@ | |
#requires -version 4.0 | |
Function New-GitHubGist { | |
[cmdletbinding(SupportsShouldProcess,DefaultParameterSetName = "Content")] | |
Param( | |
#[Parameter(Position = 0, Mandatory, HelpMessage = "What is the name for your gist?",ValueFromPipelineByPropertyName)] | |
#[ValidateNotNullorEmpty()] | |
[string]$Name, | |
#[Parameter(ParameterSetName="path",Mandatory,ValueFromPipelineByPropertyName)] | |
#[ValidateNotNullorEmpty()] | |
[Alias("pspath")] | |
[string]$Path, | |
#[Parameter(ParameterSetName="Content",Mandatory)] | |
#[ValidateNotNullorEmpty()] | |
[string[]]$Content, | |
[string]$Description, | |
[Alias("token")] | |
#[ValidateNotNullorEmpty()] | |
[string]$UserToken = $gitToken, | |
[switch]$Private, | |
[switch]$Passthru | |
) | |
Begin { | |
Write-Verbose "[BEGIN ] Starting: $($MyInvocation.Mycommand)" | |
#create the header | |
$head = @{ | |
Authorization = 'Bearer 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' | |
} | |
#define API uri | |
$base = "https://api.github.com" | |
} #begin | |
Process { | |
$Name = "temp" | |
$Description = "Temp" | |
$Content = (Get-Clipboard) | |
#display PSBoundparameters formatted nicely for Verbose output | |
[string]$pb = ($PSBoundParameters | Format-Table -AutoSize | Out-String).TrimEnd() | |
Write-Verbose "[PROCESS] PSBoundparameters: `n$($pb.split("`n").Foreach({"$("`t"*2)$_"}) | Out-String) `n" | |
#json section names must be lowercase | |
#format content as a string | |
switch ($pscmdlet.ParameterSetName) { | |
"path" { | |
$gistContent = Get-Content -Path $Path | Out-String | |
} | |
"content" { | |
$gistContent = $Content | Out-String | |
} | |
} #close Switch | |
$data = @{ | |
files = @{$Name = @{content = $gistContent}} | |
description = $Description | |
public = (-Not ($Private -as [boolean])) | |
} | Convertto-Json | |
Write-Verbose ($data| out-string) | |
Write-Verbose "[PROCESS] Posting to $base/gists" | |
If ($pscmdlet.ShouldProcess("$name [$description]")) { | |
#parameters to splat to Invoke-Restmethod | |
$invokeParams = @{ | |
Method = 'Post' | |
Uri = "$base/gists" | |
Headers = $head | |
Body = $data | |
ContentType = 'application/json' | |
} | |
$r = Invoke-Restmethod @invokeParams | |
if ($Passthru) { | |
Write-Verbose "[PROCESS] Writing a result to the pipeline" | |
$r | Select @{Name="Url";Expression = {$_.html_url}}, | |
Description,Public, | |
@{Name = "Created";Expression = {$_.created_at -as [datetime]}} | |
} | |
} #should process | |
} #process | |
End { | |
Write-Verbose "[END ] Ending: $($MyInvocation.Mycommand)" | |
} #end | |
} #end function | |
# Unmute | |
[audio]::Mute=0 | |
# Maximize volume | |
[audio]::Volume = 1 | |
# Create a new SpVoice objects | |
$voice = New-Object -ComObject Sapi.spvoice | |
# Set the speed - positive numbers are faster, negative numbers, slower | |
$voice.rate = 0 | |
# Say something | |
$voice.speak("Here") | |
New-GitHubGist |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment