Skip to content

Instantly share code, notes, and snippets.

@Buildstarted
Buildstarted / modelhack.cs
Created February 14, 2012 16:49
Model hack for cshtml outside of mvc
@functions
{
public ConsoleApplication16.CoolModel Model { get; set; }
}
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>
</head>
<body>
@Buildstarted
Buildstarted / DocumentStoreTest.cs
Created February 28, 2012 15:48
Seems to be a bug in RavenDB
using System.Linq;
using NUnit.Framework;
using Raven.Client.Embedded;
namespace DocumentStoreTest
{
[TestFixture]
public class DocumentStoreTests
{
//This test attempts to lookup an existing item when none exist in the
@Buildstarted
Buildstarted / gravatarInfo.js
Created May 15, 2012 02:51
gravatarInfo for JabbR
(function ($) {
function getGravatarInfo(hash, callback) {
console.log(hash);
var url = "http://en.gravatar.com/" + hash + ".json?callback=?";
$.getJSON(url, function (result) {
if (result.entry[0]) {
result = result.entry[0];
callback(result);
}
});
@Buildstarted
Buildstarted / FindConflictingReferences.cs
Created June 14, 2012 22:29 — forked from brianlow/FindConflictingReferences.cs
Find conflicting assembly references
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using NUnit.Framework;
namespace MyProject
{
[TestFixture]
@Buildstarted
Buildstarted / menuitem.cs
Created June 30, 2012 06:02
Creates a menu item wrapped in an li tag
// Sample call
// @Html.MenuItem("Logs", new { controller = "logs", action = "index" })
public static class HtmlExtensionMethods
{
/// <summary>
/// Creates a new menu item (li)
/// </summary>
/// <param name="helper">class this extension method is attached to</param>
/// <param name="linkText">Link text to be output in the anchor tag</param>
@Buildstarted
Buildstarted / ControllerExtensions.cs
Created July 4, 2012 23:07
ControllerExtensions to allow return of typed views
public static class ControllerExtensions
{
//should be safe for most controllers
private static MethodInfo _viewMethod;
private static readonly ConcurrentDictionary<Type, string> CachedPathNames = new ConcurrentDictionary<Type, string>();
public static ActionResult TypedView(this Controller controller, Type type)
{
return TypedView(controller, type, null, null);
@Buildstarted
Buildstarted / gist:3182600
Created July 26, 2012 15:06 — forked from davidfowl/gist:3172990
MethodInfo.Invoke is slow...
using System;
using System.Diagnostics;
using System.Linq.Expressions;
using System.Reflection;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
@Buildstarted
Buildstarted / TypeBuilderFromJson.cs
Created August 1, 2012 05:43
Creates a concrete type from json
public static class TypeBuilderFromJson
{
public static Type CreateType(JObject jObject)
{
var dict = new Dictionary<string, object>();
foreach (var child in jObject)
{
dict.Add(child.Key, child.Value);
}
return CompileResultType(dict);
public class ForeachRenderer : IRenderer
{
public string Render(AbstractNode node, object model)
{
object localModel = model;
if (node == null)
{
throw new ArgumentNullException("node");
@Buildstarted
Buildstarted / split-retain-splitchar.cs
Created August 4, 2012 02:43
Splits a string by delimiters but retails delimiter
private IEnumerable<string> GetIdentifierParts(string source)
{
char[] splitBy = new[] { '.', '#' };
int start = 0;
int index = 0;
string previousCharacter = "";
while ((index = source.IndexOfAny(splitBy, start)) != -1)
{