Skip to content

Instantly share code, notes, and snippets.

@davidvesely
davidvesely / SmartCardCertificates.cs
Created November 13, 2015 11:58
Подписване на заяка към сървис без ръчно въвеждане на ПИН код в SmartCard устройство със сертификат
using Net.Pkcs11Interop.Common;
using Net.Pkcs11Interop.HighLevelAPI;
using Net.Pkcs11Interop.PDF;
using Org.BouncyCastle.Crypto.Parameters;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Security;
@davidvesely
davidvesely / MoqExtensions.cs
Created January 13, 2016 09:38 — forked from ngocvantran/MoqExtensions.cs
Extension methods to quickly ignore arguments without repeating It.IsAny<>()
using System;
using System.Linq.Expressions;
using Moq.Language.Flow;
namespace Moq
{
public static class MoqExtensions
{
public static ISetup<T, TResult> SetupIgnoreArgs<T, TResult>(this Mock<T> mock,
Expression<Func<T, TResult>> expression)
@davidvesely
davidvesely / DictionaryToString.cs
Created January 18, 2016 02:36
Serializing dictionary to string
public static string DictionaryToString(Dictionary<string, string> d)
{
// Build up each line one-by-one and then trim the end
StringBuilder builder = new StringBuilder();
foreach (KeyValuePair<string, string> pair in d)
{
builder.Append(pair.Key).Append(":").Append(pair.Value).Append(",\n");
}
string result = builder.ToString();
return result;
@davidvesely
davidvesely / UriAppend.cs
Created July 22, 2017 19:26
Uri Append extension method
public static Uri Append(this Uri uri, params string[] paths)
{
return new Uri(paths.Aggregate(uri.AbsoluteUri,
(current, path) => string.Format("{0}/{1}", current.TrimEnd('/'), path.TrimStart('/'))));
}
@davidvesely
davidvesely / ToQueryString.cs
Created July 22, 2017 19:28
Convert NameValueCollection to query string
public static string ConvertToQueryString(NameValueCollection queryParameters)
{
return string.Join("&", queryParameters.AllKeys
.Select(a => $"{HttpUtility.UrlEncode(a)}={HttpUtility.UrlEncode(queryParameters[a])}"));
}
@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']]
)
}
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 / 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) {
@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 / 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,