Skip to content

Instantly share code, notes, and snippets.

View davepcallan's full-sized avatar

Dave Callan davepcallan

View GitHub Profile
@davepcallan
davepcallan / rateLimit.graphql
Created March 12, 2024 00:34
How to get remaining and used limits on GitHub GraphQL API
{
rateLimit {
limit
remaining
used
resetAt
}
repository(owner: "dotnet", name: "runtime") {
pullRequests(states: MERGED, first: 50, orderBy: {field: CREATED_AT, direction: DESC}) {
edges {
@davepcallan
davepcallan / Example.md
Last active March 13, 2024 08:09
Get Merged PRs from dotnet/runtime using GitHub GraphQL API

image

@davepcallan
davepcallan / PRsByUser.graphql
Created March 11, 2024 22:05
Search for PRs in dotnet/runtime by a particular user
{
search(query: "repo:dotnet/runtime is:pr author:stephentoub", type: ISSUE, first: 100) {
edges {
node {
... on PullRequest {
title
url
number
createdAt
state
@davepcallan
davepcallan / MergedPRsInDotnetRuntime.graphql
Created March 11, 2024 21:55
GitHub GraphQL query to get last 100 (by created date) Merged Pull Requests in Dotnet runtime repo
{
repository(owner: "dotnet", name: "runtime") {
pullRequests(states: MERGED, first: 100, orderBy: {field: CREATED_AT, direction: DESC}) {
edges {
node {
title
url
number
mergedAt
reviewDecision
@davepcallan
davepcallan / ChatGPTAPIExample.cs
Created March 7, 2024 13:02
Simple example of integrating with ChatGPT API from .NET
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using System.Text;
using System.Text.Json;
namespace Samples;
public class ChatGPTAPIExample(ILogger<ChatGPTAPIExample> logger, IConfiguration configuration)
{
private string Prompt = "Please explain the following code :";
@davepcallan
davepcallan / GetRuntimeInformation.cs
Created March 4, 2024 02:47
Get runtime information
using System;
using System.Runtime.InteropServices;
public class C {
static void Main(string[] args)
{
Console.WriteLine(RuntimeInformation.OSDescription);
Console.WriteLine(RuntimeInformation.ProcessArchitecture.ToString());
Console.WriteLine(RuntimeInformation.FrameworkDescription);
}
@davepcallan
davepcallan / GlobalExceptionHandlerProblemDetails.cs
Last active March 3, 2024 04:55
Example of using .NET 8 IExceptionHandler to return 7807 ProblemDetails compliant response to client
using Microsoft.AspNetCore.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using System.Net;
namespace Samples;
public class GlobalExceptionHandler(ILogger<GlobalExceptionHandler> logger) : IExceptionHandler
{
public async ValueTask<bool> TryHandleAsync(
HttpContext httpContext,
@davepcallan
davepcallan / GlobalExceptionHandler.cs
Last active March 2, 2025 13:40
ASP.NET 8 Global exception handling with IExceptionHandler example
using Microsoft.AspNetCore.Diagnostics;
namespace Samples;
public class GlobalExceptionHandler(ILogger<GlobalExceptionHandler> logger) : IExceptionHandler
{
public ValueTask<bool> TryHandleAsync(
HttpContext httpContext,
Exception exception,
CancellationToken cancellationToken)
@davepcallan
davepcallan / CollectionExpressions.cs
Created February 13, 2024 12:52
Creating list with regular v collection expression approach in .NET 8
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Environments;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Reports;
[Config(typeof(Config))]
[HideColumns(Column.Job, Column.RatioSD, Column.AllocRatio)]
[MemoryDiagnoser]
@davepcallan
davepcallan / StringContains.cs
Last active April 23, 2024 16:21
In .NET 9 string.contains("X") will delegate to string.contains('X')
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Environments;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Reports;
using BenchmarkDotNet.Running;
BenchmarkSwitcher.FromAssembly(typeof(Program).Assembly).Run(args);