Skip to content

Instantly share code, notes, and snippets.

@leethomascook
leethomascook / DateFormatService.cs
Created October 2, 2016 17:52
Sample DateFormatService
public class DateFormatService : IDateFormatService
{
public virtual string FormatDate(DateTime dateTime, ContentTypeDate format, string language = "en")
{
switch (format)
{
case ContentTypeDate.PublishedDate:
return dateTime.ToString(DateFormats.FULL_DATE);
case ContentTypeDate.DateOfBirth:
return dateTime.ToString(DateFormats.FULL_DATE);
public class CustomUmbracoSearchResultCoverter : DefaultUmbracoSearchResultCoverter, IUmbracoSearchResultCoverter
{
public bool CanConvert(string contentAlias)
{
return contentAlias == "nameOfDocType";
}
public override string GetCategory(BaseUmbracoItem currentItem)
{
@leethomascook
leethomascook / MiniProfilerAttribute
Last active August 29, 2015 14:18
Mini Profiler Aspect with Postsharp
using System;
using PostSharp.Aspects;
using StackExchange.Profiling;
namespace xxx.Core.Logging
{
[Serializable]
public sealed class MiniProfilerAttribute : MethodInterceptionAspect
{
public override void OnInvoke(MethodInterceptionArgs context)
{
"wasSuccessfull" : "false"
fields: [
{
"name" : "firstName"
"label" : "First Name"
"value" : "Lee"
"required" : "true"
"validationMessage" : "This is required, douchebag"
"type" : "text"
@leethomascook
leethomascook / gist:a974132e7ba7c353ea9a
Created December 9, 2014 22:31
Attribute to sleect form in sitecore mvc
using System.Web.Mvc;
namespace xx.Site.Infrastructure
{
public class FormButtonAttribute : ActionMethodSelectorAttribute
{
private readonly string _name;
public FormButtonAttribute(string name)
{
@leethomascook
leethomascook / gist:8841684
Created February 6, 2014 10:22
StructureMap and umbraco 7
In Global.asax
protected override void OnApplicationStarting(object sender, EventArgs e)
{
base.OnApplicationStarting(sender, e);
ObjectFactory.Configure(
x => x.For<ITest>().Use<Test>()
);
@leethomascook
leethomascook / gist:8815874
Created February 5, 2014 01:27
Glass umbraco in controller
UmbracoService service = new UmbracoService(ApplicationContext.Services.ContentService, Context.Default);
service.GetItem<HomePage>(1);
task Compile -depends Init, UpdateGlobalAssemblyInfo {
write-host "Solution: $solution_file"
write-host "Configuration: $build_configuration"
write-host "Target $build_target"
write-host "Verbosity: $build_verbosity"
write-host "Output directory: $build_dir"
exec { msbuild "$solution_file" /t:$build_target /p:configuration=$build_configuration /p:outdir="$build_dir" /verbosity:$build_verbosity /m /p:BuildInParallel=true /p:TrackFileAccess=false }
}
@leethomascook
leethomascook / gist:7317704
Created November 5, 2013 11:28
Automatic sitecore image compression. First install this nuget package: Run: Install-Package nQuant Then add to your pipeline: <getMediaStream> <processor type="Sitecore.Resources.Media.ThumbnailProcessor, Sitecore.Kernel" /> <processor type="Sitecore.Resources.Media.ResizeProcessor, Sitecore.Kernel" /> <processor type="Sitecore.Resources.Media.…
public class ImageCompressionProcessor
{
public void Process(GetMediaStreamPipelineArgs args)
{
MediaStream outputStream = args.OutputStream;
if (outputStream == null)
return;
var bitmap = new Bitmap(Image.FromStream(outputStream.Stream));