Skip to content

Instantly share code, notes, and snippets.

View gabrieljoelc's full-sized avatar

Gabriel Chaney gabrieljoelc

View GitHub Profile
@gabrieljoelc
gabrieljoelc / CreateGitHubRepo.ps1
Last active December 20, 2015 19:48
CLI commands for github API v3 (replace all CAPS keywords). Ripped off from http://stackoverflow.com/a/10325316/34315.
Invoke-RestMethod -Uri https://api.github.com/user/repos `
-Body (@{"name"="REPO"} | ConvertTo-Json) `
-Credential 'USER' `
-Method Post `
git remote add origin [email protected]:USER/REPO.git
git push origin master
@gabrieljoelc
gabrieljoelc / Multiplicity.cs
Created August 13, 2013 15:51
Check if exactly none, exactly one, or many extension method from http://stackoverflow.com/a/6940337/34315 and http://stackoverflow.com/a/6059711/34315.
public static Multiplicity Multiplicity<TElement>(this IEnumerable<TElement> @this)
{
switch (@this.Take(2).Count())
{
case 0: return General.Multiplicity.None;
case 1: return General.Multiplicity.One;
case 2: return General.Multiplicity.Many;
default: throw new Exception("WTF‽");
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Dynamic;
namespace Core.Utils
{
public static class ReflectionExtensions
{
public static ExpandoObject ToExpando(this object values)
{
StringBuilder sUrl = new StringBuilder();
sUrl.Append("http://www.esvapi.org/v2/rest/passageQuery");
sUrl.Append("?key=IP");
sUrl.Append("&passage=" + Server.UrlEncode("Matthew 5").ToString());
sUrl.Append("&include-headings=true");
WebRequest oReq = WebRequest.Create(sUrl.ToString());
StreamReader sStream = new StreamReader(oReq.GetResponse().GetResponseStream());
public class ServiceLocatorStub : ServiceLocatorImplBase
{
private readonly IDictionary<Type, ICollection<object>>
registeredTypes = new Dictionary<Type, ICollection<object>>();
private ServiceLocatorStub()
{}
public ServiceLocatorStub AddInstance<TService>(TService instance)
{
public partial class FooBar
{
private int ID { get; set; }
private string Something { get; set; }
}
public partial class FooBar
{
public class PropertyAccessExpressions
{
@gabrieljoelc
gabrieljoelc / new_gist_file
Last active December 27, 2015 15:29
How to scan for and add EntityTypeConfigurations for Entity Framework. From http://romiller.com/2012/03/26/dynamically-building-a-model-with-code-first/
public class FooContext : DbContext
{
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
AddExplicitMappings(modelBuilder);
}
private static void AddExplicitMappings(DbModelBuilder modelBuilder)
{
var addMethod = typeof (ConfigurationRegistrar)
public abstract class BillingDetail
{
public int BillingDetailId { get; set; }
public string Owner { get; set; }
public string Number { get; set; }
}
[Table("BankAccounts")]
public class BankAccount : BillingDetail
{
@gabrieljoelc
gabrieljoelc / EF_WillDefaultToTPC.cs
Created November 7, 2013 03:42
Entity Framework 6 inheritance strategy defaults. Table per Hierarchy (TPH) - one table for all types with type discriminator column Table per Concrete Type (TPC) - one table per concrete type with common properties copied in each table From http://weblogs.asp.net/manavi/archive/2010/12/24/inheritance-mapping-strategies-with-entity-framework-cod…
public abstract class BillingDetail
{
public int BillingDetailId { get; set; }
public string Owner { get; set; }
public string Number { get; set; }
}
public class BankAccount : BillingDetail
{
public string BankName { get; set; }
public static class StringExtensions
{
public static string ToStringWithSpaces(this string input)
{
return Regex.Replace(
input,
"(?<!^)" + // don't match on the first character - never want to place a space here
"(" +
" [A-Z][a-z] |" + // put a space before "Aaaa"
" (?<=[a-z])[A-Z] |" + // put a space into "aAAA" before the first capital