Skip to content

Instantly share code, notes, and snippets.

View dsolovay's full-sized avatar

Dan Solovay dsolovay

View GitHub Profile
@dsolovay
dsolovay / Life.fs
Last active August 29, 2015 14:01
Simple Life implementation in F#
let rec MakeRow (length: int) (value: int) =
if length=0 then []
else value :: MakeRow (length - 1) value
let rec MakeGrid (n: int) (rowMaker) =
if n=0 then []
else rowMaker :: MakeGrid (n - 1) rowMaker
let MakeLifeGrid x = MakeGrid x (MakeRow x 0)
@dsolovay
dsolovay / AutofacConfig.cs
Last active August 29, 2015 14:21
Sitecore TDD with Glass
using System;
using System.Reflection;
using System.Web.Mvc;
using Autofac;
using Autofac.Integration.Mvc;
using Glass.Mapper.Sc;
namespace AutofacDemo
{
public class AutofacConfig
@dsolovay
dsolovay / CascadeField.cs
Last active August 29, 2015 14:21
FakeDB Samples
using Sitecore.Data.Items;
using Sitecore.Data.Query;
namespace fakedb.Layout.Sublayouts
{
public class CascadeField
{
private readonly string _fieldName;
public CascadeField(string fieldName)
@dsolovay
dsolovay / gist:1037200
Created June 21, 2011 03:47
Git tips and tricks
Is git status running slow? It should take more than a second or two. Try running "git gc" (garbage collect) to speed things up.
using System;
using NSubstitute;
using Sitecore.Data;
using Sitecore.Events;
using Sitecore.FakeDb;
using TestableHandler.Handlers;
using TestableHandler.Wrappers;
using Xunit;
namespace TestableHandler.UnitTests
// Demonstration code for StackOverflow question: http://stackoverflow.com/questions/33301106/query-lucene-index-against-ienumerable-field
// Shows that a field can be ignored from mapping and used in a linq query.
// Paste code into /sitecore/admin/linqscratchpad.aspx
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Web;
@dsolovay
dsolovay / SOLR and Autofac.md
Last active December 31, 2015 15:39
Issue wiring up SOLR + MVC + Autofac

#Issue

SOLR code requires this:

 new AutoFacSolrStartUp(new ContainerBuilder()).Initialize();

The Initialize method does not expose the container, but instead wraps in a ServiceLocator:

 ServiceLocator.SetLocatorProvider((ServiceLocatorProvider) (() => (IServiceLocator) new AutofacServiceLocator((IComponentContext) this.container)));
@dsolovay
dsolovay / DeleteSolrCores.ps1
Created November 5, 2016 02:48
Powershell script to delete solr cores that start with a prefix
param ($prefix = $(throw "-prefix is required"))
$client = (New-Object System.Net.WebClient)
[xml]$coresXML = $client.DownloadString("http://localhost:8983/solr/admin/cores")
$cores = $coresXML.response.lst[2].lst | % {$_.name}
$success = 0
$error = 0
foreach ($core in $cores) {
@dsolovay
dsolovay / HomeControllerTests.cs
Created August 8, 2016 19:09
Demo of adding functionality to MVC controller
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using FluentAssertions;
@dsolovay
dsolovay / SampleLayout.aspx
Last active July 24, 2017 09:23
SampleLayout.ascx that displays in memory automation states.
<%@ Import Namespace="Sitecore.Analytics"%>
<%@ Import Namespace="Sitecore.Analytics.Automation.Data"%>
<%@ Import Namespace="Sitecore.Analytics.Automation.MarketingAutomation"%>
<%@ Import Namespace="Sitecore.Data"%>
<%@ Page Language="c#" Inherits="System.Web.UI.Page" CodePage="65001" %>
<%@ Register TagPrefix="sc" Namespace="Sitecore.Web.UI.WebControls" Assembly="Sitecore.Kernel" %>
<%@ OutputCache Location="None" VaryByParam="none" %>
<!DOCTYPE html>
<script runat="server">