Skip to content

Instantly share code, notes, and snippets.

View nozzlegear's full-sized avatar
🌸
There is no theory, only the knowing.

Joshua Harms nozzlegear

🌸
There is no theory, only the knowing.
View GitHub Profile
@nozzlegear
nozzlegear / SomeController.cs
Created December 17, 2014 02:37
Using the ValidateHeaderAntiForgeryToken attribute
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Helpers;
using System.Web.Mvc;
namespace MyNamespace.Controllers{
public class SomePathController : Controller{
// POST: /SomePath/DoSomething
@nozzlegear
nozzlegear / ValidateHeaderAntiForgeryToken.cs
Last active March 15, 2024 00:11
Validate an ASP.NET AntiForgeryToken sent in the request header
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Helpers;
using System.Web.Mvc;
namespace MyNamespace.Controllers
{
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
@nozzlegear
nozzlegear / using-jQuery.postJson.js
Created December 17, 2014 02:27
An example for using $.postJson with an ASP.NET AntiForgeryToken
function myFunction () {
//Grab antiForgeryToken. (Don't forget to add @Html.AntiForgeryToken() to your view or this will be empty)
var antiForgeryToken = $("input[name=__RequestVerificationToken]").val();
//Prepare parameters
var params = {
FirstName: "Joshua",
LastName: "Harms"
};
@nozzlegear
nozzlegear / jQuery.postJson-con-antiForgeryToken.js
Created December 17, 2014 02:20
Extending jQuery to send json in a post with an ASP.NET AntiForgeryToken header
jQuery.postJSON = function (url, data, success, antiForgeryToken, dataType) {
if (dataType === void 0) { dataType = "json"; }
if (typeof (data) === "object") { data = JSON.stringify(data);}
var ajax = {
url: url,
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: dataType,
data: data,
success: success
@nozzlegear
nozzlegear / jQuery.postJson-sans-antiForgeryToken.js
Last active February 8, 2018 22:44
Extending jQuery to send json in a post
jQuery.postJSON = function (url, data, success, dataType) {
if (dataType === void 0) { dataType = "json"; }
if (typeof (data) === "object") { data = JSON.stringify(data);}
var ajax = {
url: url,
type: "POST",
contentType: "application/json; charset=utf-8",
dataType: dataType,
data: data,
success: success
@nozzlegear
nozzlegear / MyPage.xaml
Last active August 29, 2015 14:10
(xaml) Loading an image from a Base64 string in Windows Phone and Windows 8
<!-- A WinRT XAML page -->
<Page
x:Class="MyApp.MyPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:MyApp"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
@nozzlegear
nozzlegear / MyPage.xaml.cs
Last active December 19, 2015 12:39
Loading an image from a Base64 string in Windows Phone and Windows 8
using System;
using System.IO;
using System.Threading.Tasks;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Media.Imaging;
using Windows.UI.Xaml.Navigation;
using Windows.Web.Http;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkID=390556
@nozzlegear
nozzlegear / gist:d3e83c5e1fda66328b6f
Last active August 29, 2015 14:09
Join KeyValuePairs into an x-www-formurlencoded string, then POST it to a URL.
public async Task<string> YourMethod()
{
//Create a list of your parameters
var postParams = new List<KeyValuePair<string, object>>(){
new KeyValuePair<string, object>("FirstParameter", "First Value") ,
new KeyValuePair<string, object>("SecondParameter", "Second Value")
};
//Join KVPs into a x-www-formurlencoded string
var formString = string.Join("&", postParams.Select(x => string.Format("{0}={1}", x.Key, x.Value)));
@nozzlegear
nozzlegear / gist:0d42673f64e5c9a9862a
Last active January 21, 2024 01:18
Converting a .ics file to JSON, parsing it and using the data
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Linq;
using DDay.iCal;
using Newtonsoft.Json;
public class YourClass
{
public string YourMethod()
{
//Download the .ics file using DDay.iCal package from nuget (install-package dday.ical)