Skip to content

Instantly share code, notes, and snippets.

View sandcastle's full-sized avatar
🍦

Glenn Morton sandcastle

🍦
View GitHub Profile
@sandcastle
sandcastle / AsyncHelpers.cs
Created January 24, 2013 16:30
Async helper methods for ensure exceptions are raised and unwrapped if possible.
/// <summary>
/// Helper methods for ensure exceptions are raised and unwrapped if possible.
/// </summary>
public static class AsyncHelpers
{
/// <summary>
/// Returns the result of the task, if a single exception is found it unwraps, otherwise throws the aggregate.
/// </summary>
/// <typeparam name="T">The type of the result the task returns.</typeparam>
/// <param name="task">The task.</param>
@sandcastle
sandcastle / Bootstrapper.cs
Created April 1, 2013 05:30
Proposed mapping layer for serilog.
// Single registration
Log.Logger = new LoggerConfiguration()
.WithConsoleSink()
.WithMap(new HttpRequestMessageMap())
.CreateLogger();
// Assembly scan
Log.Logger = new LoggerConfiguration()
.WithConsoleSink()
.WithMapsFromAssembly(typeof(Bootstrapper).Assembly)
@sandcastle
sandcastle / DisposableTimer.cs
Last active December 15, 2015 16:59
Simplified version of a logging project that captures multiple timing properties for a log entry using a DisposableTimer.
public class DisposableTimer : IDisposable
{
readonly string _name;
readonly IDelayedLogBuilder _logBuilder;
readonly Stopwatch _stopwatch;
internal DisposableTimer(IDelayedLogBuilder logBuilder, string name)
{
_name = name;
_logBuilder = logBuilder;
@sandcastle
sandcastle / install-es.sh
Last active January 2, 2016 19:39
Script to install Elastic Search v1.1.1 on Ubuntu 14.04.
cd ~
sudo apt-get update
sudo apt-get install openjdk-7-jre-headless -y
### Check http://www.elasticsearch.org/download/ for latest version of ElasticSearch and replace wget link below
# download and install
wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.1.1.deb
sudo dpkg -i elasticsearch-1.1.1.deb
@sandcastle
sandcastle / CaseInsensitiveExpando.cs
Last active January 4, 2016 19:29
a case in-sensitive dynamic object.
public class CaseInsensitiveExpando : DynamicObject, IDictionary<string, object>
{
readonly IDictionary<string, object> _dictionary = new Dictionary<string, object>(StringComparer.InvariantCultureIgnoreCase);
public int Count
{
get { return this._dictionary.Keys.Count; }
}
public bool IsReadOnly
@sandcastle
sandcastle / company-slug.js
Created February 9, 2014 00:45
Converts a company name into a site slug - for SaaS applications.
/**
* Converts a company name into a site slug.
* @param {String} value
* @returns {string}
*/
var createSlug = function(value) {
if (_.isEmpty(value)) { //lodash call
return '';
}
@sandcastle
sandcastle / node.sh
Created February 26, 2014 23:16
Setup file for node.js 0.10.* on Ubuntu 12.04
# https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager
sudo apt-get update
sudo apt-get install -y python-software-properties python g++ make
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get --purge remove node
sudo apt-get --purge remove nodejs
sudo apt-get install nodejs
@sandcastle
sandcastle / app.sh
Created February 26, 2014 23:23
Script to be able to build source on Ubuntu 12.04
sudo apt-get install git
sudo apt-get install npm
npm install -g bower
npm install
bower install
@sandcastle
sandcastle / install-teamcity.md
Last active December 7, 2023 18:02
Install TeamCity 9.0.3 on Ubuntu with Nginx
@sandcastle
sandcastle / QueryStringBuilder.cs
Created March 19, 2014 14:03
Simple query string builder for clients.
public class QueryStringBuilder : NameValueCollection
{
public QueryStringBuilder()
: base(StringComparer.InvariantCultureIgnoreCase) { }
public QueryStringBuilder(NameValueCollection collection)
: base(StringComparer.InvariantCultureIgnoreCase)
{
Add(collection);
}