Skip to content

Instantly share code, notes, and snippets.

View chilversc's full-sized avatar

Chris Chilvers chilversc

View GitHub Profile
@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 / SshTunnel.cs
Created March 11, 2015 16:59
SSH Tunnel with a dynamically allocated local port in C# using SSH.NET
class SshTunnel : IDisposable
{
private SshClient client;
private ForwardedPortLocal port;
private int localPort;
public SshTunnel (ConnectionInfo connectionInfo, uint remotePort)
{
try {
client = new SshClient (connectionInfo);
@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 / RowVersionType.cs
Created December 8, 2010 16:50
NHibernate IUserVersionType for MSSQL rowversion columns
public class RowVersionType : IUserVersionType
{
public object Seed(ISessionImplementor session)
{
return 0ul;
}
public object Next(object current, ISessionImplementor session)
{
return current;
.class interface private abstract auto ansi IBob
{
.method public newslot abstract strict virtual
instance void Foo() cil managed
{
} // end of method IBob::Foo
.method public newslot abstract strict virtual
instance void Bar() cil managed
{
@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 / 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 / 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";