Skip to content

Instantly share code, notes, and snippets.

View chilversc's full-sized avatar

Chris Chilvers chilversc

View GitHub Profile
@chilversc
chilversc / monodoc-style.css
Created December 31, 2009 02:10
Style for editing monodoc xml using tools such as oxygen
AssemblyInfo, TypeParameters, Base, MemberType, Parameters, ReturnValue
{
display: none;
}
TypeSignature {
display: block;
padding: 1em;
margin: 1em;
content: attr(Value);
create table Foo (data1 bit, data2 bit, data3 bit, seq int not null)
go
insert into Foo (data1, data2, data3, seq)
values (NULL, 0, 1, 1), (1, NULL, 0, 2), (0, 1, NULL, 3)
go
with unpivoted as (
select seq, value, col
from (select seq, data1, data2, data3 from Foo) a
void Main()
{
int x = System.Net.IPAddress.HostToNetworkOrder((127 << 24) | 1);
var y = new System.Net.IPAddress(x);
Console.WriteLine(x);
Console.WriteLine(y);
}
@chilversc
chilversc / Fob.hbm.xml
Created January 25, 2010 09:49
NHibernate insert/update problem
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-access="property" auto-import="true" default-cascade="none" default-lazy="true">
<class xmlns="urn:nhibernate-mapping-2.2" name="ValueMapping.Fob, ValueMapping, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" table="`Fob`">
<id type="System.Int32, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="id" />
<generator class="native" />
</id>
<property name="Something" type="System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="Something" />
</property>
</class>
@chilversc
chilversc / output.sql
Created January 25, 2010 14:28
NHibernate one-to-one problem
-- statement #1
begin transaction with isolation level: Unspecified
-- statement #2
SELECT bar_.Foo,
bar_.Rate as Rate1_,
bar_.Value as Value1_
FROM [Bar] bar_
WHERE bar_.Foo = '2b76e14d-c48e-490d-9d1c-9d0900ee14ec' /* @p0 */
@chilversc
chilversc / gist:291827
Created February 1, 2010 17:13
Verify SSL thumbprint
using System;
using System.IO;
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using System.Security.Principal;
namespace SslTest
{
internal class Program
@chilversc
chilversc / Range spec
Created March 12, 2010 20:03
Range spec
Range:
Min/Max rather than Start/End, better naming when dealing with non-contiguous ranges.
Start and end values are inclusive.
How enumeration works for stepping, etc is left to the class to decide, provide a static class with some standard implementations that use Math<T>.
Assumption is the main IRange<T> can be either contiguous or non-contiguous
Assumptions for SubRanges():
No two sub-ranges overlap.
Each sub-range is atomic (ie contiguous).
@chilversc
chilversc / gist:342750
Created March 24, 2010 20:30
Rough implementation to find a concrete list type from an interface
Sub Main
Dim type = GetType(List(Of String))
FindExplicitListType(type).Dump()
End Sub
Function FindExplicitListType(type As Type) As Type
If type.IsClass Then
'TODO: Should check if type implements IList or IList(Of)
Return type
ElseIf IsGenericList(type)
@chilversc
chilversc / gist:357546
Created April 6, 2010 12:41
Very odd, but it works
void Main()
{
var f = new Foo ();
f.Inc ();
f.Inc ();
f.X.Dump ();
}
struct Foo {
public readonly int X;
@chilversc
chilversc / test1.ps1
Created May 7, 2010 13:00
Powershell positional parameters
param (
[Parameter()] $foo,
[Parameter()] $bar
)
$foo
$bar
#output:
#> .\test1.ps1 0 1