Skip to content

Instantly share code, notes, and snippets.

@davidvesely
davidvesely / FlawlessLogger.cs
Created May 20, 2022 08:23
Flawless Logger
using System;
using System.Collections.Concurrent;
using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
namespace Blablabla
{
public static class Logger
@davidvesely
davidvesely / AsyncUtils.cs
Created March 22, 2022 13:07
Execute async as sync operation
using System;
using System.Threading;
using System.Threading.Tasks;
namespace Kongsberg.KSim.Extensions.Gmdss.Domain
{
/// <summary>
/// Helper class to run async methods within a sync process.
/// </summary>
public static class AsyncUtil
@davidvesely
davidvesely / EnumExtensions.cs
Created January 12, 2022 17:48
Enum extensions
public static class EnumExtensions
{
private static void CheckIsEnum<T>(bool withFlags)
{
if (!typeof(T).IsEnum)
throw new ArgumentException(string.Format("Type '{0}' is not an enum", typeof(T).FullName));
if (withFlags && !Attribute.IsDefined(typeof(T), typeof(FlagsAttribute)))
throw new ArgumentException(string.Format("Type '{0}' doesn't have the 'Flags' attribute", typeof(T).FullName));
}
@davidvesely
davidvesely / SplitPascalCaseToWords.cs
Created January 7, 2022 11:34
Split PascalCase to words
string[] tests = {
"AutomaticTrackingSystem",
"XMLEditor",
"AnXMLAndXSLT2.0Tool",
};
Regex r = new Regex(@"(?<=[A-Z])(?=[A-Z][a-z])|(?<=[^A-Z])(?=[A-Z])|(?<=[A-Za-z])(?=[^A-Za-z])");
foreach (string test in tests)
{
Console.WriteLine(r.Replace(test, " "));
@davidvesely
davidvesely / Powershell Switch x86-x64.ps1
Created July 17, 2019 00:22
Switching between PowerShell x86 and x64
# Put one of these blocks in front of your ps1 script
# Credits to http://vegetarianprogrammer.blogspot.com/2013/03/running-64-bit-powershell-from-32-bit.html
if ($env:PROCESSOR_ARCHITEW6432 -eq "AMD64") {
Write-Warning "Switching from 32bit to 64bit PowerShell"
$powershell = Join-Path $PSHOME.ToLower().Replace("syswow64","sysnative").Replace("system32","sysnative") powershell.exe
if ($myInvocation.Line) {
&"$powershell" -NonInteractive -NoProfile -ExecutionPolicy Bypass $myInvocation.Line
} else {
&"$powershell" -NonInteractive -NoProfile -ExecutionPolicy Bypass -file "$($myInvocation.InvocationName)" $args
@davidvesely
davidvesely / IEnumerableExtension.cs
Created June 18, 2019 08:26
IEnumerable extensions, Except on different collection type
using System.Linq;
namespace System.Collections.Generic
{
public static class IEnumerableExtension
{
public static IEnumerable<TFirst> Except<TFirst, TSecond, TCompared>(
this IEnumerable<TFirst> first,
IEnumerable<TSecond> second,
Func<TFirst, TCompared> firstSelect,
@davidvesely
davidvesely / Set-Permissions-ACL.ps1
Created May 22, 2019 13:28
Powershell set folder permissions recursivelly
function Set-Permission {
<#
.SYNOPSIS
Add / Remove NTFS rights to files or folders
.DESCRIPTION
Modifies ACLs of folders and files using Get-Acl and Set-Acl.
Created by Jason Svatos
Created on 3/10/2016
Modified 3/12/2016 (Added EnableInheritance switch parameter and Action:Replace parameter)
@davidvesely
davidvesely / hosts.ps1
Last active June 11, 2018 00:08 — forked from markembling/hosts.ps1
Powershell script for adding/removing/viewing entries to the hosts file.
#
# Powershell script for adding/removing/showing entries to the hosts file.
#
# Known limitations:
# - does not handle entries with comments afterwards ("<ip> <host> # comment")
#
$file = "C:\Windows\System32\drivers\etc\hosts"
function add-host([string]$filename, [string]$ip, [string]$hostname) {
Usage:
var queryParams = new QueryParameters();
queryParams.Add("public_id", messageId);
queryParams.Add("username", this.operatorConfig.Username);
queryParams.Add("checksum", this.GetChecksum(messageId));
var builder = new UriBuilder(this.serviceUri)
{
Query = queryParams.ToString()
};
@davidvesely
davidvesely / Jenkinsfile
Created July 27, 2017 12:53
Jenkins pipeline email notification
# Plugin - Email Extension Plugin
def notifySuccessful() {
emailext (
subject: "SUCCESSFUL: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]'",
body: """<p>SUCCESSFUL: Job '${env.JOB_NAME} [${env.BUILD_NUMBER}]':</p>
<p>Check console output at &QUOT;<a href='${env.BUILD_URL}'>${env.JOB_NAME} [${env.BUILD_NUMBER}]</a>&QUOT;</p>""",
recipientProviders: [[$class: 'DevelopersRecipientProvider']]
)
}