Skip to content

Instantly share code, notes, and snippets.

View ntotten's full-sized avatar

Nathan Totten ntotten

View GitHub Profile
@ntotten
ntotten / AccountController.cs
Created March 21, 2011 18:31
ASP.NET MVC 3 Simple Authorization
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Facebook;
using MyFacebookSite3434.Models;
using System.Web.Security;
namespace MyFacebookSite3434.Controllers
var fb = new FacebookClient("access_token");
var result = fb.Get<FBUser1>("/me");
string name = result.Name;
@ntotten
ntotten / MyFirstJob.cs
Created April 7, 2011 15:20
AzureToolkit Worker Role with MEF
[Export]
[PartCreationPolicy(CreationPolicy.NonShared)]
public class MyFirstJob : IJob
{
[Import]
public IMyFirstService MyFirstService { get; set; }
public void Run()
{
@ntotten
ntotten / StaticContentHelpers.cs
Created April 17, 2011 22:20
MVC helper for automatically using ASP.NET AJAX CDN and Windows Azure CDN for static content.
using System;
using System.Web.Mvc;
using System.Collections.Generic;
using System.Configuration;
public static class StaticContentHelpers
{
private const string azureCdnUrl = ".cloudapp.net/cdn";
private const string aspCdnUrl = "ajax.aspnetcdn.com/ajax";
@ntotten
ntotten / ConfigureIIS.cmd
Created July 14, 2011 16:15
Updated ConfigureIIS.cmd for WAAWR to install PHP and MVC3
@echo off
rem This is only for SDK 1.4 and not a best practice to detect DevFabric.
if ("%WA_CONTAINER_SID%") == ("") goto Exit
echo Installing Web-Mgmt-Service
if exist "%windir%\system32\ServerManagerCmd.exe" "%windir%\system32\ServerManagerCmd.exe" -install Web-Mgmt-Service
echo Configuring Web-Mgmt-Service
sc config wmsvc start= auto
net stop wmsvc
using System;
using System.Web.Script.Serialization;
namespace Facebook {
public class FrameworkJsonSerializer : IJsonSerializer {
public string SerializeObject(object obj) {
var serializer = new JavaScriptSerializer();
return serializer.Serialize(obj);
}
@ntotten
ntotten / gist:1294232
Created October 17, 2011 23:49
SimpleJson @object
public static bool TryDeserializeObject(string json, out object @object)
{
bool success = true;
if (json != null)
{
char[] charArray = json.ToCharArray();
int index = 0;
@object = ParseValue(charArray, ref index, ref success);
}
else
@ntotten
ntotten / FormatterConfig.cs
Created July 2, 2012 01:45
ApiController Formatter Configuration
public class FormatterConfig
{
public static void ConfigureApi(HttpConfiguration config)
{
// Remove the XML formatter
config.Formatters.Remove(config.Formatters.XmlFormatter);
}
}
@ntotten
ntotten / Person.cs
Created July 8, 2012 17:18
ASP.NET Web API Example
public class Person {
public int Id { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public virtual ICollection<Message> Messages { get; set; }
}
@ntotten
ntotten / chat.js
Created August 2, 2012 20:25
Tankster Command Blog Post
var socket = io.connect();
socket.on('connect', function () {
socket.emit('connect', userInfo);
});
$('#text').keypress(function (e) {
if (e.keyCode == 13) {
$("#send").click();
return false;