Skip to content

Instantly share code, notes, and snippets.

View ianfnelson's full-sized avatar

Ian Nelson ianfnelson

View GitHub Profile
@ianfnelson
ianfnelson / Main.cs
Last active February 16, 2020 20:42
Colour Blanket
static void Main(string[] args)
{
var darkSky = new DarkSky.Services.DarkSkyService("API_KEY_HERE");
var date = new DateTime(2020,1,1);
do
{
var forecast = darkSky.GetForecast(53.812174, -1.096165,
new OptionalParameters{MeasurementUnits ="uk2", ForecastDateTime = date}).Result;
@ianfnelson
ianfnelson / RedisApiOutputCache.cs
Created August 4, 2015 11:54
An implementation of WebApi.OutputCache.Core.Cache.IApiOutputCache that uses Redis as the cache.
using System;
using System.Collections.Generic;
using System.Configuration;
using StackExchange.Redis;
using WebApi.OutputCache.Core.Cache;
namespace IanNelsonSystems
{
/// <summary>
/// An implementation of WebApi.OutputCache.Core.Cache.IApiOutputCache that uses Redis as the cache.
@ianfnelson
ianfnelson / toyota.js
Created September 18, 2014 13:24
Snippet from 2008 blog post "Looking Under The Hood"
if (selectedDate > maxAvailableDay) {
alert ("Please note, your online service booking must be between 5 and 90 days from today. If you wish to book a service outside of this period, please contact your local Toyota Contre directly.");
return false;
}
if (selectedDate < nextAvailableDay) {
alert ("Please note, your online service booking must be between 2 and 90 days from today. If you wish to book a service outside of this period, please contact your local Toyota Centre directly.");
return false;
}
@ianfnelson
ianfnelson / AS1.xml
Created September 18, 2014 13:21
Snippet from 2009 blog post "appSettings considered harmful"
<appSettings>
<add key="SmtpServer" value="smtp.mycompany.com" />
<add key="bgColor" value="lightsteelblue" />
<!-- <add key="connstr" value="Server=TestDB;initial catalog=DBName;Integrated Security=SSPI" /> -->
<add key="connstr" value="Server=LiveDB;initial catalog=DBName;Integrated Security=SSPI" />
<add key="PageSize" value="20" />
<add key="Homepage" value="/default.aspx" />
<add key="FooServiceLicenseKey" value="YR39-WN51-CB73-DF62" />
<add key="SendEmails" value="True" />
<add key="FontName" value="Arial" />
@ianfnelson
ianfnelson / MN1.cs
Created September 18, 2014 13:17
Snippet from 2009 blog post ".NET - Retrieving the Month Name"
/// <summary>
/// Converts a month number into the name
/// </summary>
/// <param name="monthNumber"></param>
private string GetMonthName(int monthNumber)
{
return String.Format("{0:MMMM}", new DateTime(1969, monthNumber, 1));
}
@ianfnelson
ianfnelson / SRP1
Created September 18, 2014 13:16
Snippet for 2009 blog post "SRP Doesn't Stand For Several Responsibility Principle"
/// <summary>
/// Send an email to notify that accrual data has been successfully uploaded
/// </summary>
/// <param name="accrualUpload"></param>
/// <param name="recipientAddresses"></param>
public void SendSuccessfulUploadEmail(AccrualUpload accrualUpload, Collection<MailAddress> recipientAddresses)
@ianfnelson
ianfnelson / CWARG1.cs
Created September 18, 2014 13:02
Snippets for 2009 blog post "Castle Windsor Array Resolution Gotcha"
/// <summary>
/// Initializes a new instance of the LeadAllocationService class.
/// </summary>
/// <param name="leadAllocators">Array of Lead Allocators.</param>
public LeadAllocationService(params ILeadAllocator[] leadAllocators)
{
this.LeadAllocators = leadAllocators;
}
@ianfnelson
ianfnelson / MVCG1.cs
Created September 18, 2014 12:56
Snippets for 2010 blog post "An MVC Gotcha and the PRG Pattern"
using System;
namespace MvcGotcha1.Models
{
public class FooModel
{
public int FooCounter { get; set; }
}
}
@ianfnelson
ianfnelson / WCFNH_1.cs
Created September 18, 2014 12:38
Snippets for 2010 blog post "WCF - NHibernate Unit Of Work Endpoint Behavior"
using System;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
/// <summary>
/// Being a custom EndpointBehavior added to the WCF services such that each operation begins a
/// new unit of work when invoked, and closes the same unit of work after invocation.
/// </summary>
/// <remarks>
/// In practice, we are using this simply to manage NHibernate sessions - opening a new Session at
@ianfnelson
ianfnelson / TL1.cs
Created September 18, 2014 12:30
Snippets for 2009 blog post "Testing LINQ Queries"
/// <summary>
/// Finds leads in the repository by Customer Name.
/// </summary>
/// <param name="repo" />Repository of Leads</param>
/// <param name="customerName" />Customer name</param>
/// <returns>Leads matching the criteria</returns>
public static IQueryable<Lead> ByCustomerName(this IQueryable<Lead> repo, string customerName)
{
if (customerName.IsNullOrEmpty())
{