Skip to content

Instantly share code, notes, and snippets.

View Shazwazza's full-sized avatar

Shannon Deminick Shazwazza

View GitHub Profile
@Shazwazza
Shazwazza / gist:cdb64b221f8fdc568acf
Created May 4, 2015 04:25
hal with templated embedded resource hrefs
{
"TotalResults": 14,
"TotalPages": 3,
"Page": 1,
"_links": {
"self": {
"href": "/beers?page=1"
},
"next": {
"href": "/beers?page=2"
@Shazwazza
Shazwazza / gist:931885e682b8fe34220e
Created September 10, 2014 00:01
CachedPartial with contextualKeyBuilder
@Html.CachedPartial(
//partial view name
"myPartialView",
//the model to pass the view - this will be the same object passed to the contextualKeyBuilder delegate
Model,
//seconds to cache
123,
//the key builder delegate, accepts the model passed in to the cached partial and the current
// viewdata dictionary of the partial view
contextualKeyBuilder: (model, viewdata) =>
@Shazwazza
Shazwazza / SyncTask
Created May 9, 2014 01:19
Returns a synchronous Task instance
var task = new Task(() =>
{
//do stuff;
});
task.RunSynchronously();
return task;
@Shazwazza
Shazwazza / TaskHelpers
Created May 9, 2014 01:13
Snippet of System.Threading.Tasks.TaskHelpers used in Web Api formatters to RunSynchronously
internal static Task<TResult> RunSynchronously<TResult>(Func<TResult> func, CancellationToken cancellationToken = default(CancellationToken))
{
if (cancellationToken.IsCancellationRequested)
{
return Canceled<TResult>();
}
try
{
return FromResult(func());
@Shazwazza
Shazwazza / gist:7147978
Last active June 11, 2023 10:34
How to inspect assemblies before including them in your application with reflection
public class PackageBinaryInspector : MarshalByRefObject
{
/// <summary>
/// Entry point to call from your code
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="dllPath"></param>
/// <param name="errorReport"></param>
/// <returns></returns>
/// <remarks>