Skip to content

Instantly share code, notes, and snippets.

@antonydenyer
antonydenyer / gist:3225770
Created August 1, 2012 10:52
should be able to unit test Nest.ElasticClient
var settings = A.Fake<IConnectionSettings>();
var connection = A.Fake<IConnection>();
A.CallTo(() => settings.DefaultIndex).Returns("nest_test_data");
var value = new ConnectionStatus(File.ReadAllText(@"InversionOfControl.json"));
A.CallTo(() =>
connection.PostSync(
A<string>.That.Contains("nest_test_data/elasticsearchprojects/_search"),
@antonydenyer
antonydenyer / gist:3697427
Created September 11, 2012 10:21
Run All Sql in a directory
@echo on
set DbName="db_name"
for %%i in (*.sql) do sqlcmd -E -S localhost -d %DbName% -i %%i
@antonydenyer
antonydenyer / gist:3755395
Created September 20, 2012 11:34
nginx mono ServiceStack
server_names_hash_bucket_size 256;
server {
listen 80; ## listen for ipv4
server_name _;
access_log /home/dev/www/logs/localhost.access.log;
location / {
root /home/dev/www/current;
@antonydenyer
antonydenyer / gist:3755430
Created September 20, 2012 11:40
ServiceStack SevenDigitalAppHost
public abstract class SevenDigitalAppHost : AppHostBase
{
protected SevenDigitalAppHost(string serviceName, params Assembly[] assembliesWithServices)
: base(serviceName, assembliesWithServices)
{
JsConfig.EmitCamelCaseNames = true;
JsConfig.DateHandler = JsonDateHandler.ISO8601;
Plugins.RemoveAll(x => x is AuthFeature);
Plugins.RemoveAll(x => x is SessionFeature);
@antonydenyer
antonydenyer / gist:3755449
Created September 20, 2012 11:45
running mono service
run "nohup fastcgi-mono-server4 /applications=/:#{latest_release} /filename=/tmp/SOCK-#{fqdn} /socket=unix >/dev/null 2>&1&"
@antonydenyer
antonydenyer / gist:3755475
Created September 20, 2012 11:54
StatsD ServiceStack request timing Feature
public class StatsDFeature : IPlugin
{
private readonly Statsd _client;
private readonly string _statNamePrefix;
public StatsDFeature(IStatsd client, string statNamePrefix)
{
if (client == null)
throw new ArgumentNullException("client", "client instance must be specified");
@antonydenyer
antonydenyer / gist:3755906
Created September 20, 2012 13:28
RestServiceBase override
public abstract class RestServiceBase<TRequest> : global::ServiceStack.ServiceInterface.RestServiceBase<TRequest>
{
private IErrorResponseFactory _errorResponseFactory;
private IErrorResponseFactory ErrorResponseFactory
{
get { return _errorResponseFactory ?? (_errorResponseFactory = new ErrorResponseFactory()); }
set { _errorResponseFactory = value; }
}
private static readonly ILog Log = LogManager.GetLogger(typeof(ServiceBase<>));
@antonydenyer
antonydenyer / gist:3755929
Created September 20, 2012 13:30
ServiceStack ErrorResponseFactory
public interface IErrorResponseFactory
{
object CreateErrorResponse<TRequest>(TRequest request, Exception ex, ResponseStatus responseStatus);
object CreateErrorResponse<TRequest>(TRequest request, ValidationErrorResult validationError);
}
public class ErrorResponseFactory : IErrorResponseFactory
{
public object CreateErrorResponse<TRequest>(TRequest request, ValidationErrorResult validationError)
@antonydenyer
antonydenyer / gist:3756013
Created September 20, 2012 13:45
ValidationFeature ServiceStack
public class ValidationFeature : IPlugin
{
private readonly IErrorResponseFactory _errorResponseFactory;
public ValidationFeature(IErrorResponseFactory errorResponseFactory)
{
_errorResponseFactory = errorResponseFactory;
}
public static bool Enabled { private set; get; }
@antonydenyer
antonydenyer / gist:3760738
Created September 21, 2012 10:07
Capistrano depoly mono with fastcgi
set :stages, %w(devtest systest uat prod)
set :default_stage, "devtest"
set :keep_releases, 5
require 'capistrano/ext/multistage'
require 'nokogiri'
set :use_sudo, false
set :normalize_asset_timestamps, false