Skip to content

Instantly share code, notes, and snippets.

using iText.Kernel.Pdf;
using iText.Kernel.Pdf.Canvas.Parser;
using iText.Kernel.Pdf.Canvas.Parser.Listener;
using Net.Code.Csv;
using System.Globalization;
using System.Text.RegularExpressions;
var folder = args[0];
var output = $"FOO {nameof(R)} BAR " + $" {f(nameof(R))} BAZ ";
Console.WriteLine(output);
string f(string s) => s;
public class R
{
}
// when compiled as a net6 console app in VS2022 preview 3.1, the above code produces an unexpected result
using System.Collections.Generic;
using System.Linq;
namespace System.Collections.Immutable
{
public class ImmutableListWithValueSemantics<T> : IImmutableList<T>, IEquatable<IImmutableList<T>>
{
IImmutableList<T> _list;
public ImmutableListWithValueSemantics(IImmutableList<T> list) => _list = list;
@jhgbrt
jhgbrt / code-quiz-001.cs
Last active May 22, 2017 16:11
Which values can the variable 'x' have in the code below, and why? Hint: compile in release mode if you want to try it...
using System;
using System.Threading.Tasks;
namespace CodeQuiz
{
class Program
{
static void Main()
{
ulong sharedValue = 0;
@jhgbrt
jhgbrt / IBANChecksum.cs
Last active March 6, 2020 10:38 — forked from DvdKhl/IBANChecksum.cs
Fast C# IBAN Checksum Verifier / Validation
//Copyright (C) 2013 DvdKhl
//Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
//to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
//and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
//WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Linq;
using System.Reflection;
namespace Tools
{
@jhgbrt
jhgbrt / Logger.cs
Last active October 24, 2016 07:35
using System;
using System.IO;
namespace Tools.Infrastructure
{
class Logger
{
static object _lock = new object();
public static void Info(string message)
{
@jhgbrt
jhgbrt / gist:9df92cb0a140804ea01c
Created November 23, 2015 14:55
azure api mgr trace
{
"traceId": "[snip]",
"traceEntries": {
"inbound": [
{
"source": "api-inspector",
"timestamp": "2015-11-23T14:38:14.3755947Z",
"elapsed": "00:00:00.0980973",
"data": {
"request": {
@jhgbrt
jhgbrt / Builder.cs
Last active August 27, 2015 08:32
Basic Functional Fluent Builder
using System;
using System.Collections.Generic;
// Factory methods provided in non-generic abstract base class
public abstract class Builder
{
public static Builder<T> For<T>() where T : new()
{
return new Builder<T>(() => new T());
}
@jhgbrt
jhgbrt / ByteArraySegment.cs
Last active December 30, 2015 08:30
helper class to manage a segment of a byte array, without copying the underlying array
/// <summary>
/// Helper class to manage a (part of) an array of T (similar to the BCL's ArraySegment, but actually providing some useful functionality)
/// </summary>
public class ArraySegment<T> : IEnumerable<T>
{
private readonly T[] _rawArray;
private readonly int _offset;
private readonly int _length;
public ArraySegment(T[] rawArray, int offset, int length)