Skip to content

Instantly share code, notes, and snippets.

View dfinke's full-sized avatar

Doug Finke dfinke

View GitHub Profile
private static void InvokePowerShell(IDictionary<string, object> env, StreamWriter w)
{
string req = env["owin.RequestQueryString"] as string;
var queryParts = HttpUtility.ParseQueryString(req);
var powerShellFilename = queryParts[null] + ".ps1";
if (File.Exists(powerShellFilename))
{
var script = File.ReadAllText(powerShellFilename);
param($data=1..50)
$xl = New-Object -ComObject Excel.Application
$xlProcess = Get-Process excel
$wf = $xl.WorksheetFunction
$data = $data|iex
New-Object PSObject -Property @{
Median = $wf.Median($data)
@dfinke
dfinke / PSRoslyn.ps1
Last active February 26, 2023 11:57
function Invoke-Csx {
param($script = 'System.Console.WriteLine("Hello World");')
foreach($dll in (dir .\lib)) { Add-Type -Path $dll.FullName}
$engine = New-Object Roslyn.Scripting.CSharp.ScriptEngine $null, $null
$engine.AddReference("System")
$engine.AddReference("System.Core")
$session = $engine.CreateSession()
@dfinke
dfinke / IseNode.ps1
Last active December 15, 2015 01:49
A PowerShell ISE Add on menu that runs Node.js against a JavaScript file opened in ISE
$sb = {
$node = "node.exe"
if(!(Get-Command $node -ErrorAction SilentlyContinue)) {
throw "Could not find $node"
}
$psISE.CurrentFile.Save()
& $node $psISE.CurrentFile.FullPath
}
@dfinke
dfinke / Get-ContentJson.ps1
Last active September 15, 2021 19:23
This function works like PowerShell's builtin cmdlet Get-Content, except, if you pass in a file that contains JSON, it will convert it for you. If for example, you are working with npm modules (node.js packages), they have a file package.json that are used for configuration information. So you can use it like this: ls . -recurse *.json | Get-Con…
function Get-ContentJson {
<#
.Synopsis
Get-ContentJson reads a json file, converts it an returns the object
.Example
ls . -recurse *.json | Get-ContentJson
.Example
Get-ContentJson (dir . *.json).fullname
#>
param(
@dfinke
dfinke / New-EdgeCompiler.ps1
Last active December 15, 2015 14:49
New-EdgeCompiler -LanguageIdentifier ps -Remove -TestInstall
function Write-HostWithTimestamp {
param($Message)
Write-Host "[$((Get-Date).ToString('yyyyMMddhhmmss'))] $Message"
}
function Get-TestJS {
param(
[Parameter(Mandatory)]
$LanguageIdentifier
$json="
{
'name': 'john doe',
'age':10,
'pets': []
}
"
$json |
ConvertFrom-Json |
@dfinke
dfinke / myise.ps1
Created May 27, 2013 20:53
How I Fixed PowerShell ISE
function MyISE {
param($File)
if(!(Test-path $File)) {
New-Item -name $File -itemtype "file"
}
ise $file
}
@dfinke
dfinke / Get-CitiBikeStations.ps1
Last active December 19, 2015 02:18
@CitibikeNYC has a JSON endpoint now I can use PowerShell to find docking stations Get-CitiBikeStations "Park Ave"
function Get-CitiBikeStations {
param($label)
$wc = New-Object net.webclient
($wc.DownloadString("http://appservices.citibikenyc.com/data2/stations.php") |
ConvertFrom-Json).results |
select label, availableBikes,availableDocks |
where label -Match $label
}
@dfinke
dfinke / ExtractSVN.ps1
Created October 12, 2013 16:10
Use PowerShell to extract Subversion commands and the parameters from help to a hash table
$svninfo = @{}
svn help |
?{$_ -match "^ "} |
%{($_.trim() -split " ")[0]} |
%{
$command = $_
if(!$svninfo.ContainsKey($command)) {
$svninfo.$command=@{SingleHyphen=@();DoubleHyphen=@()}
}