Skip to content

Instantly share code, notes, and snippets.

Avatar

Adam Anderly anderly

View GitHub Profile
@anderly
anderly / Startup.cs
Last active Dec 12, 2019
MediatR Pipeline Behavior Registration.
View Startup.cs
// Register MediatR Pipeline Behaviors
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(LoggingBehavior<,>));
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(ValidationBehavior<,>));
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(CachingBehavior<,>));
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(FallbackBehavior<,>));
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(RetryBehavior<,>));
// ICachePolicy discovery and registration
services.Scan(scan => scan
.FromAssemblies(assembly)
@anderly
anderly / Details.cs
Last active Dec 12, 2019
MediatR Fallback Pipeline Behavior
View Details.cs
public class Handler : IRequestHandler<Query, Customer>, IFallbackHandler<Query, Customer>
{
private readonly ICustomerRepository _db;
private readonly ICustomerRepository<SourceSystem.Secondary> _db2;
private readonly IConfigurationProvider _configuration;
public Handler(ICustomerRepository db, ICustomerRepository<SourceSystem.Secondary> db2, IConfigurationProvider configuration)
{
_db = db;
_db2 = db2;
@anderly
anderly / Details.cs
Last active Dec 12, 2019
MediatR Retry Pipeline Behavior
View Details.cs
public class Handler : IRequestHandler<Query, Customer>, IRetryableRequest<Query, Customer>
{
private readonly CustomerContext _db;
private readonly IConfigurationProvider _configuration;
// By implementing IRetryableRequest<TRequest, TResponse> I get the following
// properties to control how my "Handle" method will get retried.
public int RetryAttempts => 2;
public int RetryDelay => 500;
public bool RetryWithExponentialBackoff => true;
@anderly
anderly / CacheService.cs
Last active Aug 23, 2021
MediatR Caching Pipeline Behavior
View CacheService.cs
public class CacheService : ICache
{
private readonly string _keyPrefix;
private readonly IDistributedCache _cache;
private readonly IConfiguration _config;
public CacheService(IDistributedCache cache, IConfiguration config)
{
_cache = cache;
_config = config;
@anderly
anderly / FilterMenu.vue
Last active Aug 16, 2019
Make Laravel Nova Per Page options configurable both globally and at resource level.
View FilterMenu.vue
<template>
<dropdown
v-if="filters.length > 0 || softDeletes || !viaResource"
dusk="filter-selector"
class-whitelist="flatpickr-calendar"
>
<dropdown-trigger
slot-scope="{ toggle }"
:handle-click="toggle"
class="bg-30 px-3 border-2 border-30 rounded"
@anderly
anderly / Index.vue
Created Mar 13, 2019
Make Index.vue support initializing viaResource, viaResourceId and viaRelationship from query string.
View Index.vue
<template>
<loading-view :loading="initialLoading" :dusk="resourceName + '-index-component'">
<custom-index-header v-if="!viaResource" class="mb-3" :resource-name="resourceName" />
<div v-if="shouldShowCards">
<cards
v-if="smallCards.length > 0"
:cards="smallCards"
class="mb-3"
:resource-name="resourceName"
@anderly
anderly / showdown.md
Last active Sep 17, 2016
Ideas for making ShowDown extensible
View showdown.md

Ideas for making ShowDown extensible:

I recently had to customize your plugin a bit for a client but wanted to suggest a few hooks and filters that could be added to the plugin to create some extensibility points for your customers.

Here are the hooks I added which would be great if you could add them into the main plugin so I could still get updates without having to do diffs when the plugin gets updated.

1st set of changes: Adding hooks to Anti-Cheat settings

File: wpshowdown.php
@anderly
anderly / woocommerce-add-custom-product-data-tab.php
Last active Jun 2, 2021
WooCommerce - Add Custom Product Data Tab
View woocommerce-add-custom-product-data-tab.php
// First Register the Tab by hooking into the 'woocommerce_product_data_tabs' filter
add_filter( 'woocommerce_product_data_tabs', 'add_my_custom_product_data_tab' );
function add_my_custom_product_data_tab( $product_data_tabs ) {
$product_data_tabs['my-custom-tab'] = array(
'label' => __( 'My Custom Tab', 'my_text_domain' ),
'target' => 'my_custom_product_data',
);
return $product_data_tabs;
}
@anderly
anderly / DFP Interstitial Ad
Last active Mar 13, 2017
DFP Interstitial Ad Code
View DFP Interstitial Ad
<script>
var DmagInterstitialAd = DmagInterstitialAd || {};
DmagInterstitialAd.showInterstitial = true;
DmagInterstitialAd.adWidth = 720;
DmagInterstitialAd.adHeight = 480;
DmagInterstitialAd.destinationURL = "http://ad.doubleclick.net/ddm/trackclk/N5716.759086CENTRO.NET/B8239828.110882020;dc_trk_aid=283955045;dc_trk_cid=59150503";
DmagInterstitialAd.embedCode = '<img src="http://ad.doubleclick.net/ddm/trackimp/N5716.759086CENTRO.NET/B8239828.110882020;dc_trk_aid=283955045;dc_trk_cid=59150503;ord=[timestamp]?" border="0" height="1" width="1" alt="Advertisement">';
/*-------------------------------------------------------------------------------------------------------*/
/* DO NOT MODIFY CODE BELOW */
@anderly
anderly / DFP Wallpaper Ad
Last active May 28, 2019
DFP Wallpaper Ad Code
View DFP Wallpaper Ad
<script>
var WallpaperAd = WallpaperAd || {};
/*-------------------------------------------------------------------------------------------------------*/
/* Two values are needed for Wallpaper Ads: */
/* 1.) destinationURL (where you want visitors to go when they click the wallpaper) */
/* - NOTE: Click-throughs to this URL will automatically be tracked in DFP */
/* 2.) backgroundURL (URL of wallpaper background image) */
/* - NOTE: Make sure to change the URL to start with
http://assets.dmagazine.com so that it is served via CloudFlare CDN (this makes pages and images load faster) */