Skip to content

Instantly share code, notes, and snippets.

View savaged's full-sized avatar
418

David Savage savaged

418
View GitHub Profile
@savaged
savaged / FPish.cs
Last active February 22, 2023 08:27
FP styled C# example inspired by Isaac Abraham's book Programming With F#
using Unit = System.ValueTuple;
_ = App.Run(Console.WriteLine);
static class App
{
public static Unit Run(Action<string> outputter)
{
outputter(GetAwayWins().ToSummary());
return Unit.Create();
@savaged
savaged / ReverseEach.cs
Last active February 4, 2023 08:45
Demonstrating that the equivalent to the Haskell map function in C# is the Select in Linq
/*
* Trying to emulate the following Haskell, with the aim of demonstrating
* that the map function in C# is the Select in Linq...
*
* main = do
* print (reverseEach ["map", "select"])
*
* reverseEach l = map reverse l
*
*/
@savaged
savaged / Rot13.cs
Last active October 21, 2022 08:15
Caesar Cipher in C# (with Linq)
if (args?.Count() > 0)
Console.WriteLine(args[0].Select(c =>
c switch
{
>= 'a' and <= 'm' or >= 'A' and <= 'M' => (char)(c + 13),
>= 'n' and <= 'z' or >= 'N' and <= 'Z' => (char)(c - 13),
_ => c
}
).ToArray());
@savaged
savaged / coding-principles-map.wiki
Created May 5, 2022 09:32
Some coding principles / things to remember

```

                                   +----------------+
    +--------------------+         | B ehaviour     |
    | ctor for structure |         | D riven        |  
    | Load for data      |         | D evelopment   |
    +--------------------+         |         G iven |
                                   |         W hen  |
      +---------------------+      |         T hen  |
      | prefer aggregation¹ |      +----------------+
      |  to inheritance²    |     

@primaryobjects
primaryobjects / readme.md
Last active January 31, 2024 19:43
How to remote desktop from Linux Mint to Windows 10 with AzureAD Azure AD login

How to remote desktop from Linux Mint to Windows 10 with AzureAD

The following steps detail how to connect over Remote Desktop from Linux Mint or Ubuntu to Windows 10 with an AzureAD username and password login account.

  1. In Windows 10, right-click This PC or My Computer and select Properties.
  2. Click Remote Settings.
  3. Check the option Allow remote connections to this computer.
  4. Uncheck the option Allow connections only from computers running Remote Desktop with Network Level Authentication.
  5. Click OK.
@savaged
savaged / FizzBuzz.cs
Last active October 12, 2022 10:00
Fizz Buzz
// Using top-level statements (see https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/tutorials/top-level-statements)
// and Linq along with pattern matching (see https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/functional/pattern-matching)
Enumerable.Range(1, 100).Select(
i =>
(i % 3, i % 5) switch
{
(0, 0) => "FizzBuzz",
(0, _) => "Fizz",
(_, 0) => "Buzz",
@krisleech
krisleech / renew-gpgkey.md
Last active April 22, 2024 20:13
Renew Expired GPG key

Renew GPG key

Given that your key has expired.

$ gpg --list-keys
$ gpg --edit-key KEYID

Use the expire command to set a new expire date:

@heroheman
heroheman / ranger-cheatsheet.md
Last active May 1, 2024 08:42
Ranger Cheatsheet

Ranger Cheatsheet

General

Shortcut Description
ranger Start Ranger
Q Quit Ranger
R Reload current directory
? Ranger Manpages / Shortcuts
@doncadavona
doncadavona / Aes256CbcEncrypterApp.cs
Last active October 29, 2023 09:30
A sample C# class to encrypt and decrypt texts using the cipher AES-256-CBC used in Laravel.
using System;
using System.Text;
using System.Security.Cryptography;
using System.Web.Script.Serialization;
using System.Collections.Generic;
namespace Aes256CbcEncrypterApp
{
class MainClass
{
@GeorgDangl
GeorgDangl / MockHttpClient.cs
Last active October 6, 2021 13:47
Mock an Asp.Net Core HttpClient with a custom HttpMessageHandler using Moq
using System;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Moq;
using Moq.Protected;
namespace Tests
{
public class MockHttpClient