Skip to content

Instantly share code, notes, and snippets.

View bymyslf's full-sized avatar

Luís Barbosa bymyslf

View GitHub Profile
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
public class FailedPreconditionObjectResult : ObjectResult
{
public FailedPreconditionObjectResult(string detail)
: base(detail)
=> StatusCode = StatusCodes.Status412PreconditionFailed;
}
@bymyslf
bymyslf / JsonPatchDocumentDiff.cs
Last active August 13, 2024 15:49
Creates a JsonPatchDocument (JSON Patch - RFC 6902) from comparing to C# objects
using Microsoft.AspNetCore.JsonPatch;
using Microsoft.AspNetCore.JsonPatch.Operations;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
//Based on this: https://blog.abodit.com/posts/2014-05-json-patch-c-implementation/
public static class JsonPatchDocumentDiff
{
using System;
using System.Linq.Expressions;
using System.Reflection;
using System.Collections.Concurrent;
public class ReflectionUtilities
{
private static readonly LockingConcurrentDictionary<PropertyInfo, Func<object, object>> getterCache;
private static readonly LockingConcurrentDictionary<PropertyInfo, Action<object, object>> setterCache;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
public static class TypeActivator
{
/// <summary>
/// Returns an instance of type <typeparamref name="TInstance"/> on which the method is invoked.
/// </summary>
@bymyslf
bymyslf / pre-receive.sh
Last active October 22, 2017 13:12
Git pre-receive hook to check GitVersion (http://gitversion.readthedocs.io/en/latest/) tags in merge message
#!/bin/bash
#
# check commit messages for semantic versioning tags
REGEX="\\+semver:\\s?(breaking|major|feature|minor|fix|patch|none|skip)"
DEFAULT_BRANCH=$(git symbolic-ref HEAD)
ERROR_MSG="[POLICY] The commit message doesn't contains a semantic versioning tag"
while read OLDREV NEWREV REFNAME ; do
if [[ "${REFNAME}" != "${DEFAULT_BRANCH:=refs/heads/master}" ]]; then
@bymyslf
bymyslf / RunSqlScripts.ps1
Created January 25, 2017 14:18
Run SQL Scripts via PowerShell and SqlCmd utility
param
(
[String]$Path,
[String]$Server,
[String]$Database
)
$sqlCmdUtil = "C:\Program Files\Microsoft SQL Server\110\Tools\Binn\SQLCMD.EXE"
Get-ChildItem $Path\*.sql | Sort-Object -Property Name | % { & $sqlCmdUtil -S $Server -d $Database -i $_.FullName -t 750 -l 600 }
@bymyslf
bymyslf / RegisterWatcherToCopy.psm1
Last active January 2, 2017 09:09
PowerShell module to register a FileSystemWatcher to copy files from source folder to destination folder
function Register-Watcher-ToCopy {
param (
[string]$sourceFolder,
[string]$destFolder,
[string]$id
)
$filter = "*.*"
$watcher = New-Object System.IO.FileSystemWatcher $sourceFolder, $filter -Property @{
IncludeSubdirectories = $true
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using System.Web.Http;
public class NotAcceptableResult : IHttpActionResult
{
private readonly HttpRequestMessage request;
@bymyslf
bymyslf / ModelBinderTestsBase.cs
Created October 22, 2016 16:09
Model binder unit test base class
using System.Collections.Specialized;
using System.Web;
using System.Web.Mvc;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
//http://mdavies.net/2013/06/07/unit-testing-mvc3mvc4-model-binders/
public abstract class ModelBinderTestsBase<TBinder, TModel>
where TBinder : IModelBinder, new()
{
using System.Net.Http;
internal class EmptyContent : ByteArrayContent
{
public EmptyContent()
: base(new byte[0])
{
}
}