Skip to content

Instantly share code, notes, and snippets.

@sniffdk
sniffdk / gist:3910391
Created October 18, 2012 08:08
CsvHelper snippet
using( var reader = new CsvReader(new StringReader(data)))
{
while (reader.Read())
{
var rec = reader.CurrentRecord;
}
}
@sniffdk
sniffdk / gist:3949104
Created October 24, 2012 21:43
Legacy strings
public int LastIndexOf(string value)
{
return this.LastIndexOf(value, this.Length - 1, this.Length, string.LegacyMode ? StringComparison.Ordinal : StringComparison.CurrentCulture);
}
// What is LegacyMode ?
internal static bool LegacyMode
{
get
// Problematic short example
var q = db.X.All().Join(db.Y, XId: db.X.Id).WithY();
// Problematic real example
var q = db.List.All().Join(db.Question, ListId: db.List.Id).WithQuestion();
// Suggested short example
var q = db.X.All().Join(db.Y, XId: db.X.Id ).With(db.X.Y);
private HttpContext _context;
public void ProcessRequest(HttpContext context)
{
_context = context;
context.Response.ContentType = "text/plain";
context.Response.Buffer = false;
foreach (var d in Document.GetRootDocuments())
public interface IBaseItem
{
int Id { get; set; }
string Name { get; set; }
}
public class ItemsIndex : AbstractIndexCreationTask<IBaseItem>
{
public ItemsIndex()
{
@sniffdk
sniffdk / gist:4717777
Created February 5, 2013 21:22
Get root sibling node in Umbraco v6
@{
var root = Model.Content.AncestorOrSelf(1);
var repository = root.Sibling("Repository");
}
@sniffdk
sniffdk / Testimonials.cs
Last active December 12, 2015 04:58 — forked from mattbrailsford/Testimonials.cs
Searching for nodes in the new Umbraco v6 API via Examine
// It's properly more correct to search on NodeTypeAlias (or DocumentTypeAlias as it's called in the new API)
var criteria = ExamineManager.Instance.DefaultSearchProvider.CreateSearchCriteria().NodeTypeAlias("Testimonial").Compile();
var testimonials = Model.Content.AncestorOrSelf(1)
.Sibling("Repository")
.Search(criteria);
// Or perhaps even just this, no traversing is need, performance should be the same, as nodes in Lucene aren't hierarchically stored
var criteria = ExamineManager.Instance.DefaultSearchProvider.CreateSearchCriteria().NodeTypeAlias("Testimonial").Compile();
var testimonials = Model.Content.Search(criteria);
// Typed
var ids = Model.Content.GetPropertyValue<string>("mNTP", true, "").Split(new[] {","}, StringSplitOptions.RemoveEmptyEntries);
var items = Umbraco.TypedContent(ids);
// Dynamic
@if (CurrentPage.HasValue("mNTP", true))
{
var ids = CurrentPage._mNTP.Split(',');
var items = Umbraco.Content(ids);
foreach (var item in items)
@sniffdk
sniffdk / gist:5583994
Created May 15, 2013 13:30
Sort document type in the dropdownlist when creating a new node in Umbraco.
/* From web.config or some other config place */
<add key="CreateContentSortOrder" value="Content page,Section page,some other page type name" />
/* In /umbraco/create/content.ascx - put the code in the bottom */
<%
var createContentSortOrder = ConfigurationManager.AppSettings["CreateContentSortOrder"];
if (!String.IsNullOrWhiteSpace(createContentSortOrder))
{ %>
<script type="text/javascript">
$(function () {
@sniffdk
sniffdk / A custom Umbraco controller implementation
Last active December 20, 2015 12:59 — forked from mattbrailsford/ListingController.cs
A slightly modified version of custom controllers/views. Works perfectly on my machine :)
public class Global : UmbracoApplication
{
protected override void OnApplicationStarting(object sender, EventArgs e)
{
base.OnApplicationStarting(sender, e);
DefaultRenderMvcControllerResolver.Current.SetDefaultControllerType(typeof(ListingPageController));
}
}