Skip to content

Instantly share code, notes, and snippets.

Shannon Deminick Shazwazza

Block or report user

Report or block Shazwazza

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@Shazwazza
Shazwazza / DisableUserPermissionsNodes.cs
Created May 18, 2017
For Umbraco, the ability to not render any user permissions tree nodes based on the current user
View DisableUserPermissionsNodes.cs
using System.Threading;
using umbraco.cms.presentation.Trees;
using Umbraco.Core;
using Umbraco.Core.Security;
namespace Test
{
public class MyStartup : ApplicationEventHandler
{
/// <summary>
@Shazwazza
Shazwazza / UserAdminCreateOnly.cs
Created May 18, 2017
Using Umbraco events to enforce a specific user to only being allowed to create users but not update them
View UserAdminCreateOnly.cs
using System.Threading;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
using Umbraco.Core.Security;
namespace Test
{
public class MyStartup : ApplicationEventHandler
{
@Shazwazza
Shazwazza / UsingUmbracoRelationService.cs
Created May 18, 2017
Using the Umbraco Relation Service to relate items on a saved event based on property values
View UsingUmbracoRelationService.cs
using System;
using System.Linq;
using System.Text.RegularExpressions;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
using HtmlAgilityPack;
using Umbraco.Web;
using Umbraco.Web.Templates;
@Shazwazza
Shazwazza / cast-vs-oftype.md
Last active Jan 4, 2017
Linq Cast vs OfType
View cast-vs-oftype.md

With BencharkDot net, this benchmark creates a list of 10,000 strings then tests either OfType<T> or Cast<T>

Here's the benchmark code:

/// <summary>
/// Want to check what is faster OfType or Cast when a enurable all has the same items
/// </summary>
[Config(typeof(Config))]
public class LinqCastBenchmarks
@Shazwazza
Shazwazza / gist:6d75bca3f98d7ef98378
Created Jun 11, 2015
Umbraco 7.3 - Enable DatabaseServerMessenger
View gist:6d75bca3f98d7ef98378
public class LoadBalancingConfigurationEventHandler : ApplicationEventHandler
{
protected override void ApplicationStarting(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
//Replace the server messenger:
ServerMessengerResolver.Current.SetServerMessenger(new BatchedDatabaseServerMessenger(
applicationContext,
true,
//You can customize some options by setting the options parameters here:
@Shazwazza
Shazwazza / gist:cdb64b221f8fdc568acf
Created May 4, 2015
hal with templated embedded resource hrefs
View gist:cdb64b221f8fdc568acf
{
"TotalResults": 14,
"TotalPages": 3,
"Page": 1,
"_links": {
"self": {
"href": "/beers?page=1"
},
"next": {
"href": "/beers?page=2"
@Shazwazza
Shazwazza / gist:931885e682b8fe34220e
Created Sep 10, 2014
CachedPartial with contextualKeyBuilder
View gist:931885e682b8fe34220e
@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
Returns a synchronous Task instance
View SyncTask
var task = new Task(() =>
{
//do stuff;
});
task.RunSynchronously();
return task;
@Shazwazza
Shazwazza / TaskHelpers
Created May 9, 2014
Snippet of System.Threading.Tasks.TaskHelpers used in Web Api formatters to RunSynchronously
View TaskHelpers
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 Jan 24, 2019
How to inspect assemblies before including them in your application with reflection
View gist:7147978
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>
You can’t perform that action at this time.