Skip to content

Instantly share code, notes, and snippets.

View mstum's full-sized avatar

Michael Stum mstum

View GitHub Profile
@mstum
mstum / gist:983658
Created May 20, 2011 19:54
Switching between multiple Views?
<script type="text/javascript">
var viewModel = {
currentView: ko.observable("template-1")
};
viewModel.template = ko.dependentObservable(function(){
return this.currentView();
}, viewModel);
$(document).ready(function() {
@mstum
mstum / gist:2409035
Created April 17, 2012 21:02
Halfwit Crash
Autofac.Core.DependencyResolutionException:
An exception was thrown while invoking the constructor 'Void .ctor(Halfwit2.Helpers.AggregateService, System.Func`3[Halfwit2.ViewModels.TimelineViewModel,Halfwit2.IHalfwitUser,Autofac.Features.OwnedInstances.Owned`1[Halfwit2.ViewModels.DirectMessageViewModel]],
System.Func`3[Halfwit2.ViewModels.TimelineViewModel,Halfwit2.ViewModels.StatusViewModel,Autofac.Features.OwnedInstances.Owned`1[Halfwit2.ViewModels.ReplyViewModel]],
System.Func`3[Halfwit2.ViewModels.TimelineViewModel,Halfwit2.ViewModels.StatusViewModel,Autofac.Features.OwnedInstances.Owned`1[Halfwit2.ViewModels.RetweetViewModel]], Halfwit2.ViewModels.TimelineViewModel, Budgie.TwitterStatus)' on type 'StatusViewModel'.
@mstum
mstum / gist:2417367
Created April 18, 2012 23:30
Another issue
{"Unexpected character encountered while parsing value: <. Line 0, position 0."}
at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
at System.Threading.Tasks.Task`1.get_Result()
at Halfwit2.Pollers.HomePoller.<>c__DisplayClass3.<PollAsync>b__2(Task`1 t)
at System.Threading.Tasks.Task`1.<>c__DisplayClass17.<ContinueWith>b__16(Object obj)
at System.Threading.Tasks.Task.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
{"Unexpected character encountered while parsing value: <. Line 0, position 0."}
at Newtonsoft.Json.JsonTextReader.ParseValue()
@mstum
mstum / gist:3037801
Created July 3, 2012 05:04
Halfwit crash on invalid OAuth PIN
NullRef: {"Object reference not set to an instance of an object."}
at Halfwit2.ViewModels.ConnectionViewModel.Save()
at GalaSoft.MvvmLight.Command.RelayCommand.Execute(Object parameter)
at MS.Internal.Commands.CommandHelpers.CriticalExecuteCommandSource(ICommandSource commandSource, Boolean userInitiated)
at System.Windows.Controls.Primitives.ButtonBase.OnClick()
at System.Windows.Controls.Button.OnClick()
at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
at System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender, MouseButtonEventArgs e)
at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget)
@mstum
mstum / gist:3165909
Created July 23, 2012 20:06
IIS File Upload Limit
<!-- You ALSO need to set this, which is KiloByte:
<httpRuntime maxRequestLength="51200" />
-->
<system.webServer>
<security>
<requestFiltering>
<!-- in bytes. Documentation says that 0 means Unlimited, but this is NOT true. 0 means zero bytes. 2 GB is the max. -->
@mstum
mstum / gist:3832307
Created October 4, 2012 08:44
Model Binder for Byte Arrays
public class AnnounceResultModelBinder : IModelBinder
{
private ByteArrayModelBinder _byteBinder = new ByteArrayModelBinder();
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
if (bindingContext.ModelName == "info_hash" || bindingContext.ModelName == "peer_id")
{
var query = controllerContext.RequestContext.HttpContext.Request.Url.Query;
if (query.StartsWith("?")) query = query.Substring(1);
@mstum
mstum / gist:4076221
Created November 15, 2012 02:15
Quick n' Dirty Web API Error Deserializer for RestSharp
// client.ClearHandlers();
// client.AddHandler("*", new WebApiJsonDeserializer());
using System;
using System.Net;
namespace RestSharp.Deserializers
{
public class WebApiJsonDeserializer : IDeserializer
{
@mstum
mstum / gist:4231781
Created December 7, 2012 08:26
Ugly yield return
private static IEnumerable<byte> Add(byte register, int value)
{
yield return Opcodes.Add.Code;
yield return register;
foreach (var bt in WriteInt(value)) yield return bt;
}
private static IEnumerable<byte> WriteInt(int value)
{
@mstum
mstum / gist:4248838
Created December 10, 2012 06:37
Resolving Labels
private static Dictionary<string, int> ResolveLabels(IList<Token> tokens)
{
var result = new Dictionary<string, int>(StringComparer.InvariantCultureIgnoreCase);
var currentPosition = 0;
foreach (var token in tokens)
{
var commandToken = token as CommandToken;
if (commandToken != null)
{
@mstum
mstum / gist:5135132
Created March 11, 2013 15:42
Any way to share the OAuth dependency between 4.0 and 4.5 so that I don't DRY? Using an empty group doesn't work in 4.0, it seems that the single net40 match trumps everything. Not putting it into a group gives an error message saying I can't mix "free" dependencies with groups.
<dependencies>
<group targetFramework="net40">
<dependency id="Microsoft.Bcl.Async" version="1.0.14-rc" />
<dependency id="DotNetOpenAuth.OAuth.ServiceProvider" version="4.2.2.13055" />
</group>
<group targetFramework="net45">
<dependency id="DotNetOpenAuth.OAuth.ServiceProvider" version="4.2.2.13055" />
</group>
</dependencies>