Skip to content

Instantly share code, notes, and snippets.

View cdhunt's full-sized avatar

Chris Hunt cdhunt

View GitHub Profile
@cdhunt
cdhunt / Verbal Expressions
Created January 5, 2016 15:04
Messing around with CSharpVerbalExpressions and Fluent API in Powershell
Add-Type -Path C:\Temp\CSharpVerbalExpressions-master\VerbalExpressions\bin\Release\VerbalExpressions.dll
[psobject].Assembly.GetType("System.Management.Automation.TypeAccelerators")::add("verbex", "CSharpVerbalExpressions.VerbalExpressions")
[verbex]::new().StartOfLine().Then("http").Maybe("s").Then("://").Maybe("www.").AnythingBut(" ").EndOfLine().Test("https://www.google.com")
$proto = [verbex]::new().StartOfLine().Then("http").Maybe("s").Then("://")
$Uri = $proto.AnythingBut(" ").EndOfLine()
$uri
$uri.Test("http://google.com")
@cdhunt
cdhunt / output
Created March 1, 2016 16:36
Beating Hadoop with Posh
Black White Tie RunTime
----- ----- --- -------
2853633 3762820 3260741 6 minutes, 45 seconds, 347 milliseconds
@cdhunt
cdhunt / Markdown.types.ps1xml
Last active May 26, 2016 16:06
A custom type file to help generate markdown
<?xml version="1.0" encoding="utf-8" ?>
<Types>
<Type>
<Name>System.String</Name>
<Members>
<ScriptMethod>
<Name>MarkdownStrong</Name>
<Script>
[OutputType([System.String])]
param()
@cdhunt
cdhunt / Help to MD
Created May 26, 2016 16:55
Use the Markdown.types.ps1xml to generate a help file in Markdown
$help = Get-Help Get-Location
$help.Name.MarkdownHeader()
"Synopsis".MarkdownHeader(2)
$help.Synopsis
"Description".MarkdownHeader(2)
Function Get-Parmeters {
[CmdletBinding()]
Param(
[string]$ComputerName,
[scriptblock]$ScriptBlock
)
$parameters = @{}
$Session = New-PSSession -ComputerName 'server'
function Select-FuzzyCommand {
param(
$search=''
)
Begin {
$data = Get-Command
$search = $search.ToCharArray() -join '.*?'
Add-Type -Path C:\Users\chris.hunt\Downloads\PivotData\lib\NReco.PivotData.dll
$CSV = gc "C:\Users\chris.hunt\Downloads\PivotData\NReco.PivotData.Examples.CsvDemo\TechCrunchcontinentalUSA.csv" | ConvertFrom-Csv
$aggregators=new-object Collections.ArrayList
$aggregators.Add([NReco.PivotData.SumAggregatorFactory]::new('raisedAmt')) | Out-Null
$aggregators.Add([NReco.PivotData.AverageAggregatorFactory]::new('raisedAmt')) | Out-Null
$aggregators.Add([NReco.PivotData.MaxAggregatorFactory]::new('raisedAmt')) | Out-Null
@cdhunt
cdhunt / Microsoft.PowerShell_profile.ps1
Created October 3, 2016 19:47
Create and set a random "Session Name" in the PowerShell Console Title
Import-Module posh-git
Import-Module NameIt
function Test-Administrator {
return ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")
}
##### Console Title ######
$SessionTitleName = Invoke-Generate '[Adjective][Noun]'
@cdhunt
cdhunt / map_fold.ps1
Created October 27, 2016 13:55
Map and Fold implementations in Powershell
function map([scriptblock]$map, [Collections.IEnumerable]$x, $y) { $x.ForEach({& $map $_ $y}) }
# Two parameters
map { param($x, $y) $x + $y } @(1,2,3) 10
# Anonymous function as a value
$squareIt = { param($x) $x + $x }
map $squareIt @(1,2,3)
# One parameter
@cdhunt
cdhunt / madlib.ps1
Last active November 14, 2016 15:53
An example of using NameIt for madlibs.
$customData = @{mword = echo money memory music mammoth; dword = echo data drive distance dance dude dog; adverb = echo badly carefully little much worse less more worst least most}
$madlib = @"
If you want to become [noun] literate, here are some key
[noun]s that you should [verb] as quickly as possible:
CD ROM: Stands for compact [dword]... read only
[mword]. This compact disc can hold as many as 600
[noun]s, which is the equivalent of 700 floppy [noun]s.