Skip to content

Instantly share code, notes, and snippets.

public class TaskExecutor
{
private ITaskProcessor _processor;
public TaskExecutor(ITaskProcessor processor)
{
_processor = processor;
}
public void DoTask()
{
@markrendle
markrendle / knockoutrt.js
Created June 4, 2012 12:14
Knockout ViewModel from WinRT object
// Reusable Knockout ViewModel from WinRT object
// with two-way binding enabled.
(function () {
function camelCase(str) {
return str[0].toLowerCase() + str.substring(1);
}
function makeViewModel(obj) {
var vm = {};
var properties = Object.keys(Object.getPrototypeOf(obj));
properties.forEach(function (p) {
@markrendle
markrendle / vs.sh
Created June 20, 2012 14:49
Shell script to launch Visual Studio with either named sln or most recently modified
if [ -n "$1" ]; then
file=$1
else
file=( $(ls -xt *.sln | head -n1))
fi
if [ -z "$file" ]; then
echo "No solution found."
exit 1
fi
/c/Program\ Files\ \(x86\)/Microsoft\ Visual\ Studio\ 11.0/Common7/IDE/devenv.exe "$file" &
@markrendle
markrendle / MultipartParser.cs
Created June 21, 2012 17:32
Multipart parser
namespace MultipartSpike
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
public class MultipartParser
{
private const int MaximumMemoryStreamSize = 1024*64;
@markrendle
markrendle / GetProfile.cs
Created August 8, 2012 20:48 — forked from dotnetchris/gist:3298615
RESTful Simple.Web handlers
[UriTemplate("/accounts/profile/{Name}")]
[Canonical(typeof(ProfileViewModel))] // RESTful, baby!
public class GetProfile : IGet, IOutput<ProfileViewModel>
{
private readonly UserReports _userReports;
private readonly ILogger _logger;
public GetProfile(UserReports userReports, ILogger logger) // No unnecessary injections
{
_userReports = userReports;
@markrendle
markrendle / XmlAttributesAsDictionary.cs
Created September 6, 2012 08:43
Utility classes for dealing with XML as Dictionaries
namespace Simple.NExtLib.Xml
{
public class XmlAttributesAsDictionary
{
private readonly XElement _element;
public XmlAttributesAsDictionary(XElement element)
{
_element = element;
}
@markrendle
markrendle / Example.cs
Created September 10, 2012 12:43
Maybe extensions for LinqToXML
public class Person
{
public string Name { get; set; }
public List<string> Numbers { get; set; }
public static Person FromXml(XElement xml)
{
return new Person
{
Name = xml.Element("Name").MaybeValue(),
@markrendle
markrendle / Sample.csproj
Created October 2, 2012 11:48
Visual Studio project bits for TypeScript compilation
<ItemGroup>
<TypeScriptCompile Include="$(ProjectDir)\**\*.ts" />
</ItemGroup>
<Target Name="BeforeBuild">
<Exec Command="&quot;$(PROGRAMFILES)\Microsoft SDKs\TypeScript\0.8.0.0\tsc&quot; -target ES5 @(TypeScriptCompile ->'&quot;%(fullpath)&quot;', ' ')" />
</Target>
declare interface AngularVersion {
full: string;
major: number;
minor: number;
dot: number;
codeName: string;
}
declare interface AngularModule {
requires: string[];
@markrendle
markrendle / databasefactory.cs
Created October 12, 2012 13:44
Simple.Data + Impromptu-Interface interfaces
static class DatabaseFactory
{
public static IDatabase Create()
{
Database.UseMockAdapter(CreateMockAdapter());
// This single line of code applies all these interfaces
return Impromptu.ActLike<IDatabase>(Database.Open());
}