Skip to content

Instantly share code, notes, and snippets.

View motowilliams's full-sized avatar

Eric Williams motowilliams

View GitHub Profile
@motowilliams
motowilliams / CleanHostHeaders.cs
Created March 13, 2014 15:57
Returns the first segment past known TlDs
/// <summary>
/// Returns the first segment past known TLDs
/// </summary>
/// <param name="uri">Source Uri</param>
/// <param name="tlds">http://data.iana.org/TLD/tlds-alpha-by-domain.txt</param>
/// <returns>Target Uri</returns>
private static Uri CleanHostHeaders(Uri uri, IEnumerable<string> tlds)
{
// IANA currently has the list upper case
string host = uri.Host.ToUpper();
### Keybase proof
I hereby claim:
* I am motowilliams on github.
* I am motowilliams (https://keybase.io/motowilliams) on keybase.
* I have a public key whose fingerprint is 2278 835C 6893 B62C 4227 54B2 E716 0927 C824 8D4C
To claim this, I am signing this object:
@motowilliams
motowilliams / trello-css-guide.md
Last active August 29, 2015 14:27 — forked from bobbygrace/trello-css-guide.md
Trello CSS Guide

Trello CSS Guide

“I perfectly understand our CSS. I never have any issues with cascading rules. I never have to use !important or inline styles. Even though somebody else wrote this bit of CSS, I know exactly how it works and how to extend it. Fixes are easy! I have a hard time breaking our CSS. I know exactly where to put new CSS. We use all of our CSS and it’s pretty small overall. When I delete a template, I know the exact corresponding CSS file and I can delete it all at once. Nothing gets left behind.”

You often hear updog saying stuff like this. Who’s updog? Not much, who is up with you?

This is where any fun you might have been having ends. Now it’s time to get serious and talk about rules.

Writing CSS is hard. Even if you know all the intricacies of position and float and overflow and z-index, it’s easy to end up with spaghetti code where you need inline styles, !important rules, unused cruft, and general confusion. This guide provides some architecture for writing CSS so it stays clean and ma

@motowilliams
motowilliams / _config.yml
Created October 22, 2011 07:16 — forked from edavis10/_config.yml
Pagination in Jekyll
# ....other stuff here
paginate: 10
@motowilliams
motowilliams / SessionStateExtensions.cs
Created October 23, 2011 18:30
Asp-net-MVC-Session-State-Extension-Method
public static class SessionStateExtensions
{
public static void Put<T>(this HttpSessionStateBase httpSession, T value) where T : class
{
httpSession[typeof (T).FullName] = value;
}
public static void Put<T>(this HttpSessionStateBase httpSession, string key, T value) where T : class
{
httpSession[typeof (T).FullName + key] = value;
@motowilliams
motowilliams / StringExtensions.cs
Created October 23, 2011 18:47
Checking-for-special-characters-using-LINQ
public static class StringExtensions
{
public static bool HasInvalidCharacters(this string value)
{
//Ascii range between 32 and 127
IEnumerable<int> lowRange = Enumerable.Range(0, 32);
IEnumerable<int> highRange = Enumerable.Range(128, 128);
IEnumerable<int> enumerable = value.ToCharArray().Select(x => Convert.ToInt32(((int)x).ToString()));
return lowRange.Intersect(enumerable).Count() != 0 || highRange.Intersect(enumerable).Count() != 0;
}
@motowilliams
motowilliams / Extension-Methods-Improving-the-quality-of-Life01.cs
Created October 23, 2011 19:27
Extension-Methods-Improving-the-quality-of-Life
foreach( var validationResult in validationResults )
{
bindingContext.ModelState
.AddModelError( validationResult.MemberNames.FirstOrDefault(), validationResult.ErrorMessage );
}
@motowilliams
motowilliams / Extension-Methods-Improving-the-quality-of-Life02.cs
Created October 23, 2011 19:30
Extension-Methods-Improving-the-quality-of-Life
bindingContext.ModelState.AddModelErrors(validationResults);
@motowilliams
motowilliams / Extension-Methods-Improving-the-quality-of-Life03.cs
Created October 23, 2011 19:30
Extension-Methods-Improving-the-quality-of-Life
public static class ModelStateExtensions
{
public static void AddModelErrors(this ModelStateDictionary values, IEnumerable<ValidationResult> validationResults)
{
foreach (var validationResult in validationResults)
values.AddModelError(validationResult.MemberNames.FirstOrDefault(), validationResult.ErrorMessage);
}
}
@motowilliams
motowilliams / Extension-Methods-Improving-the-quality-of-Life04.cs
Created October 23, 2011 19:30
Extension-Methods-Improving-the-quality-of-Life
ValidationContext validationContext = new ValidationContext( someEditModel, null, null );
List<ValidationResult> validationResults = new List<ValidationResult>();
bool isValid = Validator.TryValidateObject( someEditModel, validationContext, validationResults );
if( !isValid )
{
//do something maybe ...
bindingContext.ModelState.AddModelErrors(validationResults);
}