Skip to content

Instantly share code, notes, and snippets.

View hagbarddenstore's full-sized avatar

Kim Johansson hagbarddenstore

View GitHub Profile
" ir_black color scheme
" More at: http://blog.infinitered.com/entries/show/8
" ********************************************************************************
" Standard colors used in all ir_black themes:
" Note, x:x:x are RGB values
"
" normal: #f6f3e8
"
@hagbarddenstore
hagbarddenstore / DatabaseExample.cs
Last active December 10, 2015 15:28
A simple example that shows the principle of opening late and closing early.
public void TheWrongWay()
{
var connection = new SqlConnection(...);
connection.Open();
DoSomethingTimeConsumingThatDoesNotUseTheDatabase();
// execute query
@hagbarddenstore
hagbarddenstore / BookingDomain.cs
Last active December 11, 2015 01:09
A simple domain that can book rooms if a lesson matches the given requirements.
class UnableToBookRoomException : Exception
{
public UnableToBookRoomException()
: base("Unable to book the room")
{
}
}
class Room
{
using System;
using System.Security.Cryptography;
using System.Text;
namespace Example
{
public static class StringExtensions
{
/// <summary>
/// Hash a string with SHA-1.
@hagbarddenstore
hagbarddenstore / ThreadPool.cs
Last active December 11, 2015 08:19
A simple ThreadPool implementation. Not to be used, but to explain the concepts.
class ThreadPool
{
private static readonly object LockObject = new object();
private static readonly Queue<Action> _work = new Queue<Action>();
private static readonly List<Thread> _workers = new List<Thread>();
static ThreadPool()
{
for (var i = 0; i < 5; i++)
{
public static class DictionaryExtensions
{
private static readonly Random Generator = new Random();
public static TValue GetRandom<TKey, TValue>(this IDictionary<TKey, TValue> dictionary)
{
var randomKey = dictionary.Keys.ToList()[Generator.Next(0, dictionary.Keys.Count)];
return dictionary[randomKey];
}
It is popularly believed that Dave Cutler[2] intended the initialism "WNT" as a pun on VMS, incrementing each letter by one. However, the project was originally intended as a follow-on to OS/2 and was referred to as "NT OS/2" before receiving the Windows brand.[3] One of the original NT developers, Mark Lucovsky, states that the name was taken from the original target processor—the Intel i860, code-named N10 ("N-Ten").[4] Various Microsoft publications, including a 1998 question-and-answer session with Bill Gates, reveal that the letters were expanded to "New Technology" for marketing purposes but no longer carry any specific meaning.[5] The letters were dropped from the name of Windows 2000, though Microsoft described the product as "Built on NT technology".
class Component
{
private readonly IDictionary<string, object> _properties = new Dictionary<string, object>();
public Component()
{
}
public Component(IEnumerable<KeyValuePair<string, object>> properties)
{
public static AutoMappingExpression Override<TController>(this AutoMappingExpression autoMappingExpression, string url, Expression<Action<TController>> actionExpression)
{
Assert.ParameterIsNotNull(autoMappingExpression, "mappingExpression");
Assert.ParameterIsNotNull(url, "url");
var methodCallExpression = actionExpression.Body as MethodCallExpression;
if (methodCallExpression == null)
{
throw new ArgumentException("Invalid expression. Expression should consist of a Method call only.");
using System;
namespace Test
{
using System.Linq.Expressions;
class Program
{
static void Main(string[] args)
{