Skip to content

Instantly share code, notes, and snippets.

@Tewr
Tewr / StreamExtensions.cs
Created November 7, 2014 05:21
Stream CopyTo with bytecount
namespace Extensions {
public static class StreamExtensions
{
/// <summary>
/// Implementation of <see cref="Stream.CopyTo(System.IO.Stream)"/> with progress reporting
/// </summary>
/// <param name="fromStream"></param>
/// <param name="destination"></param>
/// <param name="bufferSize"></param>
/// <param name="progressInfo"></param>
@Tewr
Tewr / Windows Task Scheduler service restart export.xml
Created February 9, 2015 15:21
Batch, log and task scheduler export for restarting a windows service that has gone down for whatever reason (on event 0 + random checks every 30 minutes)
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2014-02-20T16:20:55.1120404</Date>
<Author>[account]</Author>
<Description>Attempts to start SERVICE_NAME. Logs the attempt to start it to a log file if the service was not started.</Description>
</RegistrationInfo>
<Triggers>
<EventTrigger>
<Enabled>true</Enabled>
@Tewr
Tewr / BuildTimeInfo.tt
Created October 5, 2015 07:52
BuildTimeInfo Setup
<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System" #>
<#@ output extension=".cs" #>
<#
string datePattern = "fffssmmHHddMMyyyy";
string buildTime = DateTime.Now.ToString(datePattern);
string humanReadableBuildTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff");
#>using System;
using System.Globalization;
@Tewr
Tewr / ComponentModelExtensions.cs
Last active July 6, 2016 14:24
Helper for classes decorated with DefaultValueAttribute
using System;
using System.ComponentModel;
using System.Linq.Expressions;
using System.Reflection;
namespace Extensions
{
public static class ComponentModelExtensions
{
public static TProperty GetPropertyValueOrDefault<TSource, TProperty>(
<#
.SYNOPSIS
Applies SQL group membership (unless exists) on availablitiy group nodes using windows login, from a definition file.
.DESCRIPTION
Applies SQL group membership (unless exists) on availablitiy group nodes using windows logins and groups, from a definition file.
Based on a role definition file, SQL snippets are generated and then executed.
Removes any login/dbuser mapping that are in conflict with the securityDefinitionFile specification.
.PARAMETER masterEndpoints
List of FQDN[,<port>] of SQL nodes participating in the availability group
.PARAMETER instanceEndpoint
@Tewr
Tewr / MessageBoxWithCheckBox.Designer.cs
Last active November 18, 2021 18:27
Winforms MessageBoxWithCheckBox
namespace CustomMessageBoxes
{
partial class MessageBoxWithCheckBox
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
@Tewr
Tewr / EmptyReadOnlyDictionary.cs
Last active June 4, 2018 11:58
ReadOnly Empty Dictionary implementation
using System.Linq;
namespace System.Collections.Generic
{
public class EmptyReadOnlyDictionary<TKey, TValue> : IReadOnlyDictionary<TKey, TValue>
{
private static readonly Lazy<IEnumerable<KeyValuePair<TKey, TValue>>> Empty =
new Lazy<IEnumerable<KeyValuePair<TKey, TValue>>>(Enumerable.Empty<KeyValuePair<TKey, TValue>>);
public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator() => Empty.Value.GetEnumerator();
@Tewr
Tewr / StateChecker.cs
Created November 8, 2018 20:11
Entity framework 6 graph update
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.Validation;
using System.Linq;
public interface IEntity
{
int Id { get; set; }
}
#%HOMEPATH%\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
function gitpushup { git rev-parse --abbrev-ref HEAD | foreach { git push --set-upstream origin $_ }}
set-alias git-pushup gitpushup
function gitmergedev { git rev-parse --abbrev-ref HEAD | foreach { if (git checkout develop) {git pull; git checkout $_;git merge develop; }}}
set-alias git-mergedev gitmergedev
function gitmergemas { git rev-parse --abbrev-ref HEAD | foreach { if (git checkout master) {git pull; git checkout $_;git merge master; }}}
set-alias git-mergemas gitmergemas
@Tewr
Tewr / Startup.cs
Created March 8, 2019 09:35
Adds Enums to swashbuckle for use with NSwag
/* Source: https://github.com/domaindrivendev/Swashbuckle/issues/1287 */
(...)
config.AddSwaggerGen(options => {
options.DocumentFilter<SwaggerAddEnumDescriptions>();
}