Skip to content

Instantly share code, notes, and snippets.

@danielwertheim
danielwertheim / AutoMoqDataAttribute.cs
Created February 13, 2022 10:55
Autofixture with AutoMoq
namespace Tests.UnitTests
{
using AutoFixture;
using AutoFixture.AutoMoq;
using AutoFixture.Xunit2;
using System;
public class InlineAutoMoqDataAttribute : InlineAutoDataAttribute
{
public InlineAutoMoqDataAttribute(params object[] objects)
@danielwertheim
danielwertheim / .bashrc
Last active October 24, 2021 12:15
Dev Settings
alias cls=clear
alias gohome='cd $USERPROFILE && clear'
alias godev='cd c:/foo && clear'
alias exp='explorer .'
alias gs='git status'
alias gss='git status -s'
alias gco='git commit -a -m $1'
alias gl='git log --oneline --graph --all --decorate'
alias gm='git merge --no-ff'
alias az='az.cmd'
@danielwertheim
danielwertheim / Program.cs
Created October 29, 2019 13:52
ConcurrentQueue vs Queueu + lock
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Threading.Tasks;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
namespace ConsoleApp2
{
public class Program
@danielwertheim
danielwertheim / RoutemeisterAndAutofac.cs
Last active April 5, 2017 03:34
How to bootstrap Autofac and Routemeister to get per request lifetime scopes. Blog: http://danielwertheim.se/routemeister-and-autofac/
using System;
using System.Threading.Tasks;
using Autofac;
using Routemeister;
using Routemeister.Routers;
namespace ConsoleApplication2
{
class Program
{
@danielwertheim
danielwertheim / app.js
Last active March 21, 2017 19:30
Super simple SPA foundation thingie.
(function (exports) {
var app = exports.app = {
bindingContext: {
domnode: null,
model: null,
loadTemplate: function (templateName) {
return document.getElementById(templateName).innerHTML;
},
bind: function (templateName, vm) {
this.domnode.innerHTML = this.loadTemplate(templateName);
@danielwertheim
danielwertheim / SuperSimpleSample.cs
Last active October 18, 2016 19:59
NATSConsumer
class Program {
static void Main(string[] args)
{
const string subject = "test";
var cnInfo = new ConnectionInfo(new Host("demo.nats.io")) {
AutoRespondToPing = true
};
Action<MsgOp> handler = msg => {
Console.WriteLine("R:" + Encoding.UTF8.GetString(msg.Payload));
@danielwertheim
danielwertheim / NatsConsumerSample.cs
Last active October 16, 2016 14:49
Future sample usage of NatsConsumer
public Task Alternative1() {
var consumer = new NatsConsumer(client);
var subscription = await consumer.SubscribeAsync("mySubject", msg => {
//do something with the message
});
//time goes by
subscription.Dispose(); //issues client.Unsub(subject) against NATS broker as well as removes handler
@danielwertheim
danielwertheim / MediatR_And_Autofac.cs
Last active March 19, 2016 11:48
How not to bootstrap MediatR and Autofac, as it will never release inner dependencies... Pretty much follows this: https://github.com/jbogard/MediatR/blob/master/samples/MediatR.Examples.Autofac/Program.cs
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Autofac;
using Autofac.Features.Variance;
using MediatR;
namespace ConsoleApplication2
{
class Program
@danielwertheim
danielwertheim / MessagePipe.cs
Created March 16, 2016 20:46
Some Owin inspired message pipeline
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
public class MessageEnvelope
{
public object Message { get; }
[Fact]
public void Can_search_on_default_index()
{
var searchRequest = new SearchIndexRequest(CloudantTestData.Views.Views101AnimalsSearchIndexId)
.Configure(q => q.Expression("kookaburra"));
var response = SUT.SearchAsync(searchRequest).Result;
response.Should().BeSuccessfulGet(numOfRows: 1);
response.Bookmark.Should().NotBeNullOrEmpty();