Skip to content

Instantly share code, notes, and snippets.

View mookid8000's full-sized avatar
💭
Pressing buttons.

Mogens Heller Grabe mookid8000

💭
Pressing buttons.
View GitHub Profile
@mookid8000
mookid8000 / TaskExtensions.cs
Last active April 4, 2017 02:51
ToListAsync task sequence extension for C#
public static class TaskExtensions
{
public static async Task<List<TItem>> ToListAsync<TItem>(this IEnumerable<Task<TItem>> items)
{
var tasks = items.Select(i => i).ToArray();
await Task.WhenAll(tasks);
return tasks.Select(t => t.Result).ToList();
}
}
@mookid8000
mookid8000 / Rebus-Org CLA.md
Last active December 20, 2016 11:01
CLA to be referenced by the CLA assistant

rebus-org Contributor License Agreement

By agreeing to this CLA you acknowledge that you transfer ownership of the code to rebus-org. The code will then carry the same MIT license as the repository to which it was submitted.

In order to do this, you must of course have the right to do so. You acknowledge this too.

@mookid8000
mookid8000 / SubscriberCacheExtensions.cs
Created April 20, 2016 07:14
Subscriber caching extension for Rebus2
public static class SubscriberCacheExtensions
{
public static void EnableSubscriberCache(this OptionsConfigurer configurer)
{
configurer.Decorate<ISubscriptionStorage>(c =>
{
var subscriptionStorage = c.Get<ISubscriptionStorage>();
return new CachingSubscriptionStorage(subscriptionStorage);
});
using System;
using System.Threading;
using System.Threading.Tasks;
using Rebus.Logging;
namespace Rebus.Threading
{
/// <summary>
/// <see cref="Task"/>-based background timer thingie, that will periodically call an async <see cref="Func&lt;Task&gt;"/>
/// </summary>
@mookid8000
mookid8000 / gist:fec9386fddb609b2ab31
Created September 18, 2014 09:39
Rebus sends to nonexistent queue
try
{
var startableBus = Configure.With(new BuiltinContainerAdapter())
.Logging(l => l.None())
.Transport(t => t.UseMsmqInOneWayClientMode())
.CreateBus();
using (var bus = startableBus.Start())
{
bus.Advanced.Routing.Send("NO_CHANCE_THAT_THIS_QUEUE_EXISTS", "hello there!");
@mookid8000
mookid8000 / gist:7536712
Created November 18, 2013 22:43
Service Azure blob with Web API
public async Task<HttpResponseMessage> Get()
{
var blobClient = GetBlobClientFromSomewhere();
var imagesContainer = blobClient.GetContainerReference("images");
var blobRef = await imagesContainer.GetBlobReferenceFromServerAsync(@"cute_cats_70MB.jpg");
var openRead = await blobRef.OpenReadAsync();
var response = new HttpResponseMessage(HttpStatusCode.OK)
Action<MyDomainAssembly.ISubscribeTo<MyDomainAssembly.IDomainEvent>, MyDomainAssembly.IDomainEvent>
dispatchSpecification = (s, e) => s.Handle(e);
Action<MyDomainAssembly.IDomainEvent> myDispatcher =
DomainEvents.Configure.With(someIocContainerAdapter)
.DefineSubscriberAs<MyDomainAssembly.ISubscribeTo<MyDomainAssembly.IDomainEvent>>(dispatchSpecification)
.RegisterSubscribersFromAssemblyContaining<MyDomainAssembly.SomeConcreteSubscriber>(Lifestyle.InstancePerCall)
.RegisterSubscribersFromAssemblyContaining<MyInfrastructureAssembly.AnotherConcreteSubscriber>(Lifestyle.InstancePerCall)
.CreateDispatcher();
Configure.With(...)
.EnableWebCallbacks()
.(...)
// (...)
// just like that
adapter.Bus.Send(new SomeRequest {Message = "hello there!"},
(SomeReply reply) =>
{
@mookid8000
mookid8000 / gist:5149813
Created March 13, 2013 06:37
Any reason why this yields NULL in `SomeIntegerColumn` in the database?
sqlReplicate('SomeTable', {
Id: documentId,
SomeIntegerColumn: 23
});
@mookid8000
mookid8000 / gist:5036740
Last active December 14, 2015 05:39
statically injectable aggregate root loader
public interface ILoadAggregateRoots
{
T Load<T>(string id) where T:Doc;
}
public static class Loader
{
static ILoadAggregateRoots currentLoader = new ThrowMustProvideLoaderException();
public static ILoadAggregateRoots Current