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 / 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 / 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 / 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 / jQuery.postJson.d.ts
Last active August 29, 2015 14:11
TypeScript definition file for $.postJson
/// <reference path="../typings/jquery/jquery.d.ts" />
// Extend the jQueryAjaxSettings interface that should be defined at /scripts/typings/jquery/jquery.d.ts
// Don't have that file? Install with NuGet: install-package jquery.typescript.definitelytyped
interface JQueryAjaxSettings {
/**
* Load data from the server using a HTTP POST request.
*
* @param url A string containing the URL to which the request is sent.
@nozzlegear
nozzlegear / YouTube.cs
Created January 15, 2015 20:08
A C# model for JSON YouTube response
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ButterflyCore.Models
{
public class Thumbnail
{
using ButterflyCore.Models;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Storage;
using Windows.ApplicationModel.Background;
using ButterflyCore;
using Windows.UI.Notifications;
using Windows.Data.Xml.Dom;
@nozzlegear
nozzlegear / MainPage.xaml
Last active August 29, 2015 14:13
For Windows
<Page
x:Name="pageRoot"
x:Class="Space_Butterfly.MainPage"
DataContext="{Binding Items, RelativeSource={RelativeSource Self}}"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Space_Butterfly"\
xmlns:common="using:Space_Butterfly.Common"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
@nozzlegear
nozzlegear / AccountController.cs
Created September 20, 2015 21:59
A quick try/catch for the login method that will help you determine if a user has uninstalled your Shopify app.
//Try to get the user's subscription charge. If it returns a 404 "Not Found" message,
//then their subscription is no longer valid.
try
{
charge = await service.GetAsync(user.ShopifyChargeId.Value);
}
catch (ShopifyException e)
when (e.Message.Equals("not found", StringComparison.OrdinalIgnoreCase))
{
await DeleteChargeId(user);
@nozzlegear
nozzlegear / CreateSnippet.cs
Created October 27, 2015 20:49
This is a quick and dirty example to show how you can add and replace a liquid snippet in a Shopify theme's layout file via the Asset API.
//Using ShopifySharp from https://github.com/nozzlegear/ShopifySharp
using ShopifySharp;
...
public void MySnippetCreatorMethod()
{
var service = new ShopifyAssetService(myShopifyUrl, accessToken);
var themeId = 123456;
var asset = new ShopifyAsset()