Skip to content

Instantly share code, notes, and snippets.

View haf's full-sized avatar
💹
currently succeeding...

Henrik Feldt haf

💹
currently succeeding...
View GitHub Profile
@haf
haf / unit-test-ruby
Created June 15, 2011 10:34
How to unit-test exec_get/getter.call
class StrQ < Q
attr_accessor :default
def initialize(question, default = nil, io_source = STDIN, validator = nil)
@question = question
@default = default
@io_source = io_source
@validator = validator || lambda { true }
end
@haf
haf / Colourized PowerShell
Created October 25, 2011 16:18
Colourized PowerShell ls command
#First in your powershell profile in
#C:\Users\<<username>>\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
set-location D:\code
. "C:\Users\<<username>>\Documents\WindowsPowerShell\Get-ChildItemColor.ps1" # read the colourized ls
set-alias ls Get-ChildItemColor -force -option allscope
function Get-ChildItem-Force { ls -Force }
set-alias la Get-ChildItem-Force -option allscope
#Then in:
@haf
haf / sh64.cs
Created January 3, 2012 14:11
Console output with C#
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
namespace ConsoleApplication1
{
class App
{
@haf
haf / bash
Created January 3, 2012 16:11
Installing graphite Ubuntu 11.10
####################################
# BASIC REQUIREMENTS
# http://graphite.wikidot.com/installation
# http://geek.michaelgrace.org/2011/09/how-to-install-graphite-on-ubuntu/
# Last tested & updated 10/13/2011
####################################
sudo apt-get update
sudo apt-get upgrade
@haf
haf / gist:1557425
Created January 3, 2012 22:59
C# snippet for Graphite
// Create an UDP client for sending metrics to "localhost:2003", prefixing all keys with "foo.bar"
using(var client = new GraphiteUdpClient("192.168.1.45", 2003, "jayway.letslog"))
{
// Report a metric
client.Send("baz", 10);
// Report a metric specifying timestamp
client.Send("baz", 21, DateTime.UtcNow.AddSeconds(42));
}
@haf
haf / ESSagaRepo.cs
Created January 17, 2012 16:03
Spike MassTransit EventStore Saga Repo
// Copyright 2007-2011 Henrik Feldt
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use
// this file except in compliance with the License. You may obtain a copy of the
// License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed
// under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
@haf
haf / gist:1869125
Created February 20, 2012 13:12
Microsoft Exception Handling
// SecuritySafeCritical because it references MessageLockLostException, MessagingCommunicationException,
// MessagingEntityAlreadyExistsException, MessagingEntityNotFoundException, ServerBusyException, ServerErrorException
[SecuritySafeCritical]
private static bool CheckIsTransient(Exception ex)
{
if (ex is FaultException)
{
return false;
}
else if (ex is MessagingEntityNotFoundException)
@haf
haf / gist:1869140
Created February 20, 2012 13:14
Code Standards Say Long Parameter Names Are Easier
/// <summary>
/// Initializes a new instance of the <see cref="RetryManagerImpl"/> class.
/// </summary>
/// <param name="retryStrategies">The complete set of retry strategy.</param>
/// <param name="defaultRetryStrategyName">The default retry strategy.</param>
/// <param name="defaultSqlConnectionStrategyName">The default retry strategy for SQL connections.</param>
/// <param name="defaultSqlCommandStrategyName">The default retry strategy for SQL commands.</param>
/// <param name="defaultAzureServiceBusStrategyName">The default retry strategy for Windows Azure Service Bus.</param>
/// <param name="defaultAzureCachingStrategyName">The default retry strategy for Windows Azure Caching.</param>
/// <param name="defaultAzureStorageStrategyName">The default retry strategy for Windows Azure Storage.</param>
@haf
haf / gist:1869638
Created February 20, 2012 15:19
Asynchronous Retries MassTransit
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Threading;
using System.Threading.Tasks;
using System.Linq;
using Magnum.Extensions;
using Magnum.Policies;
using MassTransit.Context;
using NUnit.Framework;
@haf
haf / gist:1883349
Created February 22, 2012 08:03
Dot-source PowerShell
. $PROFILE