Skip to content

Instantly share code, notes, and snippets.

View SeidChr's full-sized avatar

Christian Seidlitz SeidChr

View GitHub Profile
@SeidChr
SeidChr / vpndisconnect.ps1
Created March 18, 2020 20:42
windows based vpn automatic reconnect
param($vpnName)
rasdial $vpnName /disconnect
@SeidChr
SeidChr / Set-SlackStatus.ps1
Last active October 24, 2023 11:48
Set Slack Status via Powershell
param($token, $statusText, $emojiCode)
$baseUri = 'https://slack.com/api/users.profile.set'
$json = '{"status_text":"'+$statusText+'","status_emoji":"'+$emojiCode+'","status_expiration":0}'
$jsonEncoded = [uri]::EscapeDataString($json)
$uri = $baseUri + "?token=$token&profile=$jsonEncoded"
Invoke-WebRequest -Method Post -Uri $uri | Out-Null
param($statusText, $emojiCode)
$baseUri = 'https://slack.com/api/users.profile.set'
@SeidChr
SeidChr / Set-VpnStatus.ps1
Created May 8, 2020 08:38
Connecting or disconnecting on a windows-based vpn (rasdial) with notification messages
param(
$vpnName,
[ValidateSet("Connect", "Disconnect")]
[string]
$action
)
switch ($action) {
"Disconnect" {
$vpn = Get-VpnConnection -Name $vpnName
param(
[string[]] $videoId,
[switch] $setup,
[double] $trimPercentage = 0.015
)
function Ensure-Path
{
param([string]$Path)
if (!(Test-Path $Path)) {
@SeidChr
SeidChr / Write-Gradient.ps1
Last active February 4, 2021 21:04
Powershell Console Gradient Foreground
# https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences
function Gradient {
param(
[string] $Start,
[string] $End,
[double] $Grade,
[string] $Text
)
$marker = [char]27
@SeidChr
SeidChr / ws.ps1
Created March 19, 2021 14:57 — forked from byt3bl33d3r/ws.ps1
Async Websocket PowerShell client (producer/consumer pattern)
<#
References:
- https://docs.microsoft.com/en-us/dotnet/api/system.net.websockets.clientwebsocket?view=netframework-4.5
- https://github.com/poshbotio/PoshBot/blob/master/PoshBot/Implementations/Slack/SlackConnection.ps1
- https://www.leeholmes.com/blog/2018/09/05/producer-consumer-parallelism-in-powershell/
#>
$client_id = [System.GUID]::NewGuid()
$recv_queue = New-Object 'System.Collections.Concurrent.ConcurrentQueue[String]'
@SeidChr
SeidChr / FunnyWords.txt
Created May 19, 2022 19:08
Funny Words
Schmutzbug // 20220519 Eifelkanal Discord
@SeidChr
SeidChr / ExtractRVIndex.ps1
Created October 3, 2022 16:43
Extracts information about parked cars from mobile.de and calculates an index (higher is better) based on milage, age and price
# https://www.mobile.de/svc/my/parking-list/?lang=de
$j | ConvertFrom-Json |% items |? status -eq OK |% {
$now = Get-Date
$kmIndex = 1000000
$priceIndex = 700000
$ageIndex = 100
$kmAIndex = 300000
} {
$month,$year = $_.ad.attr.fr?.split("/") ?? 0,0
$km = [int][Regex]::Replace($_.ad.attr.ml, "[^\d]", '')
# generate regex match groups from arrays
function ContGroup {
param([object[]]$Source, [int]$GroupSize)
0..($Source.Length-$GroupSize) |% { $Source | Select -Skip $_ -First $GroupSize | Join-String }
}
# $ ContGroup -Source (1..9 + 0) -GroupSize 4 | Join-String -Separator '|'
# 1234|2345|3456|4567|5678|6789|7890
# $ ContGroup -Source ('a'..'z') -GroupSize 3 | Join-String -Separator '|'
# abc|bcd|cde|def|efg|fgh|ghi|hij|ijk|jkl|klm|lmn|mno|nop|opq|pqr|qrs|rst|stu|tuv|uvw|vwx|wxy|xyz
filter To-Select {
$object = $_
$type = $_.GetType()
if ($type -in [hashtable],[pscustomobject]) {
$properties = ([pscustomobject] $_).psobject.properties
$propNames = $properties.name
if (-not ("Name" -in $propNames -and "Expression" -in $propNames)) {
$object = $properties | ForEach-Object {
@{
Name = $_.name