Skip to content

Instantly share code, notes, and snippets.

View gist:fb5dd88838b57ca27107
public class HashedUrl
private readonly string _secretKey;
private readonly string _urlToHash;
private readonly DateTime _startDate;
private readonly DateTime _endDate;
/// <summary>
/// Hash a url
/// </summary>
cairey / MouseEnterIntent.cs
Created August 26, 2011 10:56
Just like Hover Intent in JQuery, this is Hover Intent Behavior for Silverlight. See "Read Me" below.
View MouseEnterIntent.cs
public class MouseEnterIntent
public static readonly DependencyProperty CommandProperty =
DependencyProperty.RegisterAttached("Command", typeof(ICommand), typeof(MouseEnterIntent), new PropertyMetadata(OnSetCommandCallback));
public static readonly DependencyProperty CommandParameterProperty =
DependencyProperty.RegisterAttached("CommandParameter", typeof(object), typeof(MouseEnterIntent), new PropertyMetadata(OnSetCommandParameterCallback));
public static readonly DependencyProperty MouseEnterIntentCommandBehaviorProperty =
DependencyProperty.RegisterAttached("HoverIntentCommandBehavior", typeof(MouseEnterIntentCommandBehavior), typeof(MouseEnterIntent), null);
cairey / CommandHandlerFactory.cs
Created July 20, 2012 15:13
Command pattern using MEF
View CommandHandlerFactory.cs
public class CommandHandlerFactory : ICommandHandlerFactory
private readonly IEnumerable<ICommandHandler> _commandHandlers;
public CommandHandlerFactory([ImportMany]IEnumerable<ICommandHandler> commandHandlers)
_commandHandlers = commandHandlers;
cairey / DragOverControlToCommandBehavior.cs
Created July 20, 2012 15:07
Drag over control to command bahvior
View DragOverControlToCommandBehavior.cs
public class DragOverControlToCommandBehavior : CommandBehaviorBase<Control>
public DragOverControlToCommandBehavior(Control element)
: base(element)
element.AllowDrop = true;
element.DragOver += ElementDragOver;
private void ElementDragOver(object sender, DragEventArgs e)
cairey / LogInterceptor.cs
Created July 20, 2012 15:22
Aspect Oriented Programming with MEF using the interceptors. Compose an interceptor catalog in the example below
View LogInterceptor.cs
public class LogInterceptor : IInterceptor
public void Intercept(IInvocation invocation)
if(invocation.TargetType.GetCustomAttributes(typeof(LogMethodCallsAttribute), true).Length > 0)
var loggerFacade = MefInstanceProvider.Container.GetExportedValue<ILoggerFacade>();
loggerFacade.Log(FormatMethodCall(invocation, ApplicationStates.Started), Category.Info, Priority.Low);
cairey / Literal.cs
Created October 19, 2012 09:05
Literal of an expression at runtime. Handy for property change notifications i.e Literal.Of(() => MyProperty)
View Literal.cs
public static class Literal
private static string GetMemberName(Expression expression)
switch (expression.NodeType)
case ExpressionType.MemberAccess:
var memberExpression = (MemberExpression)expression;
var supername = GetMemberName(memberExpression.Expression);
cairey / UnitOfWorkBehaviorAttribute.cs
Created October 19, 2012 09:12
WCF Unit of work Behavior
View UnitOfWorkBehaviorAttribute.cs
public class UnitOfWorkBehaviorAttribute : Attribute, IContractBehavior, IContractBehaviorAttribute
public void Validate(ContractDescription contractDescription, ServiceEndpoint endpoint)
{ }
public void ApplyDispatchBehavior(ContractDescription contractDescription, ServiceEndpoint endpoint, DispatchRuntime dispatchRuntime)
foreach(var operation in dispatchRuntime.EndpointDispatcher.DispatchRuntime.Operations)
operation.CallContextInitializers.Add(new PCMUnitOfWorkCallContextInitializer());
cairey / gist:3917111
Created October 19, 2012 09:14
MSTestContrib BDD Extensions
View gist:3917111
namespace MSTestContrib.Specifications
public static class BDDExtensions
public static ThenGrammar Then(this WhenGrammar whenGrammar, string description, Action<SpecificationContext> implementation)
Func<SpecificationContext, bool> implementationWithReturnTrue = (x) =>
return true;
cairey / offset_from_timecode.rb
Created February 7, 2016 10:59
Grab an offset in seconds from a UTC timecode on a Unified Streaming Server. Takes it to account encoder reconnects / restarts. This is the Ruby version.
View offset_from_timecode.rb
def offset_from_timecode (nokogiri_doc, start_pos_utc, in_point_utc)
video_el ='video').first
c_els = video_el.css('c')
final_c_els = []
total_seconds = 0
start_pos_time = Time.parse(start_pos_utc.to_s)
c_els.each do |c_el|
end_of_c_utc = DateTime.parse(c_el['end'])
final_c_els << c_el if end_of_c_utc > in_point_utc
cairey / OffsetFromTimecode.cs
Created February 7, 2016 10:59
Grab an offset in seconds from a UTC timecode on a Unified Streaming Server. Takes it to account encoder reconnects / restarts. This is the C# version.
View OffsetFromTimecode.cs
public double GetOffsetFromTimecode(Guid eventId, DateTime startPos, DateTime inPoint)
startPos = startPos.ToUniversalTime();
inPoint = inPoint.ToUniversalTime();
var ismUrl = _configuration.GenerateIsmStreamUrl(eventId);
var streamUrl = ismUrl + "/archive";
var doc = XDocument.Load(streamUrl);
var videoEl = doc.Descendants().First(x => x.Name.LocalName == "video");