Skip to content

Instantly share code, notes, and snippets.

Avatar

Chris Chilvers chilversc

View GitHub Profile
@chilversc
chilversc / SshTunnel.cs
Created Mar 11, 2015
SSH Tunnel with a dynamically allocated local port in C# using SSH.NET
View SshTunnel.cs
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
Connection to MySql from .net over an SSH tunnel, using http://nuget.org/packages/SSH.NET/
View gist:5575617
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 Dec 8, 2010
NHibernate IUserVersionType for MSSQL rowversion columns
View RowVersionType.cs
public class RowVersionType : IUserVersionType
{
public object Seed(ISessionImplementor session)
{
return 0ul;
}
public object Next(object current, ISessionImplementor session)
{
return current;
View foo.il
.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 Nov 25, 2016
Example showing how blocking the UI thread allows clicks to be received for a 'disabled' button
View form1.cs
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 Oct 25, 2016
Sort msbuild project items
View SortProject.linq
<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 / InstantType.cs
Created Dec 31, 2015
NHibernate NodaTime.OffsetDateTime
View InstantType.cs
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 Apr 22, 2016
webpack bootstrap-switch
View bower.json
{
"private": true,
"name": "temp",
"main": "main.js",
"dependencies": {
"bootstrap": "3.3.6",
"bootstrap-switch": "3.3.2"
}
}
@chilversc
chilversc / test.py
Last active Mar 4, 2016
Sphinx - generate reStructuredText table from directive
View test.py
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 Feb 5, 2016
Automatically reload topshelf service after build
View DevHost.cs
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";