Skip to content

Instantly share code, notes, and snippets.

Avatar

AJ Tatum ajtatum

View GitHub Profile
View article_schema.json
{
"@context": "https://schema.org",
"@graph": [
{
"@type": "Place",
"@id": "https://ajtatumdigital.com/#place",
"address": {
"@type": "PostalAddress",
"addressLocality": "Fairfax",
"addressRegion": "VA",
@ajtatum
ajtatum / functions.php
Created Jan 28, 2022
Creating Custom WordPress Get Avatar Function
View functions.php
add_filter('get_avatar', 'ajtd_get_avatar', 10, 6);
function ajtd_get_avatar($avatar, $id_or_email, $size, $default, $alt) {
$args['size'] = (int) $size;
$url2x = get_avatar_url($id_or_email, array_merge($args, array('size' => $args['size'] * 2)));
$args = get_avatar_data($id_or_email, $args);
$url = $args['url'];
@ajtatum
ajtatum / country-helper.js
Created Aug 30, 2021
JavaScript Country Name To Code and Code To Country Name Functions
View country-helper.js
var countryNameToCode = {
'Afghanistan': 'AF',
'Aland Islands': 'AX',
'Albania': 'AL',
'Algeria': 'DZ',
'American Samoa': 'AS',
'Andorra': 'AD',
'Angola': 'AO',
'Anguilla': 'AI',
'Antarctica': 'AQ',
@ajtatum
ajtatum / docReady.js
Created Aug 23, 2021
Pure JavaScript docReady Function
View docReady.js
// add event cross browser
function addEvent(elem, event, fn) {
if (elem.addEventListener) {
elem.addEventListener(event, fn, false);
} else {
elem.attachEvent("on" + event, function () {
// set the this pointer same as addEventListener when fn is called
return fn.call(elem, window.event);
});
}
@ajtatum
ajtatum / RedisService.cs
Created Jan 19, 2021
Get Redis Cache Keys
View RedisService.cs
public async Task<List<string>> GetCacheKeys()
{
var cacheKeys = new List<string>();
var endpoints = Connection.GetEndPoints();
var keys = Connection.GetServer(endpoints.First()).KeysAsync();
var enumerator = keys.GetAsyncEnumerator();
while (await enumerator.MoveNextAsync())
{
var key = enumerator.Current;
@ajtatum
ajtatum / Startup.cs
Created Jan 15, 2021
ImageKit Client Hints
View Startup.cs
var imageCdnUrl = Configuration["CDN:Images:CdnUrl"];
app.Use(async (context, next) =>
{
context.Response.Headers.Add("Accept-CH", "viewport-width, width, dpr");
context.Response.Headers.Add("Feature-Policy", $"ch-viewport-width {imageCdnUrl};ch-width {imageCdnUrl};ch-dpr {imageCdnUrl};ch-device-memory {imageCdnUrl};ch-rtt {imageCdnUrl};ch-ect {imageCdnUrl};ch-downlink {imageCdnUrl}");
context.Response.Headers.Add("Permissions-Policy", $"ch-viewport-width {imageCdnUrl};ch-width {imageCdnUrl};ch-dpr {imageCdnUrl};ch-device-memory {imageCdnUrl};ch-rtt {imageCdnUrl};ch-ect {imageCdnUrl};ch-downlink {imageCdnUrl}");
await next();
});
@ajtatum
ajtatum / View.cshtml
Created Jan 15, 2021
Using Photo CDN Service
View View.cshtml
<img
src="@CdnHelper.ConvertToPhotoCdn($"{primaryMediaImage.ImageUrl}?tr=w-252")"
srcset="@CdnHelper.ConvertToPhotoCdn($"{primaryMediaImage.ImageUrl}?tr=w-252"),
@CdnHelper.ConvertToPhotoCdn($"{primaryMediaImage.ImageUrl}?tr=w-378") 1.5x,
@CdnHelper.ConvertToPhotoCdn($"{primaryMediaImage.ImageUrl}?tr=w-504") 2x,
@CdnHelper.ConvertToPhotoCdn($"{primaryMediaImage.ImageUrl}?tr=w-756") 3x,"
alt="@Model.Media.Title" title="@Model.Media.Title" class="coverphoto rounded hoverable" itemprop="image" sizes="252" />
@ajtatum
ajtatum / CdnService.cs
Created Jan 15, 2021
Azure Storage To Photo CDN
View CdnService.cs
public string ConvertToPhotoCdn(string imageUrl)
{
var cdnUrl = _appSettings.CDN.Images.CdnUrl;
return _appSettings.CDN.Images.UseCdn
? imageUrl.Replace(_appSettings.Azure.Storage.StorageBlobUrl, cdnUrl)
: imageUrl;
}
@ajtatum
ajtatum / bitlyservice.cs
Created Dec 7, 2020
Create Bitly Custom Backhalf (Public)
View bitlyservice.cs
public async Task<string> GetShortUrl(string longUrl, string customBitLink)
{
var shortContent = $"{{\"long_url\":\"{longUrl}\",\"group_guid\":\"groupGuid\",\"domain\":\"domain.com\"}}";
var shortenUrlRequest = new HttpRequestMessage(HttpMethod.Post, ShortenUrl)
{
Content = new StringContent(shortContent, Encoding.UTF8, "application/json")
};
shortenUrlRequest.Headers.Authorization = new AuthenticationHeaderValue("Bearer", _appSettings.BitlyApiToken);
@ajtatum
ajtatum / AuthKeyFilter.cs
Created Nov 17, 2020
AuthKeyFilter logic
View AuthKeyFilter.cs
public class AuthKeyFilter : ActionFilterAttribute
{
private readonly IdentityDbContext _context;
private readonly ILogger<AuthKeyFilter> _logger;
public AuthKeyFilter(IdentityDbContext context, ILogger<AuthKeyFilter> logger)
{
_context = context;
_logger = logger;
}