Skip to content

Instantly share code, notes, and snippets.

View jfoshee's full-sized avatar
🗺️
Exploring

Jacob Foshee jfoshee

🗺️
Exploring
View GitHub Profile
using TechTalk.SpecFlow;
using Xunit;
namespace Example.SpecFlowTests.Hooks;
[Binding]
public class SkipHook
{
[BeforeScenario(tags: "skip")]
public static void BeforeScenario()
public static class StreamReaderExtensions
{
public static IEnumerable<string> ReadLines(this StreamReader reader)
{
string? line;
while ((line = reader.ReadLine()) is not null)
{
yield return line;
}
}
@jfoshee
jfoshee / ActionDisposable.cs
Created August 20, 2022 19:40
Convenient wrapper for an Action that must be called in spite of exceptions. Use with a `using` statement.
using System;
/// <summary>
/// Convenient wrapper for an Action that must be called in spite of exceptions.
/// Use with a `using` statement.
/// <code>
/// using var _ = new ActionDisposable(action);
/// </code>
/// </summary>
public class ActionDisposable : IDisposable
function downloadBlob(blob: Blob, filename: string): void {
const downloadLink = document.createElement('a');
document.body.appendChild(downloadLink);
downloadLink.style.setProperty('display', 'none');
const objectUrl = URL.createObjectURL(blob);
downloadLink.href = objectUrl;
downloadLink.download = filename;
downloadLink.click();
URL.revokeObjectURL(objectUrl);
function toPromise(dbRequest: IDBRequest<any>): Promise<any> {
return new Promise((resolve, reject) => {
dbRequest.onsuccess = () => resolve(dbRequest.result);
dbRequest.onerror = () => reject();
});
}
@jfoshee
jfoshee / HttpMocking.cs
Last active June 8, 2021 19:39
Extensions for Mock<IHttpClientFactory> that help setup the HttpClient with fake response content
using Moq;
using System;
using System.Net.Http;
namespace Example.Testing
{
public static class HttpMocking
{
public static void SetupHttpClient(this Mock<IHttpClientFactory> httpClientFactory, string response = "")
{
@jfoshee
jfoshee / TypeExtensions.cs
Created May 26, 2021 19:40
Helpful extension methods for System.Type
using System;
namespace Example
{
public static class TypeExtensions
{
/// <summary>
/// Returns a default value for a given Type at run-time.
/// </summary>
public static object GetDefaultValue(this Type type)
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Xunit.Sdk;
namespace Example.Testing
{
/// <summary>
<?xml version="1.0" encoding="utf-8"?>
<!-- copy to ~/Library/XamarinStudio-5.0/Snippets/ as vmpc.template.xml -->
<CodeTemplates version="3.0">
<CodeTemplate version="2.0">
<Header>
<_Group>C#</_Group>
<Version />
<MimeType>text/x-csharp</MimeType>
<Shortcut>vmpc</Shortcut>
<_Description>property changed</_Description>
@jfoshee
jfoshee / CodeFirstDatabase.cs
Created May 9, 2014 21:03
Sorts ServiceStack.OrmLite POCO table definitions so they can be created without violating foreign key constraints using QuickGraph's topological sort.
using System;
using System.Collections.Generic;
using System.Linq;
using QuickGraph;
using QuickGraph.Algorithms;
using ServiceStack.OrmLite;
namespace Gists
{
public static class CodeFirstDatabase