Skip to content

Instantly share code, notes, and snippets.

View scottoffen's full-sized avatar
💭
Live in SLC

Scott Offen scottoffen

💭
Live in SLC
View GitHub Profile
@scottoffen
scottoffen / generate.sh
Created January 22, 2024 21:06
Generate a WebApi project structure
if test -d src; then
rm -rf src
fi
while getopts n: flag
do
case "${flag}" in
n) projectName=${OPTARG};;
esac
done
@scottoffen
scottoffen / Program.cs
Last active October 2, 2023 22:23
Swagger Exclude in ASP.NET 6.0
builder.Services.AddSwaggerGen(options =>
{
options.SchemaFilter<SwaggerExcludeFilter>();
options.DocumentFilter<SwaggerExcludeFilter>();
});
@scottoffen
scottoffen / deepDiff.js
Last active January 5, 2023 17:55
Deep compare two objects and return a list of discrepencies.
const deepDiff = (local, remote, prefix = "") => {
let diff = [];
if (local === null && remote === null) return diff;
if (local === null || remote === null) {
let lnull = (local === null) ? "null" : typeof (local);
let rnull = (remote === null) ? "null" : typeof (remote);
diff.push(`${prefix} (null): local is ${lnull} and remote is ${rnull}`);
return diff;
@scottoffen
scottoffen / Program.cs
Created December 7, 2022 21:33
Configure Rolling Logs in ASP.NET 6.0
using System.Diagnostics.CodeAnalysis;
namespace SampleApplication.Api
{
[ExcludeFromCodeCoverage]
public static class Program
{
private const string DefaultSettingsFile = "appsettings.json";
private static IConfiguration _configuration;
private static IConfiguration _loggerOptions;
@scottoffen
scottoffen / ExampleClient.cs
Last active April 19, 2022 01:43
API Token Renewal in ASP.NET 6.0
using System.Net.Http.Headers;
public interface IExampleClient
{
/* interface methods here */
}
public class ExampleClient : IExampleClient
{
public static string AccessToken { get; set; }
@scottoffen
scottoffen / header-in-iframe.js
Created March 16, 2022 21:02
How to send headers (e.g. authentication tokens) to iframes
<script>
var myIFrame = document.querySelector('#myiframe');
var myUrl = 'http://localhost:1234/api/test';
var myHeaders = [
['Authorization', 'Bearer 1234567890']
];
populateIFrame(myIFrame, myUrl, myHeaders);
function populateIFrame(iframe, url, headers)
@scottoffen
scottoffen / Program.cs
Created August 30, 2019 17:35
Make delegates from methods
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Linq;
namespace DelegateTesting
{
public class Program
{
public static void Main(string[] args)
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Runtime.Serialization;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
namespace Sandbox
{
public class ParagraphBuilder
{
public const int DefaultColumns = 86;
private string _input;
private int _columns;
private int _remaining;
private List<string> _output = new List<string>();
private List<string> _line = new List<string>();
@scottoffen
scottoffen / Rename.cs
Created January 31, 2019 22:49
Rename files downloaded from Packt via LinqPad
void Main()
{
var dir = @"Y:\Downloads\My Books\";
var filepaths = Directory.GetFiles(dir, "*.pdf", SearchOption.TopDirectoryOnly);
var pattern = @"^\d{13}\-(\w+)\.pdf$";
var regex = new Regex(pattern);
foreach (var filepath in filepaths)
{
var filename = Path.GetFileName(filepath);