Skip to content

Instantly share code, notes, and snippets.

@jmangelo
jmangelo / VstoAopExceptionHandling.cs
Created February 17, 2010 21:25
Helpers classes for centralized exception handling in a VSTO add-in using PostSharp.
using System;
using log4net;
using PostSharp.Laos;
// http://exceptionalcode.wordpress.com/2010/02/17/centralizing-vsto-add-in-exception-management-with-postsharp/
namespace Helpers.Vsto.ErrorHandling
{
[Serializable]
public sealed class ExecutionEntryPointAttribute : OnExceptionAspect
//Customer is an aggregate root
public class Customer : AggregateRootMappedByConvention
{
//Customer contains orders, each of which is uniquely identified hence is an entity
private readonly List<Order> _orders = new List<Order>();
public void CreateOrder(int id)
{
//Does not create an entity, only publishes event.
//The entity has localy unique id. Its uniqueness is ensured here.
@ToJans
ToJans / 0.Specs.cs
Created February 16, 2011 16:19
An a attempt for a message-less CQRS setup (the idea is messages being generated by the proxy) (CQRS gen2)
using System;
namespace CG2.ExamplePOC
{
public class WithDrawCashContext : WithDrawCashHandler
{
protected Guid CardId = Guid.NewGuid();
protected Guid AccountId = Guid.NewGuid();
protected Guid AtmId = Guid.NewGuid();
}
@trbngr
trbngr / gist:868281
Created March 13, 2011 17:41
Using Entity inside AggregateRoot - NCQRS
public class Order : AggregateRoot
{
private readonly List<OrderItem> orderItems = new List<OrderItem>();
public void UpdateOrderItem(Guid orderItemId, int quantity)
{
var orderItem = orderItems.Where(q => q.EntityId ==
orderItemId).FirstOrDefault();
if (orderItem == null)
@astorm
astorm / gist:992233
Created May 25, 2011 23:29
Fix console.log in Chrome and Magento
<!-- Add to the package layout (via local.xml or however you prefer) -->
<!-- Also, best to remove before deployment, as some users report -->
<!-- it makes IE 7 crash -->
<default>
<reference name="content">
<block type="core/text" name="fix.console" as="fix.console">
<action method="setText">
<text><![CDATA[<script type="text/javascript">
iframe = document.createElement('iframe');
iframe.style.display = 'none';
@tauven
tauven / csv-format-pure.php
Created June 5, 2011 13:36
Convert a simple CSV File with PHP, list of different possible ways how to reformat a simple csv
<?php
$start = microtime(true);
$fpIn = fopen('input.csv', 'r');
$fpOut = fopen('output-pure.csv', 'w');
while (($row = fgets($fpIn)) !== false)
{
$fields = explode(";", $row);
fwrite($fpOut,
@abdullin
abdullin / RedirectToWhen.cs
Created June 26, 2011 08:59
Static helper class for invoking handling methods on AR and AR state.
// snippet is for http://abdullin.com/journal/2011/6/26/event-sourcing-a-la-lokad.html
// simple helper, that looks up and calls the proper overload of
// When(SpecificEventType event). Reflection information is cached statically
// once per type.
public static class RedirectToWhen
{
static class Cache<T>
{
public static readonly IDictionary<Type, MethodInfo> Dict = typeof(T)
/// <summary>
/// Creates convention-based routing rules
/// </summary>
public sealed class RedirectToDynamicCommand
{
readonly IDictionary<Type, Wire> _dict = new Dictionary<Type, Wire>();
sealed class Wire
{
public MethodInfo Method;
@seburgi
seburgi / gist:1607610
Created January 13, 2012 17:21
A wrapper for IAtomicWriter (see Lokad.CQRS.Sample) that calls a provided action after successful updates/deletes
internal class PublishingAtomicWriter<TKey, TEntity> : IAtomicWriter<TKey, TEntity> where TEntity : class
{
private readonly IClientNotificationService _clients;
private readonly IAtomicWriter<TKey, TEntity> _writer;
private readonly Action<TKey, TEntity> _publishAction;
public PublishingAtomicWriter(IAtomicWriter<TKey, TEntity> writer, Action<TKey, TEntity> publishAction)
{
if (publishAction == null) throw new ArgumentNullException("publishAction");
@ScottPhillips
ScottPhillips / .htaccess
Created February 2, 2012 04:30
Common .htaccess Redirects
#301 Redirects for .htaccess
#Redirect a single page:
Redirect 301 /pagename.php http://www.domain.com/pagename.html
#Redirect an entire site:
Redirect 301 / http://www.domain.com/
#Redirect an entire site to a sub folder
Redirect 301 / http://www.domain.com/subfolder/