Skip to content

Instantly share code, notes, and snippets.

@thinktainer
thinktainer / gethashcode
Created March 20, 2013 13:45
Efficient hasher
public override int GetHashCode()
{
unchecked // Overflow is fine, just wrap
{
int hash = 17;
// Suitable nullity checks etc, of course :)
hash = hash * 23 + field1.GetHashCode();
hash = hash * 23 + field2.GetHashCode();
hash = hash * 23 + field3.GetHashCode();
return hash;
@thinktainer
thinktainer / gist:5633464
Created May 23, 2013 08:19
IDisposable
public class DisposableClass :
IDisposable
{
bool _disposed;
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
using System;
using System.Collections.Generic;
public class Example
{
public static void Main()
{
int maxPrime = 100;
List<int> primes = GetPrimes(maxPrime);
Console.WriteLine("Primes less than {0}:", maxPrime);
@thinktainer
thinktainer / git_log.sh
Created May 26, 2013 10:20
nice graph for git log
git log --graph --pretty=format':%C(yellow)%h%Cblue%d%Creset %s %C(white) %an, %ar%Creset'
@thinktainer
thinktainer / references.fsx
Created May 31, 2013 11:59
Add references for testing to f# script file
#r @"..\packages\xunit.1.9.1\lib\net20\xunit.dll"
#r @"..\packages\FsUnit.xUnit.1.2.1.2\Lib\Net40\FsUnit.Xunit.dll"
#r @"..\packages\FsUnit.xUnit.1.2.1.2\Lib\Net40\NHamcrest.dll"
#r @"..\packages\xunit.extensions.1.9.1\lib\net20\xunit.extensions.dll"
let Pivot (structure: List<List<'t>>) =
let rows = [0..structure.Length - 1]
let columns = [0..structure.[0].Length - 1]
columns |> List.map(fun c -> rows |> List.map(fun r -> structure.[r].[c]))
@thinktainer
thinktainer / custom_web.config
Last active December 18, 2015 15:19
Custom config section in app.config / web.config
<section name="messageBus" type="System.Configuration.NameValueSectionHandler"/>
var busConfigSection = (NameValueCollection)ConfigurationManager.GetSection("messageBus");
var collectionRootAttr = new XmlRootAttribute("settings");
var collectionRootAttrs = new XmlAttributes { XmlRoot = collectionRootAttr };
var roomTypeIgnoreAttrs = new XmlAttributes { XmlIgnore = true };
var detailsAttrs = new XmlAttributes();
var detailsElement = new XmlElementAttribute("setting");
detailsAttrs.XmlElements.Add(detailsElement);
var langAttrs = new XmlAttributes();
var Page = window.Page || {};
Page.DataParser = function (tableId, rowFormat) {
self.tableId = tableId;
self.rowFormat = rowFormat;
};
// rowformat = [""]
Page.DataParser.prototype = (function () {
@thinktainer
thinktainer / mount.sh
Created June 29, 2013 21:19
mount fileshare in guest
mount -t 9p -o trans=virtio,version=9p2000.L /hostshare /mnt/software