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 / WrappedList.cs
Created October 8, 2014 19:37
Creating a custom thread-safe List<T> in C# that supports Add, Remove and Yank
using System;
using System.Linq;
using System.Collections.Generic;
namespace SampleNamespace
{
class WrappedList<T>
{
private List<T> list = new List<T>();
private object sync = new object();
@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 / ContentType.cs
Last active November 23, 2022 04:11
C# ContentType Enum full source code
using System;
using System.Reflection;
namespace Grapevine
{
public enum ContentType
{
[Metadata(Value = "application/x-authorware-bin", IsBinary = true)]
AAB,
@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 / clipboard-example.html
Last active April 13, 2022 08:38
JavaScript Copy To Clipboard Example
<!doctype html>
<html lang=en>
<head>
<meta charset=utf-8>
<title>Copy To Clipboard Example</title>
</head>
<body>
<input id="txtToCopy" type="text">
<button id="btnCopy">Copy!</button>
@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 / encode.html
Created July 2, 2014 21:19
Base64 Encode/Decode using HTML JavaScript
<!doctype html>
<html lang=en>
<head>
<meta charset=utf-8>
<title>Encode/Decode Base64</title>
<style type="text/css">
body
{
margin: 0px;