Skip to content

Instantly share code, notes, and snippets.

View BrunoZell's full-sized avatar
🙋‍♀️
async awake

Bruno Zell BrunoZell

🙋‍♀️
async awake
View GitHub Profile
@BrunoZell
BrunoZell / propg.snippet
Created November 18, 2019 04:18
Code snippet for an automatically implemented getter-only property
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>propg</Title>
<Shortcut>propg</Shortcut>
<Description>Code snippet for an automatically implemented getter-only property</Description>
<Author>Bruno Zell</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
@BrunoZell
BrunoZell / propr.snippet
Created November 18, 2019 04:04
Code snippet for an expression bodied property
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>propr</Title>
<Shortcut>propr</Shortcut>
<Description>Code snippet for an expression bodied property</Description>
<Author>Bruno Zell</Author>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
@BrunoZell
BrunoZell / AsyncQueue.cs
Created August 27, 2019 22:00
AsnycQueue implementation using C# 8.0 IAsyncEnumerable
public sealed class AsyncQueue<T> : IAsyncEnumerable<T>, IDisposable
{
private readonly SemaphoreSlim _enumerationSemaphore = new SemaphoreSlim(1);
private readonly BufferBlock<T> _bufferBlock = new BufferBlock<T>();
public void Enqueue(T item) =>
_bufferBlock.Post(item);
public int CurrentCount =>
_bufferBlock.Count;
@BrunoZell
BrunoZell / AsyncEvent.cs
Created August 27, 2019 21:57
An async-compatible event
public sealed class AsyncEvent
{
/// <summary>
/// The object used for synchronization.
/// </summary>
private readonly object _mutex = new object();
/// <summary>
/// The current task to await the next raise of the event.
/// </summary>
@BrunoZell
BrunoZell / LookupJsonConverter.cs
Created August 27, 2019 21:56
Newtonsoft.Json converter for serializing an ILookup<K, T>
public class LookupJsonConverter : JsonConverter
{
public override bool CanConvert(Type objectType) =>
objectType.GetInterfaces()
.Any(a => a.IsGenericType && a.GetGenericTypeDefinition() == typeof(ILookup<,>));
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) =>
throw new NotImplementedException();
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
@BrunoZell
BrunoZell / copy-appsettings.csproj
Last active September 7, 2018 19:13
Entry in csproj to copy all appsettings json files to output.
<ItemGroup>
<CopyAlways Include="appsettings.json" />
<CopyAlways Include="appsettings.*.json" />
<None Update="@(CopyAlways)">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
@BrunoZell
BrunoZell / HostedService.cs
Last active September 7, 2018 13:32 — forked from stevejgordon/HostedService.cs
Generic hosted service in .Net-Core for a long runnig async Task
public abstract class HostedService : IHostedService {
// Code kindly provided by David Fowler: https://gist.github.com/davidfowl/a7dd5064d9dcf35b6eae1a7953d615e3
private Task _executingTask;
private CancellationTokenSource _cts;
public Task StartAsync(CancellationToken cancellationToken)
{
// Create a linked token so we can trigger cancellation outside of this token's cancellation
_cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
@BrunoZell
BrunoZell / .editorconfig
Last active October 7, 2019 04:18
My coding style
# Version: 1.3.2 (Using https://semver.org/)
# Updated: 2019-08-04
# See https://github.com/RehanSaeed/EditorConfig/releases for release notes.
# See https://github.com/RehanSaeed/EditorConfig for updates to this file.
# See http://EditorConfig.org for more information about .editorconfig files.
##########################################
# Common Settings
##########################################
@BrunoZell
BrunoZell / UnixTimestampExtension.cs
Last active September 7, 2018 11:55
Extension method to convert between Unix timestamps and DateTime structs
public static class DateTimeExtensions {
public static DateTime AsUnixTimeMiliseconds(this long miliseconds) =>
new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)
.AddMilliseconds(miliseconds);
public static DateTime AsUnixTimeMiliseconds(this long seconds) =>
new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)
.AddSeconds(seconds);
public static decimal ToUnixTimestamp(this DateTime dateTime) =>
${
using Typewriter.Extensions;
Template(Settings settings) {
settings.IncludeProject("Template.Core");
settings.OutputFilenameFactory = f => "urls-gen.ts";
}
string GetRoute(Constant constant) {