Skip to content

Instantly share code, notes, and snippets.

View jfoshee's full-sized avatar
🗺️
Exploring

Jacob Foshee jfoshee

🗺️
Exploring
View GitHub Profile
@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
@jfoshee
jfoshee / PerformanceMeter.cs
Last active August 29, 2015 13:57
PerformanceMeter wraps System.Diagnostics.Stopwatch to easily accumulate basic performance measurements.
using System;
using System.Diagnostics;
namespace Unplugged.Visualization
{
public class PerformanceMeter
{
public int Count { get; private set; }
public double Minimum { get; private set; }
public double Maximum { get; private set; }
@jfoshee
jfoshee / Service Oriented ViewModel MonkeySpace 2013.md
Created July 27, 2013 01:04
Markdown source of slides I presented at MonkeySpace 2013

A Service Oriented ViewModel

Jacob Foshee

MonkeySpace 2013

Summary

  • Service not reinvented by 3rd party
  • VM not reinvented by 2nd device
  • VM Responsible for wrapping DTOs