Skip to content

Instantly share code, notes, and snippets.

@davidbreyer
davidbreyer / EFDatabaseTemplate.cs
Last active August 29, 2015 14:07
Entity Framework Database Context Template
namespace YourProject.DatabaseIntialization
{
public sealed class YourDatabase : System.Data.Entity.DbContext
{
//List of database entities, for which tables will be created.
public DbSet<FirstEntity> FirstEntities { get; set; }
public DbSet<SecondEntity> SecondEntities { get; set; }
public YourDatabase() : base("DatabaseName") { } //This value will be the name of your database or the name of the connection string.
public class FakeResponseHandler : DelegatingHandler
{
private readonly Dictionary<Uri, HttpResponseMessage> _FakeResponses = new Dictionary<Uri, HttpResponseMessage>();
public void AddFakeResponse(Uri uri, HttpResponseMessage responseMessage)
{
_FakeResponses.Add(uri, responseMessage);
}
@davidbreyer
davidbreyer / Logger.cs
Last active August 29, 2015 14:22
Basic Logger class for Log4net
public static class Logger
{
private static string LogFile;
private static string LogLevel;
private static bool VerboseLogging;
static Logger()
{
LogFile = GetLoggingFileProperty();
LogLevel = GetLogLevelProperty();
@davidbreyer
davidbreyer / UnityConfig.cs
Created June 9, 2015 19:39
Basic Unity Container running Log4net extensions.
using System;
using Microsoft.Practices.Unity;
using UnityLog4NetExtension.Log4Net;
public static class UnityConfig
{
static IUnityContainer GetContainer()
{
var newContainer = new UnityContainer()
.AddNewExtension<LogCreation>() //Custom extension that executes logger setup
@davidbreyer
davidbreyer / LogActionWebApiFilter.cs
Last active March 21, 2017 16:55
Custom Web API Filter with Log4net logging.
public class LogActionWebApiFilter : ActionFilterAttribute
{
/// <summary>
/// Instance of the Log4Net log.
/// </summary>
[Dependency] //Part 1
public ILog Log { get; set; }
//This function will execute before the web api controller
//Part 2
@davidbreyer
davidbreyer / RegisterFilterProvidersMethod.cs
Last active August 29, 2015 14:22
The UnityActionFilterProvider class will build up custom filters in your web api project. The RegisterFilterProviders will call the buildup class.
private static void RegisterFilterProviders()
{
var providers =
GlobalConfiguration.Configuration.Services.GetFilterProviders().ToList();
GlobalConfiguration.Configuration.Services.Add(
typeof(System.Web.Http.Filters.IFilterProvider),
new UnityActionFilterProvider(UnityConfig.GetConfiguredContainer()));
var defaultprovider = providers.First(p => p is ActionDescriptorFilterProvider);
@davidbreyer
davidbreyer / ProfilingInterceptionBehavior.cs
Last active August 29, 2015 14:24
Example of a Unity Interceptor.
public class ProfilingInterceptionBehavior : IInterceptionBehavior
{
[Dependency]
public ILog Log { get; set; }
public IMethodReturn Invoke(IMethodInvocation input,
GetNextInterceptionBehaviorDelegate getNext)
{
// Code here will execute prior to the method that was called.
// Add any custom code you want to execute prior to intercepted method here.
@davidbreyer
davidbreyer / ProfilingInterceptionBehavior.cs
Last active August 29, 2015 14:24
Unity Interceptor to log the elapsed time of a method.
public class ProfilingInterceptionBehavior : IInterceptionBehavior
{
[Dependency]
public ILog Log { get; set; }
public IMethodReturn Invoke(IMethodInvocation input,
GetNextInterceptionBehaviorDelegate getNext)
{
//This behavior will record the start and stop time
//of a method and will log the method name and elapsed time.
@davidbreyer
davidbreyer / DateTimeLibrary.cs
Last active August 29, 2015 14:27
Get DateTimeOffset for a specified time zone.
public static DateTimeOffset GetCurrentDateTimeForTimeZone(string TimeZoneStandardName)
{
try
{
//Find specified time zone
var timeZone = TimeZoneInfo.FindSystemTimeZoneById((TimeZoneStandardName));
//Convert UTC time to a specified local time.
DateTime localTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, timeZone);
@davidbreyer
davidbreyer / Solar System Simulator 2.0 Pure CSS.markdown
Created March 11, 2016 00:25
Solar System Simulator 2.0 Pure CSS

Solar System Simulator 2.0 Pure CSS

I have done it again.. This time, using Haml and SCSS.

Version 1 was pretty filthy in terms of syntax, it was raw html and css, but now I just used algorithms to (hopefully) get everything pixel perfect. I added the glowing stars, which are really just circles 2x2 spawned in random positions increasing in opacity every couple of seconds.

Didn't think I'd be making another solar system, but after seeing how easy everything else was using a preprocessor, I thought why the hell not.

Also I finally worked out how to make the ring for saturn, also the moon is much better.