Skip to content

Instantly share code, notes, and snippets.

View robertmclaws's full-sized avatar

Robert McLaws robertmclaws

View GitHub Profile
@robertmclaws
robertmclaws / SendGridController.cs
Created September 27, 2012 00:56
Simple code to convert SendGrid's ridiculous Event API into usable C# objects.
public ActionResult Index()
{
var json = new StreamReader(Request.InputStream).ReadToEnd();
//RWM: The next line turns the faux-array into an actual one.
json = string.Format("[{0}]", json.Replace("}" + Environment.NewLine + "{", "},{"));
var models = JsonConvert.DeserializeObject<List<SendGridEventModel>>(json);
models.ForEach(c => ProcessEvent(c));
return new HttpStatusCodeResult(HttpStatusCode.OK);
}
@robertmclaws
robertmclaws / ShowContactTaskHackAttempt.cs
Created December 31, 2012 16:33
This is an attempt on Windows Phone 8 to trigger a Contact's Details UI to be displayed by creating a VCF file. This is at the suggestion of @JustinAngel (http://www.twitter.com/JustinAngel/status/285552040636194816)
private async void listBox_ItemTap(object sender, Telerik.Windows.Controls.ListBoxItemTapEventArgs e)
{
var result = (Contact)e.Item.AssociatedDataItem.Value;
var test = new ContactInformation();
test.GivenName = result.CompleteName.FirstName;
test.FamilyName = result.CompleteName.LastName;
test.DisplayName = result.DisplayName;
var vCard = await test.ToVcardAsync();
var tempName = Guid.NewGuid().ToString() + ".vcf";
@robertmclaws
robertmclaws / ApplicationInfo.cs
Created January 20, 2013 21:28
Windows Phone WMAppManifest reader that doesn't waste cycles reading the file every time you need to access a value. Usage: var version = ApplicationInfo.Version.
public static class ApplicationInfo
{
#region Private Members
const string AppManifestName = "WMAppManifest.xml";
const string AppNodeName = "App";
#endregion
@robertmclaws
robertmclaws / DecryptingSqlMembershipProvider.cs
Created May 10, 2013 23:36
Code to use SimpleMembership if your logins are encrypted and not hashed. Works in conjunction with the concepts and Account Controller code outlined at http://pretzelsteelersfan.blogspot.com/2012/11/migrating-legacy-apps-to-new.html
using System;
using System.Text;
using System.Web.Security;
namespace AdvancedREI.Providers
{
public class DecryptingSqlMembershipProvider : SqlMembershipProvider
{
/// <summary>
@robertmclaws
robertmclaws / KendoMvcExtensions.cs
Last active March 2, 2016 07:52
Solution to allow Kendo.Mvc ClientTemplates on MVC4 when the AntiXssEncoder is enabled. Also works with any other MVC control experiencing an "Invalid Template" issue due to AntiXssEncoder.
using Kendo.Mvc.UI;
using System.Web;
using System.Web.Mvc;
using System.Web.Security.AntiXss;
using System.Web.Util;
namespace Your.Namespace.Here
{
public static class KendoMvcExtensions
{
@robertmclaws
robertmclaws / orchard-error-2013.07.23.log
Created July 23, 2013 16:05
Error message from Vandelay.Industries on Orchard 1.7 RC. This error causes a race condition that halts W3WP.exe on Windows Server 2012.
2013-07-23 01:50:06,174 [7] Orchard.Exceptions.DefaultExceptionPolicy - An unexpected exception was caught
Autofac.Core.DependencyResolutionException: None of the constructors found with 'Orchard.Environment.AutofacUtil.DynamicProxy2.ConstructorFinderWrapper' on type 'Vandelay.Industries.Services.FaviconService' can be invoked with the available services and parameters:
Cannot resolve parameter 'Orchard.Media.Services.IMediaService mediaService' of constructor 'Void .ctor(Orchard.IWorkContextAccessor, Orchard.Caching.ICacheManager, Orchard.Caching.ISignals, Orchard.Media.Services.IMediaService)'.
at Autofac.Core.Activators.Reflection.ReflectionActivator.ActivateInstance(IComponentContext context, IEnumerable`1 parameters) in c:\Projects\OSS\autofac\Core\Source\Autofac\Core\Activators\Reflection\ReflectionActivator.cs:line 106
at Autofac.Core.Resolving.InstanceLookup.Activate(IEnumerable`1 parameters) in c:\Projects\OSS\autofac\Core\Source\Autofac\Core\Resolving\InstanceLookup.cs:line 79
at Autofac.Co
@robertmclaws
robertmclaws / App.xaml.cs
Last active January 12, 2017 03:25
Windows Phone 8 In-App Purchase End-to-End Example using Telerik Windows Phone Controls
public partial class App : Application
{
public static ListingInformation MarketplaceListing { get; set; }
//RWM: The rest of your startup code goes here...
}
@robertmclaws
robertmclaws / [yourmobileservicesschema].[GetAvgRatingForPicture].sql
Last active January 3, 2016 04:29
Computed Columns in Azure Mobile Services
CREATE FUNCTION [yourmobileservicesschema].[GetAvgRatingForPicture](@pictureId bigint)
RETURNS int
AS
BEGIN
DECLARE @r decimal(3,2)
select @r = AVG(rating) from PictureRatings where picture_id = @pictureId
RETURN @r
END
@robertmclaws
robertmclaws / table.read.js
Created January 31, 2014 17:44
Example of outputting the Mobile Services query object to SQL for use in custom queries.
function read(query, user, request) {
query.toSql = function() {
var result = "";
var queryComponents = query.getComponents();
//RWM: Reflection component for getting the sort order.
if (queryComponents.ordering != null) {
queryComponents.ordering.getProperties = function() {
var properties = [];
for (var prop in this) {
@robertmclaws
robertmclaws / Program.cs
Last active August 29, 2015 14:06
Our current WebJobs method signature
public static void ProcessQueueMessage([QueueTrigger("events")] byte[] messageEnvelope)
{
var message = messageEnvelope.Deserialize<string>());
Trace.WriteLine(message).
}
public static T Deserialize<T>(this byte[] data) where T : class
{
if (data == null)
{