Skip to content

Instantly share code, notes, and snippets.

View aannenko's full-sized avatar

Andrii Annenko aannenko

View GitHub Profile
@aannenko
aannenko / CryptSharp.cs
Last active August 30, 2023 17:18
CryptSharp - crypt(3) via C# and .NET Core (min .NET Core version = 2.1; min .NET Standard = 2.1)
using System;
namespace Crypt
{
public static class CryptSharp
{
private const string m_encryptionSaltCharacters =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789./";
private const int m_desIterations = 16;

FreePlay CM3 Software setup

At the time of writing of this guide, the current version of the image is Freeplay_CM3-and-Zero2_Test_22061501.img.gz

Things you need

  • FreePlay board (the board), bundled screen
  • Raspberry Pi CM3 or CM3+ module
  • at least a 2 Ampere phone charger with a Micro USB
  • microSD (one of the best for RPi 3/4 is Samsung EVO+)
  • USB keyboard
@aannenko
aannenko / BruteForce.cs
Last active October 16, 2021 05:20
Efficient Brute Force generator that can be consumed by foreach. Replace contents of Program.cs in your .NET 5 project with the following code and run.
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;
@aannenko
aannenko / AwaiterTaskSource.cs
Last active November 11, 2023 19:45
One Task, many awaiters - starts a task, issues awaiter-tasks for it, tracks the task until it's finished or all awaiter-tasks are cancelled.
#nullable enable
using System;
using System.Threading;
using System.Threading.Tasks;
public sealed class AwaiterTaskSource<TResult>
{
private readonly CancellationTokenSource _cancellationTokenSource;
private int _awaitersCount = 0;
// 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
{
// 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
{
@aannenko
aannenko / Node.cs
Last active May 6, 2024 07:30
Trie
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)
{
@aannenko
aannenko / BinarySearch.cs
Created May 30, 2024 14:20
Binary search, iterative and recursive
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)
{
@aannenko
aannenko / RotatedBinarySearch.cs
Last active June 2, 2024 09:05
Binary search with support for rotated arrays with duplicates
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;
@aannenko
aannenko / Book.cs
Created June 4, 2024 14:00
Library management OOP/SOLID
namespace LibraryManager;
public sealed record Book(string Name, bool CanBeBorrowed, int? AgeRating) : ILibraryItem;