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 / gist:11183775
Created April 22, 2014 15:32
Updating specific properties on an entity using Entity Framework
//Open database context
using(DbContext db = new DbContext())
{
//Get the id of the entity we want to update
int id = 1;
//Create an instance of the entity we want to update
SomeEntity entity = new SomeEntity(){
Id = id,
@nozzlegear
nozzlegear / gist:11183928
Created April 22, 2014 15:36
Updating all properties on an entity using Entity Framework
//Open database context
using(DbContext db = new DbContext())
{
//Get the id of the entity we want to update
int id = 1;
//Create an instance of the entity we want to update
SomeEntity entity = new SomeEntity(){
Id = id,
@nozzlegear
nozzlegear / gist:11184132
Created April 22, 2014 15:42
Never update certain entity properties using Entity Framework
//Open database context
using(DbContext db = new DbContext())
{
//Get the id of the entity we want to update
int id = 1;
//Create an instance of the entity we want to update
SomeEntity entity = new SomeEntity(){
Id = id,
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)
@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;
@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 / 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 / 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 / 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 / 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