Skip to content

Instantly share code, notes, and snippets.

View bymyslf's full-sized avatar

Luís Barbosa bymyslf

View GitHub Profile
@bymyslf
bymyslf / settings.json
Last active December 29, 2021 14:36
Windows Terminal Settings
// This file was initially generated by Windows Terminal 1.7.1091.0
// It should still be usable in newer versions, but newer versions might have additional
// settings, help text, or changes that you will not see unless you clear this file
// and let us generate a new one for you.
// To view the default settings, hold "alt" while clicking on the "Settings" button.
// For documentation on these settings, see: https://aka.ms/terminal-documentation
{
"$schema": "https://aka.ms/terminal-profiles-schema",
@bymyslf
bymyslf / IJobQueue.cs
Created April 9, 2021 13:09
Redis Job Queue
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
public interface IJobQueue
{
Task Finish(string key, CancellationToken cancellationToken = default);
Task Requeue(string key, CancellationToken cancellationToken = default);
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
public class SqlScriptMigrator
@bymyslf
bymyslf / Either.cs
Created April 7, 2020 16:23
C# Either Monad
using System;
public class Either<TLeft, TRight>
{
private readonly TLeft left;
private readonly TRight right;
private readonly bool isLeft;
public Either(TLeft left)
{
@bymyslf
bymyslf / TaskExtensions.cs
Last active February 21, 2021 14:51
Useful task extensions
namespace System.Threading.Tasks
{
using System;
using System.Runtime.CompilerServices;
using System.Threading;
/// <summary>
/// Extensions on Task and Task<T>.
/// </summary>
public static class TaskExtensions
@bymyslf
bymyslf / StreamAssert.cs
Created January 9, 2020 08:55
Compare streams
public static class StreamAssert
{
public static bool AreEquivalent<T>(T left, T right)
where T : Stream
{
int file1byte;
int file2byte;
if (left == right)
{
@bymyslf
bymyslf / .gitconfig
Last active October 12, 2022 08:28
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
@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)
using System;
using System.IO;
public sealed class TempDirectory : IDisposable
{
private string _path;
public TempDirectory()
: this(System.IO.Path.GetTempFileName())
{
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
public class ConflictObjectResult : ObjectResult
{
public ConflictObjectResult(string detail)
: base(detail)
=> StatusCode = StatusCodes.Status409Conflict;
}