Skip to content

Instantly share code, notes, and snippets.

View bymyslf's full-sized avatar

Luís Barbosa bymyslf

View GitHub Profile
@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 / 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
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>
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;
@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 Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
public class FailedPreconditionObjectResult : ObjectResult
{
public FailedPreconditionObjectResult(string detail)
: base(detail)
=> StatusCode = StatusCodes.Status412PreconditionFailed;
}
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
public class ConflictObjectResult : ObjectResult
{
public ConflictObjectResult(string detail)
: base(detail)
=> StatusCode = StatusCodes.Status409Conflict;
}
using System;
using System.IO;
public sealed class TempDirectory : IDisposable
{
private string _path;
public TempDirectory()
: this(System.IO.Path.GetTempFileName())
{
@bymyslf
bymyslf / post-merge.sh
Created January 10, 2019 12:39
Git post-merge hook to delete merged branch
#!/bin/bash
# Based on: https://github.com/brianstorti/git-hooks/blob/master/hooks/post-merge
exec < /dev/tty
# Merge can go three ways:
# * F: fast forward: no commit is created, only a ref is changed
# * A: automatic: true merge (non-ff) without conflicts. A new commit is created
# * C: merge with conflicts: no commit is created but the index is prepared (partially)
@bymyslf
bymyslf / .gitconfig
Last active March 20, 2026 21:39
Useful git aliases
[alias]
co = checkout
sw = switch
st = status
unstage = reset HEAD --
last = log -1 HEAD
cln = clean -n
clf = clean -f
cli = clean -i
clfx = clean -fx