Skip to content

Instantly share code, notes, and snippets.

View tkouba's full-sized avatar

Tomas Kouba tkouba

  • Prague, Czech Republic
View GitHub Profile
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
namespace ForBenchmark
{
[MemoryDiagnoser(false)]
public class Program
{
[Params(10, 1000)]
@tkouba
tkouba / Get-KepwareConfigRoot.ps1
Created February 19, 2024 15:41
Get Kepware KEPServerEX V6 configuration root dirwectory.
<#PSScriptInfo
.VERSION 1.0
.GUID d1e5442a-c2cf-403d-a4f9-e4a54b4886bd
.AUTHOR Tomas Kouba
.COMPANYNAME Axians CZ
@tkouba
tkouba / Stop-ClusterServices.ps1
Created February 7, 2024 19:12
Stop services managed by the cluster but not owned by the current node (unexpectedly started)
<#PSScriptInfo
.VERSION 1.1
.GUID 872d1af1-6a2c-4c71-be96-4b230a8e4a5f
.AUTHOR Tomas Kouba
.COMPANYNAME
namespace TestGetBusinessDays
{
public class UnitTestCalcBusinessDays
{
int GetBusinessDays(DateTime startD, DateTime endD)
{
double calcBusinessDays =
1 + ((endD - startD).TotalDays * 5 -
(startD.DayOfWeek - endD.DayOfWeek) * 2) / 7;
@tkouba
tkouba / usb_hid_keys.h
Created August 7, 2023 11:00 — forked from MightyPork/usb_hid_keys.h
USB HID Keyboard scan codes
/**
* USB HID Keyboard scan codes as per USB spec 1.11
* plus some additional codes
*
* Created by MightyPork, 2016
* Public domain
*
* Adapted from:
* https://source.android.com/devices/input/keyboard-devices.html
*/
@tkouba
tkouba / FindDiff.cs
Created February 16, 2023 17:32
Compare two JSON and find the difference
/// <summary>
/// Compare two JSON and create diff object
/// </summary>
/// <param name="leftJson">Left JSON to compare</param>
/// <param name="rightJson">Right JSON to compare</param>
/// <returns>Diff object with the result.</returns>
/// <remarks>
/// Original version https://stackoverflow.com/a/65222961/1498252 by Rohith Daruri
/// based on https://stackoverflow.com/a/53654737/1498252 by Dzmitry Paliakou
/// </remarks>
@tkouba
tkouba / DelayedStartService.cs
Created January 11, 2023 11:20
Delayed Start Service - helper service for dependent service delayed start
using System;
using System.Diagnostics;
using System.ServiceProcess;
class DelayedStartService : ServiceBase
{
private int _delay;
private string[] _services;
@tkouba
tkouba / Add-StopClusterServicesJob.ps1
Created May 9, 2022 07:19
Add Powershell scheduled job for stopping services on cluster passive node
$options = New-ScheduledJobOption -WakeToRun -StartIfIdle -MultipleInstancePolicy IgnoreNew -RunElevated
$trigger = New-JobTrigger -Once -At (Get-Date) -RepetitionInterval (New-TimeSpan -Minutes 5) -RepeatIndefinitely
Unregister-ScheduledJob -Name "Stop-ClusterServices" -ErrorAction SilentlyContinue
Register-ScheduledJob -Name "Stop-ClusterServices" -ScriptBlock {
(Get-ClusterGroup | Where-Object {$_.OwnerNode -ne $env:COMPUTERNAME} | Get-ClusterResource) | Where-Object {$_.ResourceType -eq 'Generic Service'} | Get-Service | Where-Object {$_.Status -eq 'Running'} | Stop-Service -Verbose
} -Trigger $trigger -ScheduledJobOption $options
(Get-ScheduledJob -Name "Stop-ClusterServices").StartJob()
@tkouba
tkouba / Stop-ClusterServices.ps1
Created May 2, 2022 11:33
Stop services in cluster resources on inactive node.
# Selects cluster groups which are not owned by current node
# then select resources with type 'Generic Service'
# then select 'Running' services
# and stop them
(Get-ClusterGroup | Where-Object {$_.OwnerNode -ne $env:COMPUTERNAME} | Get-ClusterResource) | Where-Object {$_.ResourceType -eq 'Generic Service'} | Get-Service | Where-Object {$_.Status -eq 'Running'} | Stop-Service -Verbose
@tkouba
tkouba / .gitignore
Created October 13, 2021 10:46
My Visual Studio .gitignore file
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
*.apk
# User-specific files
*.suo
*.user
*.userosscache
*.sln.docstates