Skip to content

Instantly share code, notes, and snippets.

@paigecook
paigecook / UrlExists.cs
Created January 31, 2011 15:09
Check if a Url exists
public static bool UrlExists(string url)
{
try
{
var request = WebRequest.Create(url) as HttpWebRequest;
if (request == null) return false;
request.Method = "HEAD";
using (var response = (HttpWebResponse)request.GetResponse())
{
return response.StatusCode == HttpStatusCode.OK;
@paigecook
paigecook / DidNotWork.xml
Created March 18, 2011 15:24
Settings that worked when MvcBuildViews is set to true.
<Target Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
<AspNetCompiler VirtualPath="temp" PhysicalPath="$(ProjectDir)\..\$(ProjectName)" />
</Target>
public static DbContextExtensions
{
public static void EntryAsModified<T>(this DbContext context, T entity) where T : class
{
context.Entry(entity).State = EntityState.Modified;
}
public static void EntriesAsModified<T>(this DbContext context, IEnumerable<T> entities) where T : class
{
foreach(var entity in entities)
@paigecook
paigecook / Person.cs
Created May 31, 2011 12:26
EF Serialization Entity
using System.Collections.ObjectModel;
using System.Collections.Generic;
namespace MyTest
{
public class Person
{
public Person()
{
Tags = new Collection<Tag>();
@paigecook
paigecook / .gitignore
Created June 14, 2011 11:42
Git Ignore Settings
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
# Packages #
@paigecook
paigecook / Example.cs
Created June 24, 2011 15:51
SO Question 6466936
using System;
using System.Collections.Generic;
using System.Data.Entity;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
@paigecook
paigecook / NinjectKernelActivator.cs
Created October 9, 2012 19:35
Example of a Ninject IHttpControllerActivator for an ASP.NET Web Api project.
using System;
using System.Net.Http;
using System.Web.Http.Controllers;
using System.Web.Http.Dispatcher;
using Ninject;
namespace WebApiNinjectIHttpControllerActivator
{
public class NinjectKernelActivator: IHttpControllerActivator
{
@paigecook
paigecook / CookiesAwareWebClient.cs
Last active December 15, 2015 07:09
Cookies based authentication for NCrawler, overrides the base functionality of WebDownloaderV2
using System.Net;
namespace Crawler
{
public class CookiesAwareWebClient : WebClient
{
private CookieContainer outboundCookies = new CookieContainer();
private CookieCollection inboundCookies = new CookieCollection();
public CookieContainer OutboundCookies
@paigecook
paigecook / JSON-Example
Created August 8, 2013 12:40
Example JSON file for Blog Post 8/8/2013
{
"parameters":{
"tbdb":"nasapoc",
"service":"prefix",
"template":"service.json",
"term_prefix":"11"
},
"termHints":[
{
"name":"Soyuz T11",
@paigecook
paigecook / JSON-Class
Created August 8, 2013 12:41
Classes created from JSON-Example for Blog Post 8/8/2013
public class Rootobject
{
public Parameters parameters { get; set; }
public Termhint[] termHints { get; set; }
public int total { get; set; }
}
public class Parameters
{
public string tbdb { get; set; }