Skip to content

Instantly share code, notes, and snippets.

@papyr
papyr / DelayedRenderExtensions.cs
Created August 6, 2016 17:59 — forked from zaus/DelayedRenderExtensions.cs
RenderSections in PartialViews -- delayed rendering of any HTML content. See SO answer: http://stackoverflow.com/a/18790222/1037948
public static class HtmlRenderExtensions {
/// <summary>
/// Delegate script/resource/etc injection until the end of the page
/// <para>@via http://stackoverflow.com/a/14127332/1037948 and http://jadnb.wordpress.com/2011/02/16/rendering-scripts-from-partial-views-at-the-end-in-mvc/ </para>
/// </summary>
private class DelayedInjectionBlock : IDisposable {
/// <summary>
/// Unique internal storage key
/// </summary>
/// <summary>
/// PGP round-trip encryption -- http://blogs.microsoft.co.il/kim/2009/01/23/pgp-zip-encrypted-files-with-c/#comment-611002
/// </summary>
public class PGPEncryptDecrypt
{
/**
* A simple routine that opens a key ring file and loads the first available key suitable for
* encryption.
*
* @param in
@papyr
papyr / SimpleServer.cs
Created August 6, 2016 18:11 — forked from anonymous/SimpleServer.cs
SimpleServer - makes echo testing from .NET unit tests easier
using System.IO;
// modified from RestSharp unit tests https://github.com/restsharp/RestSharp/blob/master/RestSharp.IntegrationTests/Helpers/SimpleServer.cs
namespace UnitTesting
{
using System;
using System.Net;
using System.Security;
using System.Threading;
@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...)
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 / 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();
@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 / 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 / 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 / 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