Skip to content

Instantly share code, notes, and snippets.

@dschenkelman
dschenkelman / sample.js
Last active August 29, 2015 14:01
Frozen Proxies
var immutable = (function(){
function isFunction(f) {
var getType = {};
return f && getType.toString.call(f) === '[object Function]';
}
function shallowCopy(object){
var copy = Object.create(Object.getPrototypeOf(object));
Object.getOwnPropertyNames(object).forEach(function (name){
@dschenkelman
dschenkelman / MVP.cs
Last active August 29, 2015 14:01
MMC 3.0 Sample Plug-In using MVP and Unity
public class ConnectionListView : MmcListView, IConnectionListView
{
private readonly IConnectionListPresenter presenter;
public ConnectionListView()
{
var container = this.SnapIn.Tag as IUnityContainer;
@dschenkelman
dschenkelman / RootBindingExtension.cs
Created May 9, 2014 05:01
Binding to View Model properties in Data Templates. The RootBinding Markup Extension
public class RootBindingExtension : IMarkupExtension<Binding>
{
public string Path { get; set; }
public Binding ProvideValue(IServiceProvider serviceProvider)
{
IRootObjectProvider rootProvider = (IRootObjectProvider) serviceProvider.GetService(typeof(IRootObjectProvider));
var view = rootProvider.RootObject;
var fe = view as FrameworkElement;
@dschenkelman
dschenkelman / Everything.cs
Created May 9, 2014 04:57
Needle Container: Fluency and Mapping Types
needleContainer
.Map<IForceEnlightened>()
.To<Jedi>()
.WithId("Yoda")
.UsingLifetime(RegistrationLifetime.Singleton)
.Commit();
@dschenkelman
dschenkelman / CompositeDatabaseInitializer.cs
Created May 9, 2014 04:51
Creating Indexes via Data Annotations with Entity Framework 5.0
using System.Collections.Generic;
using System.Data.Entity;
public class CompositeDatabaseInitializer<T> : IDatabaseInitializer<T> where T : DbContext
{
private readonly List<IDatabaseInitializer<T>> initializers;
public CompositeDatabaseInitializer(params IDatabaseInitializer<T>[] databaseInitializers)
{
this.initializers = new List<IDatabaseInitializer<T>>();
@dschenkelman
dschenkelman / MyClass.js
Created May 9, 2014 04:46
To Arrow Function or not to Arrow Function
var MyClass = (function () {
function MyClass() {
}
MyClass.prototype.add = function (a, b) {
return a + b;
};
MyClass.prototype.partialAdd = function (a) {
var _this = this;
return function (b) {
return _this.add(a, b);
@dschenkelman
dschenkelman / sample.csx
Created May 9, 2014 04:40
scriptcs TCP client and server Script Pack: ScriptCs.Net
var net = Require<Net>();
var server = net.CreateServer(socket =>
{
Console.WriteLine("New connection");
socket.On(
data: bytes => Console.Write(bytes.AsString()),
close: () => Console.WriteLine("Connection closed"),
error: e => Console.WriteLine("Error: {0}\r\nStackTrace: {1}", e.Message, e.StackTrace));
@dschenkelman
dschenkelman / Extensions.cs
Created May 9, 2014 04:38
Intro to OWIN talk and a simple IP filtering middleware sample
namespace Owin.IpFilter
{
using System;
using System.Net;
public static class Extensions
{
public static IAppBuilder UseIpFiltering(this IAppBuilder appBuilder, Func<IPAddress, bool> rejectRequest)
{
appBuilder.Use(typeof(IpFilterMiddleware), rejectRequest);
@dschenkelman
dschenkelman / AsyncMain.cs
Created May 9, 2014 04:35
Asynchronous I/O in C#: Introduction
static void Main()
{
var fs = new FileStream("test.txt", FileMode.Open, FileAccess.Read, FileShare.None, 1024, true);
var buffer = new byte[1024];
fs.BeginRead(buffer, 0, 1024, ReadCallback, new State { Buffer = buffer, FileStream = fs });
Console.ReadLine();
}
@dschenkelman
dschenkelman / FakeNavigationService.cs
Created May 9, 2014 04:29
fakewin8: Easy fakes for Windows Store apps unit tests
public class FakeNavigationService : INavigationService
{
public FakeAction<string> NavigateAction { get; set; }
public FakeAction GoBackAction { get; set; }
public void Navigate(string viewName)
{
this.NavigateAction.Invoke(viewName);
}