Skip to content

Instantly share code, notes, and snippets.

@papyr
papyr / Numeric.cs
Created October 1, 2022 16:42 — forked from cimnine/Numeric.cs
A way to check if a type is numeric in C#
using System;
namespace ch.cimnine.Util
{
public sealed class Numeric
{
/// <summary>
/// Determines if a type is numeric. Nullable numeric types are considered numeric.
/// </summary>
/// <remarks>
@papyr
papyr / commands.sh
Created August 15, 2022 00:39 — forked from manoj-choudhari-git/commands.sh
.NET Upgrade Assistant - Install, Analyze and Upgrade Commands
## Install the .NET Upgrade Assistant
dotnet tool install -g upgrade-assistant
## Update the .NET Upgrade Assistant
dotnet tool update -g upgrade-assistant
## Uninstall the .NET Upgrade Assistant
dotnet tool uninstall -g upgrade-assistant
## Analyze
@papyr
papyr / ZipMultiple.cs
Created January 21, 2022 02:40 — forked from ChuckSavage/ZipMultiple.cs
It seems an oversight on the .Net team to not enable multiple arrays to be passed to Enumerable.Zip. So I've created up to seven overloaded Zip extensions that borrow from the code by Eric Lippert here: http://blogs.msdn.com/b/ericlippert/archive/2009/05/07/zip-me-up.aspx
using System;
using System.Collections.Generic;
namespace ZipMany
{
/// <summary>
/// Zip multiple arrays (more than 2 since there is a built in Zip for 2 with .Net 4.0)
/// </summary>
public static class ZipMultiple
{
@papyr
papyr / XmlLinqConversionExtensions.cs
Created January 21, 2022 02:40 — forked from ChuckSavage/XmlLinqConversionExtensions.cs
Convert To/From XmlDocument and XDocument/XElements
using System.Xml;
using System.Xml.Linq;
namespace XmlLib
{
/// <summary>
/// Provides extension methods for simple conversion between System.Xml and System.Xml.Linq classes.
/// </summary>
/// <remarks>From: http://brianary.blogspot.com/2010/02/converting-between-xdocument-and.html</remarks>
public static class XmlLinqConversionExtensions
@papyr
papyr / ObservableValue
Created January 21, 2022 02:39 — forked from ChuckSavage/ObservableValue
Observe the changes in a value
public class ObservableValue<T> : INotifyPropertyChanged
{
public class MyArgs : PropertyChangedEventArgs
{
public MyArgs(string propertyName, T old, T @new)
: base(propertyName)
{
Old = old;
New = @new;
}
@papyr
papyr / AppendImageExtension.cs
Created January 21, 2022 02:39 — forked from ChuckSavage/AppendImageExtension.cs
C# Is file an image and get its type
// Includes a mini-program for checking and fixing files that have no extension
// Only checks for the most common types
// If you create a better version, please upload it here.
using System;
using System.Collections.Generic;
using System.IO;
namespace AppendJPG
{
@papyr
papyr / migrate-b4-to-b5.sh
Created August 26, 2021 07:16 — forked from Juan-escobar94/migrate-b4-to-b5.sh
Migrate bootstrap 4 classes to bootstrap 5.
set -x
set -e
# e.g. folder to process e.g. "frontend/"
migration_folder=$1
find_regex=".*/*.tsx?" # mach all .ts and .tsx files
# include trailing path "/" in folder parameter: e.g "frontend/" instead of just "frontend"
ignore_path="*/$1node_modules/*"
# Back up your files or change sed argument -i to -i.bak to generate backup files
find $migration_folder -regextype posix-egrep -regex $find_regex -type f -not -path $ignore_path | xargs sed -i -E '/[(class)(")]/{
s/([mp])l(-[0-5])/\1s\2/g
@papyr
papyr / gist:a49b7fc8ac7ae48e6ccfa0fd6b7250b3
Created March 29, 2018 21:06 — forked from RolandPheasant/gist:91cb2d3cb685eab49a937c1afbd7d60e
Populate JobInfoRepository observable data
public class JobInfoRepository : IDisposable
{
private readonly IDisposable _cleanUp;
public IObservableCache<JobInfo, int> Results { get; }
public JobInfoRepository()
{
var readWriteCache = new SourceCache<JobInfo, int>(ji => ji.JobID);
Results = readWriteCache.AsObservableCache();
public static class SqlObservations
{
public static IObservable<IEnumerable<IDataRecord>> MonitorChanges(string connectionString, string sql)
{
/*
1. read data from database and return results
2. monitor changes
3. when there is a change, repeat the whole process
*/
@papyr
papyr / =ChromeDevToolsSnippets.md
Created August 6, 2016 18:14 — forked from zaus/=ChromeDevToolsSnippets.md
Chrome DevTools Snippets (because it doesn't save when you clear your user data...)