Skip to content

Instantly share code, notes, and snippets.

View thecodejunkie's full-sized avatar

Andreas Håkansson thecodejunkie

View GitHub Profile
@thecodejunkie
thecodejunkie / gist:5345420
Created April 9, 2013 12:44
SSVE gist matcher
public class GistSuperSimpleViewEngineExtension : ISuperSimpleViewEngineExtension
{
private readonly Regex regex = new Regex(@"(?:@gist\[(?<id>[a-z01-9]*)\])", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private const string GistTemplate = "<script src='https://gist.github.com/{0}.js'></script>";
public string Invoke(string content, dynamic model, IViewEngineHost host)
{
return regex.Replace(content, match => (match.Groups["id"].Success) ? string.Format(GistTemplate, match.Groups["id"].Value) : string.Empty);
}
}
public interface ISuperSimpleViewEngineExtension
{
string Invoke(string content, dynamic model, IViewEngineHost host);
}
public class GistSuperSimpleViewEngineExtension : ISuperSimpleViewEngineExtension
{
private readonly Regex regex = new Regex(@"(?:@gist\[(?<id>[a-z01-9]*)\])", RegexOptions.Compiled | RegexOptions.IgnoreCase);
private const string GistTemplate = "<script src='https://gist.github.com/{0}.js'></script>";
public class CustomeOwinHost
{
private readonly Func<IDictionary<string, object>, Task> next;
public CustomeOwinHost(Func<IDictionary<string, object>, Task> next, string foo)
{
this.next = next;
}
public Task Invoke(IDictionary<string, object> environment)
@thecodejunkie
thecodejunkie / gist:5236179
Last active December 15, 2015 09:09
RequestStream rewrite
public RequestStream(Stream stream, long expectedLength, long thresholdLength, bool disableStreamSwitching)
{
this.thresholdLength = thresholdLength;
this.disableStreamSwitching = disableStreamSwitching;
this.stream = stream ?? this.CreateDefaultMemoryStream(expectedLength);
ThrowExceptionIfCtorParametersWereInvalid(this.stream, expectedLength, this.thresholdLength);
if (!this.MoveStreamOutOfMemoryIfExpectedLengthExceedExpectedLength(expectedLength))
{
if (!this.stream.CanSeek)
{
var buffer =
new MemoryStream((int)this.stream.Length);
this.stream.CopyTo(buffer, (source, destination, ex) =>
{
this.stream = buffer;
});
}
@thecodejunkie
thecodejunkie / gist:5235757
Created March 25, 2013 08:47
CopyStreamToStream implemented as an extension method on Stream
public static class StreamExtensions
{
public static void CopyStreamToStream(this Stream source, Stream destination, Action<Stream, Stream, Exception> completed)
{
var buffer = new byte[4096];
var operation =
AsyncOperationManager.CreateOperation(null);
Action<Exception> done = e =>
I don't have VS2012 installed on one of my machines, but .NET Framework 4.5 is. When creating a web project using VS2012 it instists on adding
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
To the csproj of said project. If I build these outside of VS (in this case using Rake) it will resolve VisualStudioVersion to v11.0, which means will try to look for targets at
@thecodejunkie
thecodejunkie / gist:5132898
Created March 11, 2013 08:58
RequestStream modification
public RequestStream(Stream stream, long expectedLength, long thresholdLength, bool disableStreamSwitching)
{
this.thresholdLength = thresholdLength;
this.disableStreamSwitching = disableStreamSwitching;
this.stream = stream ?? this.CreateDefaultMemoryStream(expectedLength);
ThrowExceptionIfCtorParametersWereInvalid(this.stream, expectedLength, this.thresholdLength);
this.MoveStreamOutOfMemoryIfExpectedLengthExceedExpectedLength(expectedLength);
this.MoveStreamOutOfMemoryIfContentsLengthExceedThresholdAndSwitchingIsEnabled();
public class IndexModule : NancyModule
{
public IndexModule()
{
Get["/"] = x => {
return "Nancy running on ScriptCS!";
};
}
}
@thecodejunkie
thecodejunkie / gist:5068466
Created March 1, 2013 22:32
Modifying Nancy.Serializers.JsonNet to support customization through either auto-discovery or explicit settings
public static JsonSerializer Serializer;
public JsonNetSerializer()
{
Serializer = GetJsonSerializer();
}
private static JsonSerializer GetJsonSerializer()
{
if (Serializer != null)