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 / gist:1251717
Created September 29, 2011 19:39
.NET regexes to extract tags and mentions
static readonly Regex TagsRegex = new Regex(@"(?:(?<=\s)|^)#(\w*[A-Za-z_]+\w*)");
static readonly Regex MentionsRegex = new Regex(@"(?:(?<=\s)|^)\@(\w*[A-Za-z_]+\w*)");
@mookid8000
mookid8000 / gist:1510130
Created December 22, 2011 12:24
Rebus example configuration
var adapter = new MyContainerAdapter(favoriteContainer);
Configure.With(adapter)
.Transport(t => t.UseMsmq("some_input_queue"))
.Serialization(s => s.UseJsonSerializer())
.Sagas(s => s.StoreInSqlServer(connectionstring, "saga_table", "saga_index_table"))
.Subscriptions(s => s.StoreInSqlServer(connectionstring, "subscriptions"))
.SpecifyOrderOfHandlers(h => h.First<SomeType>().Then<AnotherType>())
.Logging(l => l.Log4Net())
.DetermineEndpoints(d => d.FromRebusMappingsSection())
@mookid8000
mookid8000 / gist:1729732
Created February 3, 2012 11:20
AssertIgnorance()
[Test]
public void AssertIgnorance()
{
var ignoredTestCases = Assembly.GetExecutingAssembly().GetTypes()
.SelectMany(t => t.GetMethods())
.Where(m => m.GetCustomAttributes(typeof (IgnoreAttribute), false).Any())
.ToList();
Assert.That(ignoredTestCases.Any(), Is.False, @"The following tests have been IGNORED:
begin transaction
delete 1000 rows
<---- why is it possibly for my other tx to get results about here?
insert bulk 1000 rows
commit transaction
@mookid8000
mookid8000 / gist:2830338
Created May 29, 2012 19:55
StructureMap Rebus registry THAT DOES NOT WORK
public class SomeRegistry : StructureMap.Configuration.DSL.Registry
{
public SomeRegistry()
{
For<ISomething>().Singleton().Use<SomeImplementation>();
For<IDit>().Singletong().Use<Dat>();
// osv....
// og så:
@mookid8000
mookid8000 / gist:3315202
Created August 10, 2012 15:56
Possible MSMQ subqueue thing for Rebus
Configure.With(adapter)
.Transport(t => t.UseMsmqWithSubqueues())
.CreateBus().Start();
//...
<!-- old style: -->
<!-- <rebus inputQueue="someExplicitlyStatedInputQueue" errorQueue="someExplicitlyStatedErrorQueue"> -->
<!-- subq style ('input' and 'error' automagically created beneath this name): -->
@mookid8000
mookid8000 / gist:3829106
Created October 3, 2012 19:10
MongoDB query check
> use test
switched to db test
> db.coll.save({firstName: "Mogens", address:{street: "Torsmark"}})
> db.coll.find()
{ "_id" : ObjectId("506c8cbaac822bf4a75bd2c9"), "firstName" : "Mogens", "address" : { "street" : "Torsmark" } }
> db.coll.find({"firstName": "Mogens"})
{ "_id" : ObjectId("506c8cbaac822bf4a75bd2c9"), "firstName" : "Mogens", "address" : { "street" : "Torsmark" } }
> db.coll.find({"firstName": "Mogens", "address.street": "Torsmark"})
{ "_id" : ObjectId("506c8cbaac822bf4a75bd2c9"), "firstName" : "Mogens", "address" : { "street" : "Torsmark" } }
@mookid8000
mookid8000 / gist:3849308
Created October 7, 2012 19:23
Rebus timeout example
These two can be in the same handler:
public void Handle(SomethingInteresting msg)
{
var correlationId = "possiblySomethingThatMakesSense";
bus.Send(new SomeMessageThatKicksOffSomeProcess { CorrelationId = correlationId });
bus.Defer(TimeSpan.FromMinutes(2), new VerifyThatAllExpectedRepliesWereReceived { CorrelationId = correlationId });
}
public void Handle(VerifyThatAllExpectedRepliesWereReceived msg)
@mookid8000
mookid8000 / gist:3951079
Created October 25, 2012 07:11
SQL datareader
using(var conn = new SqlConnection("server=.;initial catalog=minDatabase;integrated security=sspi"))
{
conn.Open();
using(var cmd = conn.CreateCommand())
{
cmd.CommandText = "select something from whatever";
using(var reader = cmd.ExecuteReader())
{
@mookid8000
mookid8000 / gist:3964165
Created October 27, 2012 10:42
DrugLord.Messages
namespace DrugLord.Messages
{
public class MakeDeposit
{
public Money Money { get; set; }
public Drugs Drugs { get; set; }
public string SecretCode { get; set; }
}
public class Money