Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Phil Cooper restlessmedia

🎯
Focusing
View GitHub Profile
View ClientDisconnectedConnectionAdapter.cs
/// <summary>
/// Creates a connection adapter that cancels any <see cref="IDbCommand"/> created from it when the client disconnects from the response.
/// </summary>
private class ClientDisconnectedConnectionAdapter : IDbConnection
{
private readonly SqlConnection _connection;
public conn(SqlConnection sqlConnection)
{
_connection = sqlConnection ?? throw new ArgumentNullException(nameof(sqlConnection));
View DefaultEncoder.cs
using ImageResizer;
using ImageResizer.Configuration;
using ImageResizer.Encoding;
using ImageResizer.Plugins;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
namespace ImageResizer.CustomPlugins
View DelegatingStream.cs
public class DelegatingStream : Stream
{
Stream stream;
protected DelegatingStream(Stream stream)
{
if (stream == null)
throw new ArgumentNullException("stream");
this.stream = stream;
View createPaginator.js
const createPaginator = (endpoint, resultKey) => {
const createRequestPageActionCreator = (endpoint, resultKey) => (page) => requestPage(endpoint, resultKey, page)
const requestPage = (page) => ({
type: 'REQUEST_PAGE',
payload: {
page
},
meta: {
View LinqExtensions.cs
public static class LinqExtensions
{
public static IQueryable<TSource> Page<TSource>(this IQueryable<TSource> source, IPageable pageable)
{
return Page<IQueryable<TSource>, TSource>(source, pageable);
}
public static IQueryable<TSource> Page<TSource>(this IQueryable<TSource> source, int page, int maxPerPage = 10)
{
return Page<IQueryable<TSource>, TSource>(source, page, maxPerPage);
@restlessmedia
restlessmedia / Example.cs
Created Sep 14, 2016
Entity Framwork GridReader for multiple result sets.
View Example.cs
public DataModel GetDataModel(int id)
{
const string sql = "map.GetDataModel @id=@id";
using (DbContext context = new DbContext(_connectionString))
{
using (GridReader reader = new GridReader(context, sql, new SqlParameter("@id", id)))
{
DataModel model = reader.Read<DataModel>().FirstOrDefault();
model.NestedArray = reader.Read<Nested>().ToArray();
@restlessmedia
restlessmedia / CommandInterceptionOptions.cs
Last active Sep 7, 2016
Entity Framework DbCommandInterception for instrumentation.
View CommandInterceptionOptions.cs
public class CommandInterceptionOptions
{
public CommandInterceptionOptions()
{
WarningThreshold = TimeSpan.FromSeconds(2);
}
public TimeSpan WarningThreshold { get; set; }
public static CommandInterceptionOptions Default = new CommandInterceptionOptions();
@restlessmedia
restlessmedia / BindAsAttribute.cs
Last active Aug 24, 2016
.Net Mvc bind abstract properties
View BindAsAttribute.cs
using System;
namespace MvcApplication1
{
public class BindAsAttribute : Attribute
{
public BindAsAttribute(Type modelType)
{
ModelType = modelType;
}
View AsyncTraceListener.cs
public abstract class AsyncTraceListener : TraceListener
{
public AsyncTraceListener()
{
_loggingThread = new Thread(new ThreadStart(ProcessQueue))
{
// this is performed from a bg thread, to ensure the queue is serviced from a single thread
IsBackground = true
};
_loggingThread.Start();
View WebConfiguration.cs
public class WebConfiguration
{
public WebConfiguration(string path = "~", bool autoSave = true, bool autoRefresh = true)
{
if (string.IsNullOrWhiteSpace(path))
throw new ArgumentNullException("path");
_autoSave = autoSave;
_autoRefresh = autoRefresh;
_configuration = Open(path);