Skip to content

Instantly share code, notes, and snippets.

View chilversc's full-sized avatar

Chris Chilvers chilversc

View GitHub Profile
@chilversc
chilversc / form1.cs
Created November 25, 2016 13:35
Example showing how blocking the UI thread allows clicks to be received for a 'disabled' button
using System;
using System.Threading;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
[STAThread]
static void Main()
@chilversc
chilversc / SortProject.linq
Created October 25, 2016 15:26
Sort msbuild project items
<Query Kind="Program" />
static XNamespace ns = "http://schemas.microsoft.com/developer/msbuild/2003";
static XName ItemGroup = ns + "ItemGroup";
static XName Reference = ns + "Reference";
static XName ProjectReference = ns + "ProjectReference";
static XName Condition = "Condition";
static XName Include = "Include";
static XName OutputType = ns + "OutputType";
static XName Folder = ns + "Folder";
@chilversc
chilversc / bower.json
Created April 22, 2016 14:36
webpack bootstrap-switch
{
"private": true,
"name": "temp",
"main": "main.js",
"dependencies": {
"bootstrap": "3.3.6",
"bootstrap-switch": "3.3.2"
}
}
@chilversc
chilversc / test.py
Last active March 4, 2016 16:46
Sphinx - generate reStructuredText table from directive
from docutils import nodes, core, io
from docutils.parsers.rst import Directive
def setup(app):
app.add_directive('test', TestDirective)
return {'version': '0.1'}
class TestDirective(Directive):
def run(self):
table = nodes.table(cols=2)
@chilversc
chilversc / DevHost.cs
Last active February 5, 2016 19:49
Automatically reload topshelf service after build
using System;
using System.IO;
using System.Threading;
using System.Diagnostics;
using System.Runtime.InteropServices;
class Program
{
const string exe = "Server.exe";
const string config = exe + ".config";
@chilversc
chilversc / InstantType.cs
Created December 31, 2015 08:59
NHibernate NodaTime.OffsetDateTime
using System;
using System.Data;
using NHibernate;
using NHibernate.SqlTypes;
using NHibernate.UserTypes;
using NodaTime;
[Serializable]
public class InstantType : IUserType
{
@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 / 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 / Description.md
Created July 15, 2015 11:32
ASP.Net MVC - Choose method to handle action based upon query string parameters

The scenario is a some external legacy code is accessing the site. In the past the request was handled by an IHttpHandler that dispatched to different private methods to handle the request based upon query string parameters.

The goal is to replace the IHttpHandler with a standard MVC controller.

  • The different requests should go to different methods.
  • We want to retain the standard MVC parameter binding.
  • We do not want one action with lots of parameters, many of which are unrelated.
@chilversc
chilversc / gist:2a1da3e6bc5689f89f9d
Last active August 29, 2015 14:18
Bootstrap, overriding tables with cascading styles is too verbose
/*
Due to boostrap's high specificity on td styles
I cannot see a shorter method to override this.
*/
.table.vert-align-mid > thead > tr > td,
.table.vert-align-mid > thead > tr > th,
.table.vert-align-mid > tbody > tr > td,
.table.vert-align-mid > tbody > tr > th,
.table.vert-align-mid > tfoot > tr > td,