Skip to content

Instantly share code, notes, and snippets.

View chilversc's full-sized avatar

Chris Chilvers chilversc

View GitHub Profile
@chilversc
chilversc / target.xml
Last active January 21, 2016 12:28
Target to remove old typescript output files after msbuild. This will remove all javascript files found in the typescript output directory that were not generated by typescript.
<Target Name="TypeScriptCleanOldOutput" DependsOnTargets="PreComputeCompileTypeScript" AfterTargets="Clean;Build" Condition=" '$(TypeScriptOutDir)' != '' ">
<!--
Assumes the TypeScriptOutDir only contains generated code.
If a TypeScript file is deleted from the project the old js file
will remain in the output folder.
Find JS files in the output folder that were not generated by
TypeScript and delete them.
-->
@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 / file.js
Last active December 18, 2015 11:30
addHost() {
var header = { key: this.hostHeaderKey, value: this.hostHeaderValue };
if (!this.hasHeader(header)) {
this.hostHeaders.push(header);
this.hostHeaderKey = '';
this.hostHeaderValue = '';
}
};
hasHeader(header) {
@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 / 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