Skip to content

Instantly share code, notes, and snippets.

View jknopp's full-sized avatar
🏠
Working from home

Jon Knopp jknopp

🏠
Working from home
View GitHub Profile
@jknopp
jknopp / DefaultCacheHelper.cs
Created April 13, 2021 23:59
A cache wrapper that invalidates multiple objects based on string dependency keys.
/// <summary>
/// A cache wrapper that invalidates multiple objects based on string dependency keys.
/// </summary>
public class DefaultCacheHelper : ICacheHelper
{
private readonly IMemoryCache _cache;
private readonly ILogger<DefaultCacheHelper> _logger;
private readonly CacheSettingsConfig _cacheSettingsConfig;
// a place to hold cancellation tokens to invalidate the cache
private static readonly ConcurrentDictionary<string, CancellationTokenSource> _cancellationTokens = new ConcurrentDictionary<string, CancellationTokenSource>();
@jknopp
jknopp / Is_Port_Listening.ps1
Created April 13, 2021 22:30
Use PowerShell to find out if a port is listening on a remote server
Test-NetConnection <address> -p <port_number>
@jknopp
jknopp / Find_Largest_Objects_In_DB.sql
Last active March 22, 2022 20:05
SQL Find Largest Objects In DB
SELECT
t.NAME AS TableName,
i.name as indexName,
sum(p.rows) as RowCounts,
sum(a.total_pages) as TotalPages,
sum(a.used_pages) as UsedPages,
sum(a.data_pages) as DataPages,
(sum(a.total_pages) * 8) / 1024 as TotalSpaceMB,
(sum(a.used_pages) * 8) / 1024 as UsedSpaceMB,
(sum(a.data_pages) * 8) / 1024 as DataSpaceMB
@jknopp
jknopp / Find_Fragmented_Indexes.sql
Last active March 22, 2021 15:21
SQL Find Fragmented Indexes
SELECT S.name as 'Schema',
T.name as 'Table',
I.name as 'Index',
DDIPS.avg_fragmentation_in_percent,
DDIPS.page_count
FROM sys.dm_db_index_physical_stats (DB_ID(), NULL, NULL, NULL, NULL) AS DDIPS
INNER JOIN sys.tables T on T.object_id = DDIPS.object_id
INNER JOIN sys.schemas S on T.schema_id = S.schema_id
INNER JOIN sys.indexes I ON I.object_id = DDIPS.object_id
AND DDIPS.index_id = I.index_id
@jknopp
jknopp / TransformationExamples.cs
Created March 5, 2021 22:15
Forked from greggnakamura/gist:817caeda46d2c7ad1660
/* Transformation Examples */
// Ternary example
<%# !string.IsNullOrEmpty((string)Eval("ItemToTest")) ? "True" : "False" %>
<%# !String.IsNullOrEmpty(Eval("ItemToTest").ToString()) ? "True" : "False" %>
<%# !string.IsNullOrEmpty((string)Eval("CatalogLink")) ? "<p>For detailed curriculum and more, please visit the <a href=\"" + Eval("CatalogLink") + "\" target=\"_blank\">Course Catalog entry</a> for this program.</p>" : Eval("CatalogDescription") + "<br /><br /><strong>For detailed curriculum and more please visit the <a onclick=\"_gaq.push(['_trackEvent', 'Link', 'Click' 'Course Catalog Adult Education'])\" target=\"_blank\" href=\"" + Eval("CatalogLink") + "\">Course Catalog entry</a> for this program.</strong><br />" %>
<%# !String.IsNullOrEmpty(Eval("ScheduleOfBenefitsDownload").ToString()) || !String.IsNullOrEmpty(Eval("ProviderNetwork").ToString()) ? "<strong>Resources</strong><br>" : "" %>
/* ********** */
@jknopp
jknopp / DebugService.cs
Last active February 5, 2021 20:13
Determine if running in DEBUG mode
public interface ISystemService
{
bool IsRunningInDebugMode();
}
public class SystemService : ISystemService
{
private bool _debugging;
public bool IsRunningInDebugMode()
@jknopp
jknopp / DataTableExtensions.cs
Last active February 2, 2021 19:09
Helpful DataRow/DataTable Extensions
public static class DataTableExtensions
{
public static List<T> ToList<T>(this DataTable table) where T : new()
{
IList<PropertyInfo> properties = typeof(T).GetProperties().ToList();
List<T> result = new List<T>();
foreach (var row in table.Rows)
{
var item = CreateItemFromRow<T>((DataRow)row, properties);
@jknopp
jknopp / index.js
Created January 6, 2021 18:08
Example Webpack config
// https://github.com/PButcher/flipdown
import { FlipDown } from 'flipdown';
@jknopp
jknopp / .zshrc
Created December 29, 2020 03:51
Example .zshrc Config File (https://pastebin.com/UWHMV2QF)
# https://youtube.com/c/cognitivesurge
export ZSH="/Users/karl/.oh-my-zsh"
ZSH_THEME="robbyrussell"
plugins=(
git
bundler
dotenv
osx
# setup font settings
font_family FuraCode Nerd Font
font_size 18.0
# no bells. Ever.
enable_audio_bell no
bell_on_tab no
# default layout is vertical splits only
enabled_layouts splits