Skip to content

Instantly share code, notes, and snippets.

View wgrrrr's full-sized avatar

William Richards wgrrrr

View GitHub Profile
@wgrrrr
wgrrrr / gist:7778913
Last active December 30, 2015 04:49
Take an Array of ActiveRecord::Relation objects, extract their WHERE clauses and join them via a SQL OR operator. Allows you to conditionally build the relations based on business rules.
def merge_where_clause_with_or(relations)
relations.map { |relation| relation.arel.where_clauses }.join(' OR ')
end
# Usage
model.where(merge_where_clause_with_or(array_of_relations))
@wgrrrr
wgrrrr / Helpers.cshtml
Last active December 30, 2015 15:48
C# ASP.NET MVC JavaScript relative TimeAgoInWords using jQuery Timeago plugin. Place the Helpers.cshtml file (or its contents) into your App_Code directory.
@helper TimeAgoInWords(DateTime dateTime) {
<time class="timeago" datetime="@dateTime.ToString("yyyy-MM-ddTHH:mm:ssK")" title="@dateTime.ToString("f")">
@dateTime.ToString("f")
</time>
}

Keybase proof

I hereby claim:

  • I am wgrrrr on github.
  • I am wgrrrr (https://keybase.io/wgrrrr) on keybase.
  • I have a public key whose fingerprint is 22E7 27C6 BF05 441F 54F4 C72B 9FF4 A6CB 669A CC61

To claim this, I am signing this object:

@wgrrrr
wgrrrr / DbRepository.cs
Created April 2, 2014 01:16
A "query by example" implementation for Entity Framework 5 and C# 5 using a generic repository pattern.
/// <summary>
/// Uses the supplied entity as search criteria and returns matching records. When more than one entity properties
/// are populated it will use an AND in the query.
/// </summary>
/// <remarks>
/// Only simple properties such as strings and value types can be evaluated by this method. If you require a more
/// advanced query you should add an entity specific DbRepository class which extends this class.
/// </remarks>
/// <param name="example">The entity to use as an example</param>
public virtual IQueryable<TEntity> GetByExample(TEntity example)