Skip to content

Instantly share code, notes, and snippets.

View gitfvb's full-sized avatar
👋

Florian von Bracht gitfvb

👋
View GitHub Profile
@gitfvb
gitfvb / example.ps1
Created December 10, 2021 16:48
Note about always returning arrays in powershell
<#
Sometimes it is hard to make sure a function passes an array back if it is only one element
With @( ) you can make sure you have an array, even with one element. But in the function to always return an array,
do something like below, inspired by https://evotec.xyz/powershell-returning-one-object-from-function-as-an-array/
#>
Function Do-Foo() {
# Check the installed capabilites
Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH*'
# Install OpenSSH Server
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
# Start service and set it automatically
Start-Service sshd
@gitfvb
gitfvb / readme.md
Created November 30, 2021 23:36
Using npgsql via powershell 5.1 with .net 4.x

Used the following files from nuget

        FileDescription                        CompanyName           FileVersionRaw
        ---------------                        -----------           --------------
        Microsoft.Bcl.AsyncInterfaces          Microsoft Corporation 4.700.20.21406
        Npgsql                                 Npgsql                4.0.12.0
        System.Buffers                         Microsoft Corporation 4.6.28619.1
        System.Memory                          Microsoft Corporation 4.6.28619.1
@gitfvb
gitfvb / readme.md
Last active November 18, 2021 17:23
calculate processing times in sqlite

if you have multiple columns and want to calculate the differences in seconds and milliseconds, a query like this can help to produce output like in the csv file in this gist.

This is the query

select
	"timestamp"
	,strftime('%f',julianday("inserted")-julianday("timestamp")) "Timestamp to inserted"
	,strftime('%f',julianday("response_calculated")-julianday("inserted")) "Response calculated"
	,strftime('%f',julianday("response_timestamp")-julianday("response_calculated")) "API Call finished"
@gitfvb
gitfvb / scheduledtask.ps1
Created October 27, 2021 09:57
Create a windows scheduled task (running in background) via PowerShell
################################################
#
# CREATE WINDOWS TASK
#
################################################
# Confirm you read the licence details
$createTask = $Host.UI.PromptForChoice("Confirmation", "Do you want to create a scheduled task for the check and refreshment?", @('&Yes'; '&No'), 0)
@gitfvb
gitfvb / extras.xml
Created September 1, 2021 10:24
Extras.xml together with E-Mail GenericFTP
<Extras>
<AddColumn>
<runcommand>
<command>powershell.exe</command>
<arguments> -ExecutionPolicy Bypass -File "D:\Scripts\GenericFTP\test.ps1" -inputFile "{%directory%}{%filename%}.{%ext%}" -scriptPath "D:\Scripts\GenericFTP"</arguments>
<workingdirectory></workingdirectory>
<waitforcompletion>true</waitforcompletion>
</runcommand>
</AddColumn>
</Extras>
@gitfvb
gitfvb / readme.md
Last active March 23, 2021 09:39
Use json1 in SQLITE and DB Browser

When downloading the current (today: 2021-03-23) precompiled binaries or the cli of sqlite, the json extension is already compiled into the exe/dll

When you want to use it for db browser (which does not have the json1 extension right now), just download the precompiled binaries for windows from https://www.sqlite.org/download.html

Unzip it and replace the sqlite3.dll in C:\Program Files\DB Browser for SQLite

After re-opening DB Browser, you can execute queries like

SELECT JSON('{"a": "b"}')
@gitfvb
gitfvb / random_strings.ps1
Last active February 1, 2021 23:56
random strings eg for vouchers
function getRandomString([int] $length) {
$random = [Random]::new()
$chars = @("0", "2", "3", "4", "5", "6", "8", "9", "a", "b", "c", "d", "e", "f", "g", "h", "j", "k", "m", "n", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z")
$stringBuilder = ""
for ($i = 0; $i -lt $length; $i++) {
$stringBuilder += $chars[$random.Next($chars.Length)]
}
return $stringBuilder
}
@gitfvb
gitfvb / readme.md
Created January 9, 2021 11:39
Playing minecraft 1.16.4 on local network LAN with one purchased game

Notebook #1

  • Open Minecraft normally
  • Go into a single player game
  • When in the gameplay, open the menu and open the game in the LAN
  • Note the port and maybe the IP

Notebook #2

  • Open the minecraft launcher so the current login tokens are getting refreshed
@gitfvb
gitfvb / check-datatypes.ps1
Created December 22, 2020 11:13
Check some datatypes in PowerShell
<#
Is-Numeric 10 # True
Is-Numeric "10" # True
Is-Numeric "10f" # False
Is-Numeric "+10" # True
Is-Numeric "-10" # True
Is-Numeric "-10.5" # False
#>
function Is-Int ($value) {