Skip to content

Instantly share code, notes, and snippets.

View IEvangelist's full-sized avatar
:octocat:
Coding for a better world 🤓

David Pine IEvangelist

:octocat:
Coding for a better world 🤓
View GitHub Profile
internal static class HttpClientExtensions
{
internal static async Task GetAsync(
this HttpClient client,
string requestUri,
Stream destination,
IProgress<float> progress,
CancellationToken cancellationToken = default)
{
using HttpResponseMessage response = await client.GetAsync(
@IEvangelist
IEvangelist / GitHubFlavoredMarkdown.md
Created February 1, 2024 20:29 — forked from Myndex/GitHubFlavoredMarkdown.md
GitHub Flavored Markdown Cheat Sheet
@IEvangelist
IEvangelist / IDistributedCache.cs
Last active April 29, 2023 00:23
Proposed new APIs for the `IDistributedCache` interface.
public interface IDistributedCache
{
T? GetOrCreate(string key, Func<DistributedCacheEntryOptions, T> factory)
{
var bytes = Get(key);
if (bytes is { Length: > 0 })
{
var payload = Encoding.UTF8.GetString(bytes);
return JsonSerializer.Deserialize<T>(payload);
}
/*
Requests the navigator.mediaDevices for video input.
*/
export async function requestVideoDevices() {
try {
// Ask the first time to prime the underlying device list.
let devices = await navigator.mediaDevices.enumerateDevices();
if (devices &&
(devices.length === 0 || devices.every(d => d.deviceId === ""))) {
await navigator.mediaDevices.getUserMedia({
@IEvangelist
IEvangelist / Program.cs
Last active December 2, 2021 06:32
Minimal API — Azure Cosmos DB repository-pattern .NET SDK
// GitHub: 👨🏽‍💻 https://github.com/ievangelist
// Twitter: 🤓 https://twitter.com/davidpine7
// SDK: 🛠️ https://github.com/IEvangelist/azure-cosmos-dotnet-repository
using System.ComponentModel.DataAnnotations;
using Microsoft.Azure.CosmosRepository;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddCosmosRepository();
#nullable enable
using System;
using System.Net.Http;
using System.Net.Http.Json;
using System.Text.Json;
JsonSerializerOptions _options = new()
{
PropertyNameCaseInsensitive = true
@IEvangelist
IEvangelist / potential-worker-template.cs
Last active May 24, 2021 02:20
Potential worker service template improvements.
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Example.App;
using IHost host = Host.CreateDefaultBuilder(args)
.ConfigureServices(services => services.AddHostedService<Worker>())
.Build();
await host.RunAsync();
using System;
using System.Collections.Generic;
static IEnumerable<int> Fibonacci(int max)
{
int current = 1, next = 1;
while (current < max)
{
yield return current;
next = current + (current = next);
@IEvangelist
IEvangelist / Program.cs
Created May 3, 2021 13:29
Simplified ASP.NET Core `Program` file
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using Company.WebApplication1;
await Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder => webBuilder.UseStartup<Startup>())
.Build()
.RunAsync();
public readonly struct EnumerableRange : IEnumerable<int>
{
readonly Range _range;
public EnumerableRange(Range range)
{
if (range.Start.IsFromEnd || range.End.IsFromEnd)
{
throw new ArgumentException(nameof(range));
}