Skip to content

Instantly share code, notes, and snippets.

View jwatney's full-sized avatar

Jonathon Watney jwatney

View GitHub Profile
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using Dapper;
using Microsoft.EntityFrameworkCore;
public static class DbContextExtensions {
public static IQueryable<object> Set(this DbContext context, Type type) {
#!/bin/bash
log="$(mktemp)"
email="[email protected]"
mount /media/Backup &&
rsync -vax --delete --ignore-errors --log-file=$log /media/Data/ /media/Backup/ &&
umount /media/Backup &&
(cat $log | mail -s "[rsync] Mirror Data drive $(date)" $email) &&
rm $log
@jwatney
jwatney / gist:3869360
Created October 11, 2012 00:19
Class decorator that proxies class attributes.
def proxy(proxied="instance"):
def real_proxy(cls):
def get_attribute(self, name):
try:
return object.__getattribute__(self, name)
except AttributeError:
if type("instance") == type(proxied):
return object.__getattribute__(getattr(self, proxied), name)
else:
return object.__getattribute__(getattr(self, "instance"), name)
@jwatney
jwatney / TypeUtil.cs
Created April 8, 2012 18:54
Fast Property Info-type class.
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Reflection;
namespace TypeUtil {
public static class TypeExtensions {
public static FastPropertyInfo<T> GetProperty<T>(this Type type, string name) {
return type.GetProperty<T>(name, BindingFlags.Default);
}
@jwatney
jwatney / MoqDataExtensions
Created April 8, 2012 06:20
Moq extensions for mocking ADO.NET interfaces.
using System;
using System.Collections;
using System.Data;
using Moq;
namespace Moq.DataExtensions {
public static class MockFactoryDataExtensions {
public static Mock<IDbCommand> CreateIDbCommand(this MockFactory factory) {
var command = factory.Create<IDbCommand>();