Skip to content

Instantly share code, notes, and snippets.

View mcintyre321's full-sized avatar

Harry McIntyre mcintyre321

View GitHub Profile
@mcintyre321
mcintyre321 / gist:1175478
Created August 27, 2011 14:56
NHibernate + MiniProfiler
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Runtime.Remoting.Proxies;
using System.Text;
using System.Web;
@mcintyre321
mcintyre321 / ProfiledSql2008ClientDriver.BatchFix.cs
Created August 27, 2011 15:14
ProfiledSql2008ClientDriver.BatchFix.cs
public partial class ProfiledSql2008ClientDriver : IEmbeddedBatcherFactoryProvider
{
System.Type IEmbeddedBatcherFactoryProvider.BatcherFactoryClass
{
get { return typeof(ProfiledSqlClientBatchingBatcherFactory); }
}
}
public class ProfiledSqlClientBatchingBatcherFactory : SqlClientBatchingBatcherFactory
{
public override NHibernate.Engine.IBatcher CreateBatcher(ConnectionManager connectionManager, NHibernate.IInterceptor interceptor)
@mcintyre321
mcintyre321 / gist:5860606
Created June 25, 2013 17:47
Flawed (?) sync methods
void SyncToSignalR<T>(ObservableCollection<T> oc)
{
oc.OnCollectionChanged += (o, e) { Hub.Send(e.NewItems.Cast<T>()); }
//race condition, what if OnCollectionChanged fires before send is donev
Hub.Send(oc));
}
//alternatiive
void SyncToSignalR2<T>(ObservableCollection<T> oc)
{
@mcintyre321
mcintyre321 / gist:5876578
Created June 27, 2013 13:53
Fix for Lucene DateTime issue
using System;
using System.ComponentModel;
using System.Globalization;
using Lucene.Net.Documents;
namespace Lucene.Net.Linq.Converters
{
public class DateTimeConverter : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
@mcintyre321
mcintyre321 / gist:6230628
Created August 14, 2013 12:31
Example of a CodeView for AspMvc
public class IndexView : CodeView<IndexViewModel>
{
protected override void Render(CQ doc, IndexViewModel model, ViewContext viewContext)
{
doc["body"].Append("<div>" + viewContext.ViewBag.Message + "</div>");
}
}
@mcintyre321
mcintyre321 / gist:6294588
Last active October 4, 2019 00:02
Replacing a case-sensitive methods in an Expression Tree with a case-insensitive equivalents using QueryInterceptor. Very cool! This is runnable in LinqPad if you add the QueryInterceptor Nuget package
void Main()
{
var words = new []{"HELLO"}.AsQueryable().SetComparer(StringComparison.CurrentCultureIgnoreCase);
words.Where (x => x.StartsWith("hel")).Dump();
words.Where (x => x.Contains("ell")).Dump();
words.Where (x => x.EndsWith("llo")).Dump();
words.Where (x => x.Equals("hello")).Dump();
words.Where (x => x == "hello").Dump();
//inject this into class needing to query data, it can live in the domain
public User delegate FindUserByEmail(string email);
//(over in external DataAccess project)
container.Register<FindUserByEmail>(c => (string email) => c.Resolve<IDocumentSession>().Query<User>().Single(u => u.Email == email));
PROPFIND http://sabre.127.0.0.1.xip.io/ HTTP/1.1
Connection: TE
TE: trailers
Host: sabre.127.0.0.1.xip.io
Depth: 0
Content-Length: 159
Content-Type: application/xml
<?xml version="1.0" encoding="utf-8"?>
<propfind xmlns="DAV:"><prop>
<?php
use
Sabre\DAV;
//ini_set('display_errors', '1');
if (isset($_SERVER['HTTP_X_ORIGINAL_URL']))
{
$_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_ORIGINAL_URL'];
if (!isset($_SERVER['REQUEST_URI'])) {
void Main()
{
var x = XDocument.Load(@"...\packages.config")
.Document.Root.Elements().Select (r => r.Attribute("id").Value)
.Select (r => {
var cq = CsQuery.CQ.CreateFromUrl("https://www.nuget.org/packages/" + r);
return new{
Package = r,
License = cq[".licenseName"].Html(),
LicenseUrl = cq["a"].Single (el => el.InnerText == "License")["href"]