Skip to content

Instantly share code, notes, and snippets.

@toenuff
toenuff / h2o.ps1
Last active February 13, 2019 19:29
# Published for http://powertoe.wordpress.com
# https://powertoe.wordpress.com/2017/10/23/h2o-machine-learning-with-powershell/
function ConvertTo-FormData {
param(
[Parameter(ValueFromPipeline=$true)] [PSObject] $InputObject
)
Begin {
$output = ""
}
function Get-HistoryGrep {
param(
[Parameter(Mandatory=$false, Position=0)]
[string]$Regex
)
get-history |?{$_.commandline -match $regex}
}
function Invoke-History {
param(
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Bootstrap 101 Template</title>
<p></p><a href="http://getbootstrap.com/getting-started/#examples">Examples</a></p>
<!-- Bootstrap -->
var HTML_COLORS = ["AliceBlue","AntiqueWhite","Aqua","Aquamarine","Azure","Beige","Bisque","Black","BlanchedAlmond","Blue", "BlueViolet",
"Brown","BurlyWood","CadetBlue","Chartreuse","Chocolate","Coral","CornflowerBlue","Cornsilk","Crimson","Cyan", "DarkBlue","DarkCyan",
"DarkGoldenRod","DarkGray","DarkGrey","DarkGreen","DarkKhaki","DarkMagenta","DarkOliveGreen","Darkorange","DarkOrchid","DarkRed",
"DarkSalmon","DarkSeaGreen","DarkSlateBlue","DarkSlateGray","DarkSlateGrey","DarkTurquoise","DarkViolet","DeepPink","DeepSkyBlue",
"DimGray","DimGrey","DodgerBlue","FireBrick","FloralWhite","ForestGreen","Fuchsia","Gainsboro","GhostWhite","Gold","GoldenRod","Gray",
"Grey","Green","GreenYellow","HoneyDew","HotPink","IndianRed","Indigo","Ivory","Khaki","Lavender","LavenderBlush","LawnGreen",
"LemonChiffon","LightBlue","LightCoral","LightCyan","LightGoldenRodYellow","LightGray","LightGrey","LightGreen","LightPink",
"LightSalmon","LightSeaGreen","LightSkyBlue","LightSlateGray","LightSlateGre
@toenuff
toenuff / gist:7536659
Created November 18, 2013 22:40
Write-Trace - Write a trace message with PowerShell
function Write-Trace {
param(
[Parameter(Mandatory=$true, Position=0, ValueFromRemainingArguments=$true)]
[string]$message,
[Parameter(Mandatory=$false)]
[string]$category="PS Script"
)
[System.Diagnostics.Debug]::WriteLine($message, $category)
}
@toenuff
toenuff / currentdir
Last active December 24, 2015 00:19
The following snippet gets the current directory whether or not it's run from a script or a PowerShell host. I put this at the top of nearly every script I write. Blogged as powerbit #9 here: http://powertoe.wordpress.com/2012/11/02/powerbits-9-set-the-current-directory-to-the-script-directory-or-the-current-directory-if-run-in-a-session/
# http://powertoe.wordpress.com/2012/11/02/powerbits-9-set-the-current-directory-to-the-script-directory-or-the-current-directory-if-run-in-a-session/
$currdir = ''
if ($MyInvocation.MyCommand.Path) {
$currdir = Split-Path $MyInvocation.MyCommand.Path
} else {
$currdir = $pwd -replace '^\S+::',''
}
@toenuff
toenuff / hgrep.ps1
Last active December 24, 2015 00:09
Hgrep is a function that provides similar functionality to the unix commands history |grep something
# http://powertoe.wordpress.com/2013/09/26/powerbits-10-history-grep-or-hgrep-in-powershell/
function hgrep {
param(
[Parameter(Mandatory=$false, Position=0)]
[string]$Regex,
[Parameter(Mandatory=$false)]
[switch]$Full
)
$commands = get-history |?{$_.commandline -match $regex}
function Get-Periscope {
param(
[Parameter(Mandatory=$true, Position=0)]
[string] $Id,
[Parameter(Mandatory=$true)]
[ValidateScript({Test-Path $_})]
[string] $Path
)
if (!(test-path $Path)) {
-----BEGIN RSA PRIVATE KEY-----
MIIEpQIBAAKCAQEA7oei2KnmNsq4pZVtcwtDN0zIrEmv5TgMxdLQtdIszqO/UJbp
Lbf4LG+DtT7eVmzmN3rSWV9Q7P7UdAds0j03c9sAwjprMuv5F1MzyC1rNQct5M5m
X0X0Scylan9HVccjTXt6Yr+IPni8PNOs0rwhqRB0TEtJuP2IYuzeg5Z2LWxnAVjL
5uNd9HMpuDwVHDMibpeMOomr2ePqdUPAK+ZRQbUYVvnR6fkzSKehcTvnKG6P1qhO
ifx6dsmls9HqrRpfBXmItAUaMO7VrQAjFybYgr8dHdVewLJqM2EmyN2buxEMIckp
afxb042mZbukJqZXEAZo2IYeee4NgSPV7fXhGwIDAQABAoIBAQDXg0s6MT+kb8Mn
MHyEPj/L3h9NswIuu1anAhO6w5viVAaOPNuPiDG9jD/W6WefdKMIq3sUbs9CYff4
oaDLz62jitMDqh6jEpurXGxjx82eSs9HdMj/+cd/SlyGfVspgFRANHlecSkbMKD6
4FG80WgkRY6eREPm1YN9xgBBqhc6b4GGZ2+hcVhkfYdnfmACy9+tIF6yHG5c4VPE
@toenuff
toenuff / samplecred
Last active August 29, 2015 14:20
Example of putting -Credential in function
$class = new-object psobject @{credential=$null}
function samplecred {
param(
[Parameter(Mandatory=$false)]
[ValidateScript({("String","PSCredential") -contains $_.gettype().name})]
[Object] $Credential
)
if ($Credential) {
switch ($Credential.gettype().name) {