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 / 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 / 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-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; }
@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 / XML-Class
Created August 8, 2013 12:45
Classes created from XML-Example for Blog Post 8/8/2013
/// <remarks/>
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true)]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "", IsNullable = false)]
public partial class SEMAPHORE
{
private SEMAPHOREPARAMETER[] pARAMETERSField;
private SEMAPHORETERM_HINT[] tERM_HINTSField;
@paigecook
paigecook / XML-Example
Created August 8, 2013 12:47
Example XML file for Blog Post 8/8/2013
<?xml version="1.0" encoding="utf-8"?>
<SEMAPHORE>
<PARAMETERS>
<PARAMETER NAME='TBDB'>nasapoc</PARAMETER>
<PARAMETER NAME='SERVICE'>prefix</PARAMETER>
<PARAMETER NAME='TEMPLATE'>service.xml</PARAMETER>
<PARAMETER NAME='TERM_PREFIX'>11</PARAMETER>
</PARAMETERS>
<TERM_HINTS>
<TERM_HINT NAME='Soyuz T11' ID='OMII0IIN2112985674' INDEX='nasapoc' WEIGHT='39.1393' CLASS='Missions'>