Skip to content

Instantly share code, notes, and snippets.

View bgrainger's full-sized avatar

Bradley Grainger bgrainger

View GitHub Profile
using MySqlConnector;
using System.Diagnostics;
var threadCount = args.Length == 1 && int.TryParse(args[0], out var tc) ? tc : 100;
var csb = new MySqlConnectionStringBuilder
{
Server = // REDACTED
UserID = // REDACTED
Password = // REDACTED
@bgrainger
bgrainger / BenchmarkResults.md
Last active February 13, 2023 05:34
Benchmark async/await options in C# 7
BenchmarkDotNet=v0.10.3.0, OS=Microsoft Windows 10.0.14393
Processor=Intel(R) Xeon(R) CPU E5-1650 v3 3.50GHz, ProcessorCount=12
Frequency=3410069 Hz, Resolution=293.2492 ns, Timer=TSC
dotnet cli version=1.0.1
  [Host]     : .NET Core 4.6.25009.03, 64bit RyuJIT
  DefaultJob : .NET Core 4.6.25009.03, 64bit RyuJIT

Method | Mean | StdDev | Gen 0 | Allocated

using Dapper;
using MySqlConnector;
await MethodToRunAsync();
async Task Method1Async()
{
using (var domain = new MySqlConnection())
{
await domain.OpenDBAsync();
internal static class NativeMethods
{
[DllImport("XpsPrint.dll", ExactSpelling = true, CharSet = CharSet.Unicode)]
public static extern int StartXpsPrintJob(string printerName, string jobName, string outputFileName, IntPtr progressEvent, SafeWaitHandle completionEvent,
[MarshalAs(UnmanagedType.LPArray)] byte[] printablePagesOn, int printablePagesOnCount, out IXpsPrintJob xpsPrintJob, out IXpsPrintJobStream documentStream, out IXpsPrintJobStream printTicketStream);
}
[ComImport, Guid("E974D26D-3D9B-4D47-88CC-3872F2DC3585"), ClassInterface(ClassInterfaceType.None)]
internal class XpsOMObjectFactory
{
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
namespace System.Runtime.CompilerServices
{
internal static class RuntimeHelpers
{
/// <summary>
/// Slices the specified array using the specified range.
async Task Main()
{
var httpClient = new HttpClient();
var html57 = await (await httpClient.GetAsync("https://dev.mysql.com/doc/mysql-errors/5.7/en/server-error-reference.html")).Content.ReadAsStringAsync();
var html8 = await (await httpClient.GetAsync("https://dev.mysql.com/doc/mysql-errors/8.0/en/server-error-reference.html")).Content.ReadAsStringAsync();
var valueNames = new Dictionary<int, string>();
foreach (MySqlErrorCode value in Enum.GetValues(typeof(MySqlErrorCode)))
{
var intValue = (int)value;
@bgrainger
bgrainger / About.md
Last active March 21, 2021 05:10
Reading Portable PDBs with System.Reflection.Metadata

Reading Embedded Portable PDBs

This example shows how to read an embedded portable PDB file using the System.Reflection.Metadata classes.

@bgrainger
bgrainger / ReadFileFragment.cpp
Created June 3, 2019 17:50
Improving WPF Text Display Performance
HRESULT FontFileStream::ReadFileFragment(const void ** fragmentStart, UINT64 fileOffset, UINT64 fragmentSize, void ** fragmentContext)
{
if (fragmentStart != nullptr)
*fragmentStart = nullptr;
if (fragmentContext != nullptr)
*fragmentContext = nullptr;
if (fragmentStart == nullptr || fragmentContext == nullptr)
return E_POINTER;
if (fileOffset >= m_length || fileOffset + fragmentSize > m_length)
return E_INVALIDARG;
@bgrainger
bgrainger / ReservedWords.cs
Created September 12, 2018 15:56
MySQL 8 reserved words
var reservedWords = new[]
{
"ACCESSIBLE",
"ADD",
"ALL",
"ALTER",
"ANALYZE",
"AND",
"AS",
"ASC",
void Main()
{
using (var writer = new StreamWriter(@"GetValueConversionTestBase.g.cs"))
{
writer.WriteLine("using System;");
writer.WriteLine("using System.CodeDom.Compiler;");
writer.WriteLine("using System.Data;");
writer.WriteLine("using System.Threading.Tasks;");
writer.WriteLine("using Xunit;");
writer.WriteLine("");