Skip to content

Instantly share code, notes, and snippets.

@Wind010
Wind010 / RSACryptoServiceProviderExtensions.cs
Last active March 6, 2018 02:16 — forked from Jargon64/RSACryptoServiceProviderExtensions.cs
RSACryptoServiceProvider Extension to add FromXmlString and ToXmlString methods for ASP.NET Core
using System;
using System.Security.Cryptography;
using System.Xml;
namespace RSACryptoServiceProviderExtensions
{
public static class RSACryptoServiceProviderExtensions
{
public static void FromXmlString(this RSACryptoServiceProvider rsa, string xmlString)
{
@Wind010
Wind010 / OperationLogger.cs
Created September 26, 2019 21:04
OperationLogger
using System;
using System.Diagnostics;
namespace Profiler
{
using Serilog;
using Serilog.Events;
public class OperationLogger : Stopwatch, IDisposable
{
@Wind010
Wind010 / ObjectExtensions.cs
Last active December 22, 2019 03:01
Extensions for objects.
using GraphQL;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Reflection;
namespace Extensions
{
public static class ObjectExtensions
{
public static T ToObject<T>(this IDictionary<string, object> dict)
@Wind010
Wind010 / preRequestScript.js
Last active January 14, 2020 00:24 — forked from ptrstpp950/preRequestScript.js
Calculate TOTP in Postman
//Article about TOTP on my blog https://stapp.space/generate-totp-in-postman/
/**
* @preserve A JavaScript implementation of the SHA family of hashes, as
* defined in FIPS PUB 180-4 and FIPS PUB 202, as well as the corresponding
* HMAC implementation as defined in FIPS PUB 198a
*
* Copyright Brian Turek 2008-2017
* Distributed under the BSD License
* See http://caligatio.github.com/jsSHA/ for more information
@Wind010
Wind010 / UpdateTargetFramework.sh
Last active January 16, 2020 22:57
Bash script to update all .csproj to .NET 3.1. Relevant to API and Test projects. Exclude libraries that are targeting .NET Standard
find . -name "*.csproj" -exec sed -b -i "s,<TargetFramework>[^<]*</TargetFramework>,<TargetFramework>netcoreapp3.1</TargetFramework>," {} \;
@Wind010
Wind010 / ResilientHttpClientWithProxyExtension.cs
Created February 21, 2020 02:07
Example of an extension that uses Polly and WebProxy to configure HttpClients created by an IHttpClientFactory
using System;
using System.Configuration;
using System.Net;
using System.Net.Http;
using System.Security.Cryptography.X509Certificates;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace Something
@Wind010
Wind010 / RunCmdnSubDir.sh
Last active February 23, 2020 03:39
Run command in all sub-directories in current directory
for dir in */; do (cd "$dir" && <your_cmd_here>); done
#For example could be a git command.
#for dir in */; do (cd "$dir" && git pull); done
@Wind010
Wind010 / Startup.cs
Last active March 8, 2020 02:22
Enums serialized as strings for ASP.NET Core 3.1 using System.Text.Json.Serialization
using System.Text.Json.Serialization
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers().AddJsonOptions(opts =>
opts.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()));
}
@Wind010
Wind010 / MockResponseFeature.cs
Created April 19, 2020 06:01
A mock response for testing HttpContext.Response.
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Threading.Tasks;
namespace Starbucks.CustomerEngagement.Serilog.Enrichers.Tests
{
@Wind010
Wind010 / standardize_proxy.sh
Created June 13, 2020 02:17
Used to replace exported Apigee proxy with expected pipeline tokens. Can be a pre-commit githook.
#!/bin/bash.
# Author: wind.TWD@gmail.com
# Description: Used to replace exported Apigee proxy with expected pipeline tokens. Can be a pre-commit githook.
# Notes:
# Generally I wouldn't parse XML/HTML with regex, use xmlstarlet, but whatever.
# Can run the commands without the -i to test.
blue="\e[104m"
normal=$(tput sgr0)
proxy_name="PROXY_NAME"