Skip to content

Instantly share code, notes, and snippets.

@kstenson
kstenson / explaination
Last active August 29, 2015 14:21
Boolean field score inside query should
{
"value":3.722785,
"description":"weight(services.Phone.freeCalls.Daytime:T in 2786) [PerFieldSimilarity], result of:",
"details":[
{
"value":3.722785,
"description":"score(doc=2786,freq=1.0 = termFreq=1.0 ), product of:",
"details":[
{
"value":0.51985043,
### Keybase proof
I hereby claim:
* I am kstenson on github.
* I am kstenson (https://keybase.io/kstenson) on keybase.
* I have a public key whose fingerprint is RETU RN T HIS. PGP. GET_ FING ERPR INT( );
}
To claim this, I am signing this object:
@kstenson
kstenson / ObjectDiff.cs
Last active August 29, 2015 14:05
A Naive Object diff extension method
public static class ObjectExtensions
{
public static IEnumerable<Change> Diff<T>(this T obj1, T obj2)
{
PropertyInfo[] properties = typeof(T).GetProperties();
List<Change> changes = new List<Change>();
foreach (PropertyInfo pi in properties)
{
object value1 = typeof(T).GetProperty(pi.Name).GetValue(obj1, null);
public class MvcApplication : NinjectHttpApplication
{
protected void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new
@kstenson
kstenson / gist:6216952
Created August 13, 2013 01:16
Log all events fired in a page on the console
$(document).on("click mousedown mouseup focus blur keydown change",function(e){
console.log(e);
});
@kstenson
kstenson / delete.sql
Created September 3, 2012 15:15
clear all tables in db
-- disable all constraints
EXEC sp_msforeachtable "ALTER TABLE ? NOCHECK CONSTRAINT all"
-- delete data in all tables
EXEC sp_MSForEachTable "DELETE FROM ?"
-- enable all constraints
exec sp_msforeachtable "ALTER TABLE ? WITH CHECK CHECK CONSTRAINT all"
@kstenson
kstenson / HealthMonitor
Created July 26, 2012 09:17
Clients is null
namespace MC.Bureau.Adaptation.Service
{
public class HealthMonitor :IWantToRunAtStartup
{
private string url = "http://localhost:8081/";
private Server _server;
private HealthMonitorHub _healthMonitor;
public ITransport Transport { get; set; }
@kstenson
kstenson / gist:3047511
Created July 4, 2012 14:03
Autofac intercepter setup
//this class registers the two interceptors in the container with a name for each
public class InterceptorsModule: Module
{
protected override void Load(ContainerBuilder builder)
{
builder.Register(x => new LoggingInterceptor()).Named<IInterceptor>("Logger");
builder.Register(x => new TimingInterceptor()).Named<IInterceptor>("Timing");
}
}
@kstenson
kstenson / gist:3040253
Created July 3, 2012 14:58
Using modules with autofac
builder.RegisterModule(new DataModule()
{
AssemblyMapper = typeof(AcquireConfig).Assembly,
BuildSchema = true,
ConnectionString = Properties.Settings.Default.DataAcquisitionStoreConnection,
Web = false
});
public class DataModule : Module
{
@kstenson
kstenson / gist:3040235
Created July 3, 2012 14:55
Log4Net interceptor
public class LoggingInterceptor: IInterceptor
{
private static readonly ILog Logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);
public void Intercept(IInvocation invocation)
{
try
{
StringBuilder sb = null;