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 / .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
@jknopp
jknopp / index.js
Created January 6, 2021 18:08
Example Webpack config
// https://github.com/PButcher/flipdown
import { FlipDown } from 'flipdown';
@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 / 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 / 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 / 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 / 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 / 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 / QueryStore.sql
Last active May 26, 2021 21:00
SQL Query Store provides insight on query plan choice and performance.
--query store status
SELECT actual_state_desc, desired_state_desc, current_storage_size_mb,
max_storage_size_mb, readonly_reason
FROM sys.database_query_store_options;
--top 10 bad runners. This gives you the query ID to search for the query in SSMS->Query Store->Tracked Queries. Type in the ID, get details on the query.
SELECT TOP 10
qt.query_text_id,
q.query_id,
p.plan_id,
# Push to multiple remotes
# To do this, choose a remote ID which will refer to all the remotes.
# I usually call it all, but there are developers who prefer origin.
# The idea is to add all the remote repo URLs as “push URLs” to this remote.
# Here’s what you do:
# Create a new remote called "all" with the URL of the primary repo.
git remote add all git@github.com:jknopp/toggl2redmine.git
# Re-register the remote as a push URL.
git remote set-url --add --push all git@github.com:jknopp/toggl2redmine.git
# Add a push URL to a remote. This means that "git push" will also push to this git URL.