Skip to content

Instantly share code, notes, and snippets.

View danbarua's full-sized avatar

Dan Barua danbarua

  • GSK
  • United Kingdom
View GitHub Profile
using System.Collections.Generic;
using System.Linq;
using NHibernate.Criterion;
using ServiceStack.Common;
using ServiceStack.NH.Core.Domain;
using ServiceStack.ServiceInterface;
using ServiceStack.ServiceInterface.ServiceModel;
namespace ServiceStack.NH.Web.App_Start
{
@danbarua
danbarua / gist:3528413
Created August 30, 2012 13:21
RabbitMQ reliable consumer pattern
while (_isRunning)
{
try
{
if (channel == null || consumer == null)
{
try
{
_connection = factory.CreateConnection();
channel = _connection.CreateModel();
@danbarua
danbarua / gist:5356062
Last active November 23, 2016 06:22 — forked from HasAndries/gist:3135128
AngularJs directive for Bootstrap datepicker
angular.module('bDatepicker', []).
directive('bDatepicker', function(){
return {
require: '?ngModel',
restrict: 'A',
link: function ($scope, element, attrs, controller) {
var updateModel, onblur;
if (controller != null) {
@danbarua
danbarua / RedisTextSearchExtensions.cs
Created April 23, 2013 10:10
Simple text search with ServiceStack.Redis, based on Antirez's 'AutoComplete with Redis' post http://oldblog.antirez.com/post/autocomplete-with-redis.html Add POCOs to the index like this: client.AddToTextIndex(dto, x => x.Name, x => x.Address); and search like this: client.SearchText<TModel>("foo");
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using ServiceStack.Common.Utils;
using ServiceStack.Redis;
using ServiceStack.Text;
namespace RedisSearch
{
@danbarua
danbarua / gist:6249022
Created August 16, 2013 11:04
Redis request logger for ServiceStack
using System;
using System.Collections.Generic;
using System.Linq;
using ServiceStack.Common.Web;
using ServiceStack.Redis;
using ServiceStack.ServiceHost;
using ServiceStack.ServiceInterface;
using ServiceStack.ServiceInterface.Providers;
using ServiceStack.ServiceInterface.ServiceModel;
using ServiceStack.ServiceModel;
@danbarua
danbarua / gist:6520603
Created September 11, 2013 08:05
Custom version of EasyNetQ's AutoSubscriber
namespace Foo.Common.Messaging.EasyNetQ
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
@danbarua
danbarua / rakefile.rb
Created February 10, 2014 13:26
Albacore task to verify projects have StyleCop.MSBuild set up properly
desc "Checks .csproj files for StyleCop.MSBuild target"
task :verify_stylecop_msbuild do
projectFiles = FileList["./**/*.csproj"]
projectFiles.each{|f|
doc = Nokogiri::XML(File.open(f))
target = doc.css('PropertyGroup > StyleCopMSBuildTargetsFile')
if (target.empty?)
puts "#{f} has no stylecop.msbuild"
else
puts "#{f} is ok"
@danbarua
danbarua / ObservableExtensions.cs
Created February 18, 2014 15:32
Reactive Freeswitch ESL Parsing
/// <summary>The observable extensions.</summary>
public static class ObservableExtensions
{
/// <summary>Aggregates a Stream using the supplied Aggregator until the given predicate is true</summary>
/// <param name="source">The source.</param>
/// <param name="seed">The seed.</param>
/// <param name="accumulator">The accumulator.</param>
/// <param name="predicate">A predicate which indicates whether the aggregation is completed.</param>
/// <typeparam name="TSource">The Type of the Source stream.</typeparam>
/// <typeparam name="TAccumulate">The Type of the Accumulator.</typeparam>
@danbarua
danbarua / SystemDateTime.cs
Created April 4, 2014 12:39
SystemDateTime - a mockable implementation of System.DateTime.Now
/// <summary>
/// Provides a mockable implementation of System.DateTime.Now;
/// </summary>
public static class SystemDateTime
{
private static readonly Func<DateTime> DefaultProvider = () => DateTime.Now;
[ThreadStatic]
private static Func<DateTime> dateTimeProvider;
@danbarua
danbarua / gist:9cdf1601b678081aeef0
Last active August 29, 2015 14:01
Testing in Nancy
public class CreateUserValidator : AbstractValidator<CreateUser>
{
public CreateUserValidator(IUserRepository repository)
{
this.RuleFor(x => x.UserName)
.NotEmpty()
.Length(1, 255);
this.RuleFor(x => x.UserName)
.Must(x => x != null && !x.Any(char.IsWhiteSpace))