Skip to content

Instantly share code, notes, and snippets.

View chilversc's full-sized avatar

Chris Chilvers chilversc

View GitHub Profile
@chilversc
chilversc / gist:8581320
Created January 23, 2014 16:09
Contiguous segments
#define NONEST
void Main()
{
Sample1 ();
Sample2 ();
}
void Sample1 ()
{
@chilversc
chilversc / gist:8577648
Last active January 4, 2016 05:49
combining adjacent ranges
#define NONEST
void Main()
{
Sample1 ();
Sample2 ();
}
void Sample1 ()
{
@chilversc
chilversc / alternate.css
Last active December 27, 2015 18:19
Support multiple prefix/suffix addons in an input group using Twitter Bootstrap, http://jsfiddle.net/gh/gist/library/pure/7369380/
/*
if instead of
.input-group-addon:last-child {
border-left: 0;
}
this is used
.input-group-addon:last-child {
border-left-style: none;
}
@chilversc
chilversc / compare-migrations.sh
Created June 27, 2013 14:00
Lists new/removed migration scripts/directories between 2 commits in git
#!/bin/sh
DBDIR="Database/Migrations"
FROM="$1"
TO="$2"
function usage() {
echo "Usage: $0 <from-commit> [<to-commit>]"
echo " <from-commit>: Optional, the earlier commit, defaults to the latest tag from the current branch"
echo " <to-commit> : Optional, the newer commit, defaults to HEAD"
@chilversc
chilversc / gist:5731769
Created June 7, 2013 19:30
Helper class to allow comparing part of a key in linq groupby/join operations using a specific comparer
/* Usage:
source.GroupBy (x => new {
x.TeamId,
x.Name.CompareUsing (StringComparer.OrdinalIgnoreCase)
})
*/
public struct KeyPart<T> : IEquatable<KeyPart<T>>
{
private readonly IEqualityComparer<T> comparer;
@chilversc
chilversc / gist:5643278
Created May 24, 2013 12:49
Specify field order for CsvHelper when writing
static void WriteCsv<T> (IEnumerable<T> data, string file, params string[] fields)
{
var writerType = typeof (CsvWriter);
var writerParam = Expression.Parameter (writerType, "writer");
var itemType = typeof (T);
var itemParam = Expression.Parameter (itemType, "item");
var fieldWriters = new List<Action<CsvWriter, T>> ();
foreach (var name in fields) {
var value = Expression.PropertyOrField (itemParam, name);
@chilversc
chilversc / gist:5575617
Created May 14, 2013 12:47
Connection to MySql from .net over an SSH tunnel, using http://nuget.org/packages/SSH.NET/
void Test()
{
var ci = new ConnectionInfo ("remoteserver", "remoteuser", new PasswordAuthenticationMethod ("remoteuser", "password"));
var cs = new MySqlConnectionStringBuilder ();
cs.AllowBatch = true;
cs.Server = "127.0.0.1";
cs.Database = "database";
cs.UserID = "dbuser";
cs.Password = "dbpassword";
@chilversc
chilversc / Example.cshtml
Last active December 16, 2015 03:39
Simple indexed prefix for razor foreach loop
@foreach (var item in Html.Prefix(Model.Results, "result")) {
<label for="@Html.Id("comment")>Comment</label>
@Html.TextArea("comment", item.Comment)
}
@using (Html.Prefix("test")) {
<label for="@Html.Id("nested")">Nested</label>
@Html.TextArea("nested")
}
@chilversc
chilversc / README.md
Last active December 15, 2015 11:48
Format observable as a number with a specific precision
@chilversc
chilversc / gist:5100296
Created March 6, 2013 15:52
NHibernate Contains query bug - mutating a collection after a query has executed breaks queries in subsequent sessions
[Test]
public void UsersWithListContains_MutatingListDoesNotBreakOtherSessions()
{
using (var firstSession = OpenSession ()) {
var names = new List<string> { "ayende", "rahien" };
var query = (from user in firstSession.Query<User> ()
where names.Contains(user.Name)
select user).ToList();