Skip to content

Instantly share code, notes, and snippets.

View mstum's full-sized avatar

Michael Stum mstum

View GitHub Profile
@mstum
mstum / Level.cpp
Last active August 29, 2015 14:06
CodeReview #62254 - Static Factory function and Lifetime questions
#include "Level.h"
#include <fstream>
#include <sstream>
std::string Level::GetName(){
// Should this return a Pointer?
return _name;
}
int Level::GetPlayerStartX() {
@mstum
mstum / rnn.cs
Created July 20, 2015 23:38
rnn (Requires.NotNull) ReSharper Template
// ReSharper Template to make "rnn" a shortcut to Requires.NotNull
// For use with the Validation NuGet Package by @AArnott
// https://www.nuget.org/packages/Validation
// https://github.com/AArnott/Validation
// C# Pre-6
Validation.Requires.NotNull($param$,"$param$");
// C# 6
Validation.Requires.NotNull($param$, nameof($param$));
@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)
{