Skip to content

Instantly share code, notes, and snippets.

View dfinke's full-sized avatar

Doug Finke dfinke

View GitHub Profile
$template = @'
{[DateTime]Date*:Tue Nov 11, 2014} {Home:Penguins}{Away:Rangers} {[DateTime]Time:7:00 PM} FINAL PIT (0) - NYR (5) Recap
{Date*:Sat Mar 14, 2015} {Home:Bruins}{Away:Penguins} 1:00 PM ROOT, NHLN-US, TVA Tickets BUY/SELL
Thu Mar 26, 2015 PenguinsHurricanes 7:00 PM ROOT
Sat Nov 22, 2014 PenguinsIslanders 7:00 PM ROOT, CITY
Sat Nov 1, 2014 SabresPenguins 7:00 PM FINAL BUF (0) - PIT (5) Recap
Fri Jan 16, 2015 PenguinsIslanders 7:00 PM ROOT, TVA2
'@
(Invoke-WebRequest http://penguins.nhl.com/club/schedule.htm).AllElements |
@dfinke
dfinke / GeometryNumber,.ps1
Last active August 29, 2015 14:11
Fluent API Using PowerShell v5 Classes
class GeometryNumber {
[double]$Number
GeometryNumber() {}
GeometryNumber($Number) { $this.Number=$Number }
[GeometryNumber] Sqrt() { return [GeometryNumber]::new([Math]::Sqrt($this.Number)) }
[GeometryNumber] Reciprocal() { return [GeometryNumber]::new(1/$this.Number) }
[GeometryNumber] TangetAngle() { return [GeometryNumber]::new([System.Math]::Atan($this.Number)) }
[GeometryNumber] AsDegrees() { return [GeometryNumber]::new($this.Number*180/[Math]::PI) }
function mynetstat {
$t=@"
Proto Local Address Foreign Address State
{Proto*:TCP} {Address:0.0.0.0:80} {FA:my-laptop:0} {State:LISTENING}
TCP 0.0.0.0:135 my-laptop:0 LISTENING
TCP 192.168.0.6:139 my-laptop:0 LISTENING
{Proto*:TCP} 192.168.0.6:1128 a23-209-83-52:https {State:CLOSE_WAIT}
"@
$data | cfs -TemplateContent $t | select * -ExcludeProperty ExtentText
@dfinke
dfinke / MagicSquares.ps1
Last active August 29, 2015 14:13
Lusus Numerorum - . Strange coincidences of a lusus numerorum. "Magic squares and cubes" - Paul Carus
1..10 | ForEach {
$r = 0..($_-1) -join ''
$exp = "$($r)*9+$_"
"{0,15}={1}" -f $exp, ($exp|Invoke-Expression)
}
''
@dfinke
dfinke / maze.ps1
Last active August 29, 2015 14:14
Using PowerShell Classes - works simply by visiting each cell in the grid, and choosing to carve a passage either north, or east
param($Rows=8, $Columns=8)
Add-Type -AssemblyName System.Drawing
class Cell {
[int]$Row
[int]$Col
$links = @{}
@dfinke
dfinke / ConvertFrom-JsonToCsv.ps1
Created February 16, 2015 14:28
Using PowerShell to Convert From JSON to CSV format
function ConvertFrom-JsonToCsv {
param(
[Parameter(ValueFromPipeline)]
$json
)
Process {
($json | ConvertFrom-Json) | ConvertTo-Csv -NoTypeInformation
}
}
@dfinke
dfinke / Get-DateOfEaster.ps1
Last active January 12, 2016 22:18
PowerShell Get-DateOfEaster, algorithm devised in 1876
function Get-DateOfEaster {
param(
[Parameter(ValueFromPipeline)]
$Year=(Get-Date).Year
)
Process {
[pscustomobject]@{} |
Add-Member -PassThru -MemberType NoteProperty C3 $Year |
Function Expand-Alias {
$Editor=$psISE.CurrentFile.Editor
$script=$Editor.Text
[ref]$errors=$null
[System.Management.Automation.PsParser]::Tokenize($script, $errors) |
Where { $_.Type -eq 'Command'} |
Sort StartLine, StartColumn -Desc |
@dfinke
dfinke / PSSummit.ps1
Last active April 8, 2023 06:44
PowerShell GUI for viewing YouTube Videos of the PowerShell NA Summit 2015
Add-Type -AssemblyName PresentationFrameWork
$MainWindow=@'
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Topmost="True"
WindowStartupLocation="CenterScreen"
Title="PowerSHell Summit Videos" Height="850" Width="1200">
<Grid>
<Grid.RowDefinitions>
$startDate = (Get-Date).ToString('Mddyy') # 51515
$ca=$startDate.ToCharArray()
[array]::Reverse($ca)
$ofs=''
$startDate -eq "$ca" # prints True