This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var client = new HttpClient(); | |
var regex = new Regex( | |
"\"(?<magnet>magnet:\\?.*?)\"", | |
RegexOptions.Compiled | RegexOptions.NonBacktracking | RegexOptions.ExplicitCapture); | |
using var stream = await client.GetStreamAsync(@"https://nnmclub.to/forum/viewtopic.php?t=1716490"); | |
using var reader = new StreamReader(stream); | |
string? line; | |
while ((line = await reader.ReadLineAsync()) is not null) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.AspNetCore.Routing.Constraints; | |
using System.Text.Json.Serialization; | |
var builder = WebApplication.CreateSlimBuilder(args); | |
builder.Services.ConfigureHttpJsonOptions( | |
options => options.SerializerOptions.TypeInfoResolverChain.Insert(0, AppJsonSerializerContext.Default)); | |
builder.Services.Configure<RouteOptions>( | |
options => options.SetParameterPolicy<RegexInlineRouteConstraint>("regex")); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace LibraryManager; | |
public sealed record Book(string Name, bool CanBeBorrowed, int? AgeRating) : ILibraryItem; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Console.WriteLine(RotatedBinarySearch([6, 7, 8, 9, 10, 1, 2, 3, 5], 3)); // 7 | |
Console.WriteLine(RotatedBinarySearch([1, 1, 1, 1, 1, 1, 2, 1, 1, 1], 2)); // 6 | |
static int RotatedBinarySearch(int[] ints, int searchedValue) | |
{ | |
var low = 0; | |
var high = ints.Length - 1; | |
while (low <= high) | |
{ | |
var mid = low + (high - low) / 2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ints = new int[] { 2, 3, 4, 10, 40 }; | |
Console.WriteLine(IndexOfUsingIterativeBinarySearch(ints, 3)); // 1 | |
Console.WriteLine(IndexOfUsingRecursiveBinarySearch(ints, 0, ints.Length - 1, 3)); // 1 | |
static int IndexOfUsingIterativeBinarySearch(int[] ints, int searchedValue) | |
{ | |
int low = 0; | |
int high = ints.Length - 1; | |
while (low <= high) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public sealed class Node | |
{ | |
private readonly Dictionary<char, Node> _children = []; | |
public IReadOnlyCollection<Node> Children => _children.Values; | |
public string? Word { get; private set; } | |
public Node GetOrAddChild(char letter, string? word = null) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Introduction to Algorithms, Third Edition - 2009 | |
using System; | |
using System.Collections.Generic; | |
Console.WriteLine(string.Join(' ', new[] { 2, 8, 7, 1, 3, 5, 6, 4 }.QuickSort())); | |
Console.WriteLine(string.Join(' ', new[] { 31, 41, 59, 26, 41, 58 }.QuickSort())); | |
static class ArrayExtensions | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Introduction to Algorithms, Third Edition - 2009 | |
using System; | |
using System.Collections.Generic; | |
Console.WriteLine(string.Join(' ', new[] { 5, 2, 4, 6, 1, 3 }.InsertionSortOptimized())); | |
Console.WriteLine(string.Join(' ', new[] { 31, 41, 59, 26, 41, 58 }.InsertionSortOptimized())); | |
static class ArrayExtensions | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#nullable enable | |
using System; | |
using System.Threading; | |
using System.Threading.Tasks; | |
public sealed class AwaiterTaskSource<TResult> | |
{ | |
private readonly CancellationTokenSource _cancellationTokenSource; | |
private int _awaitersCount = 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
foreach (var text in new BruteForceEnumerable(2, "abc")) | |
Console.WriteLine(text.ToString()); | |
public class BruteForceEnumerable | |
{ | |
private readonly int _maxTextLength; | |
private readonly string _characters; |
NewerOlder