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 / remmina-azure-ad.md
Last active April 10, 2024 13:14 — forked from primaryobjects/readme.md
How to remote desktop from Linux to Windows 10 with AzureAD Azure AD login

How to remote desktop from Linux 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 / totp-fun.sh
Last active October 9, 2023 14:08
Fun with a very basic implementation of TOTP
#!/bin/sh
# generate shared secret for TOTP
secret='never gonna give you up'
# take only the last 16 characters less padding
# apply standard formatting (see https://github.com/google/google-authenticator/wiki/Key-Uri-Format )
# generate the QR code (remember to apply percent encoding for the url)
echo -n $secret | base32 | sed 's/=//g' | tail -c 16 | xargs -I $ echo 'otpauth://totp/savaged%20info:alice@test.com?secret=$&issuer=Savaged' | xargs qrencode -o ~/Downloads/savaged-qr-code.png
#finally, generate TOTP
@savaged
savaged / sofd.sh
Last active September 30, 2023 21:08
SOTD (scripture of the day)
#!/bin/sh
# dependencies: curl, grep, sed, html-xml-utils, lolcat and an internet connection
curl -s "https://wol.jw.org/en/wol/h/r1/lp-e/$(date +"%Y/%m/%d")" | grep -E -A5 "data-date=\"$(date +"%Y-%m-%d")" | grep -m 1 '\<themeScrp\>' | hxselect -c 'em' | sed 's/$/\n/g' | lolcat
@savaged
savaged / TEA.cs
Last active September 24, 2023 18:22
TEA implementation
// Credit to Page Brooks https://www.codeproject.com/Articles/6137/Tiny-Encryption-Algorithm-TEA-for-the-Compact-Fram
var key = "mykey";
var encrypted = Encrypt("testing", key);
var decrypted = Decrypt(encrypted, key);
Console.WriteLine(decrypted);
static string Encrypt(string data, string key)
{
if (data.Length == 0)
throw new ArgumentOutOfRangeException("data must be at least 1 character in length.");
@savaged
savaged / DiffieHellman
Last active September 24, 2023 16:58
High-level Diffie-Hellman key exchange
// public (primitive root) base¹, known to Alice, Bob, and Eve
const long G = 5;
// public (prime) modulus², known to Alice, Bob, and Eve
const long P = 23;
var aliceCalc = new Calc(6, G, P);
var bobCalc = new Calc(5, G, P);
// Alice's public key, known to Alice, Bob, and Eve. A = g^a mod p
long A = aliceCalc.GetPublicKey(bobCalc.OutgoingSharedKey);
@savaged
savaged / SavagedCipherCLI.cs
Last active July 17, 2023 07:38
Some fun with ciphers in C#
using System.Text;
App.Run(args, Console.WriteLine);
interface ICipherService
{
string Apply(string input, bool encrypt = false);
}
class XOrCipherService : ICipherService
@savaged
savaged / SeeFunPtr.c
Last active June 14, 2023 10:26
Fun with function pointers in C
// Program.h
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef int (*op_on_triple_ptr)(int, int, int);
typedef int (*op_on_pair_ptr)(int, int);
typedef int (*op_on_single_ptr)(int);
void cout_for_op(char* op_name, int op_result);
@savaged
savaged / OcrPostcodeCleaningEx.cs
Created March 31, 2023 14:04
Some regex to clean OCR 'O' for zero mistakes in UK postcodes
using System.Text.RegularExpressions;
foreach (var postcode in args)
Console.WriteLine(postcode.ReplaceAnyMisplacedO());
static class OcrPostCodeCleaningExtensions
{
public static string ReplaceAnyMisplacedO(this string postcode) =>
postcode.ReplaceAnyFrontO().ReplaceAnyEndO();
@savaged
savaged / YCombinator.cs
Created March 25, 2023 19:00
Trying to get my head around the y combinator
// Y = λf.(λx.f(x x))(λx.f(x x))
var factorial = YCombinator.Y<int, int>(recursiveFunc => num => num == 0 ? 1 : num * recursiveFunc(num - 1));
var fibonacci = YCombinator.Y<int, int>(recursiveFunc => num => num <= 1 ? 1 : recursiveFunc(num - 1) + recursiveFunc(num - 2));
// Test with sample inputs
Console.WriteLine(factorial(3));
Console.WriteLine(fibonacci(5));
// Implementation of Y combinator
@savaged
savaged / CurryConcept.cs
Created March 25, 2023 17:18
Fun tasting curry in C#
// See Computerphile: https://youtu.be/psmu_VAuiag
// add x y = x + y
Func<int, int, int> AddTwoParameters = (x, y) => x + y;
// map (add 100) [1..10]
Enumerable.Range(1, 10)
.Select(i => AddTwoParameters.AddLater()(100)(i))
.ToList()
.ForEach(i => Console.WriteLine(i));