Skip to content

Instantly share code, notes, and snippets.

View jrusbatch's full-sized avatar

Justin Rusbatch jrusbatch

View GitHub Profile
/**
* Both of the below methods are valid actions in an ApiController, and both would result in the
* same response being sent to the client.
**/
// GET api/strings
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
public class DocumentSessionFactory : IDisposable
{
private readonly IDocumentStore documentStore;
public DocumentSessionFactory()
{
documentStore = new EmbeddableDocumentStore { RunInMemory = true };
documentStore.Initialize();
}
@jrusbatch
jrusbatch / gist:3872094
Created October 11, 2012 12:54
Precompile.targets
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- Created by Craig Andrews http://candrews.integralblue.com [email protected] -->
<UsingTask TaskName="Microsoft.WebDeployment.Tasks.AspNetMerge" AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\WebDeployment\v10.0\Microsoft.WebDeployment.Tasks.dll"/>
<PropertyGroup>
<_PackageTempDirCompiled>$(PackageTempRootDir)\PackageTempCompiled</_PackageTempDirCompiled>
@jrusbatch
jrusbatch / AvailablePorts.cs
Created December 5, 2012 02:17
Find an Available Port with C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.NetworkInformation;
using System.Net;
namespace AvailablePort
{
class Program
/// <summary>
/// Represents an IIS Express site.</summary>
public class IISExpress : IDisposable
{
private readonly string applicationPath;
private readonly Uri address;
private Process process;
private bool disposed;
@jrusbatch
jrusbatch / gist:4731149
Last active December 12, 2015 06:39
A wrapper for Twitter Bootstrap's typeahead plugin that supports objects.
(function($) {
'use strict';
function TypeaheadItem(value, selectedText, suggestionText) {
this.value = value;
this.text = selectedText;
this.suggestion = suggestionText || selectedText;
}
TypeaheadItem.prototype.toString = function () {
using (var client = new HttpClient())
{
var authTokenBytes = Encoding.UTF8.GetBytes("auth_key:");
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(authTokenBytes));
await client.PostAsync("https://push.ducksboard.com/v/widget_id", new { value = timer.ElapsedMilliseconds }, new JsonMediaTypeFormatter());
}
public static class HtmlHelperExtensions
{
public static WebGrid<T> Grid<T>(
this HtmlHelper<PagedViewModel<T>> htmlHelper,
int rowsPerPage = 10) where T : class
{
return new WebGrid<T>(htmlHelper, rowsPerPage);
}
public static WebGrid<TModel> Grid<T, TModel>(
private class FakeScriptPack : IScriptPack
{
public void Initialize(IScriptPackSession session)
{
}
public IScriptPackContext GetContext()
{
return new FakeScriptPackContext();
}
public void Execute(string code, IEnumerable<string> references, IEnumerable<string> namespaces, ScriptPackSession scriptPackSession)
{
var host = _scriptHostFactory.CreateScriptHost(new ScriptPackManager(scriptPackSession.Contexts));
foreach (var context in scriptPackSession.Contexts) _scriptEngine.AddReference(context.GetType().Assembly);
var session = _scriptEngine.CreateSession(host);
foreach (var reference in references.Union(scriptPackSession.References).Distinct())
session.AddReference(reference);