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
#!/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:[email protected]?secret=$&issuer=Savaged' | xargs qrencode -o ~/Downloads/savaged-qr-code.png | |
#finally, generate TOTP |
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
#!/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 |
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
// 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."); |
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 (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); |
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.Text.RegularExpressions; | |
foreach (var postcode in args) | |
Console.WriteLine(postcode.ReplaceAnyMisplacedO()); | |
static class OcrPostCodeCleaningExtensions | |
{ | |
public static string ReplaceAnyMisplacedO(this string postcode) => | |
postcode.ReplaceAnyFrontO().ReplaceAnyEndO(); |
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
// 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 |
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
// 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)); |
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.Text.RegularExpressions; | |
if (args.Length == 0 || !args[0].IsUnixFileModeAndPermissionsString()) | |
{ | |
Console.WriteLine( | |
"Argument must be in the form of a UNIX file permission string, " + | |
"i.e. -rwxrwxrwx or -rwxr-xr-x etc."); | |
return; | |
} | |
Console.WriteLine(args[0].ToClasses().ToPermissionNumber()); |
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 customers = new List<(string Name, string Town)> | |
{ | |
("Isaac", "London"), | |
("Sara", "Birmingham"), | |
("Tim", "London"), | |
("Michelle", "Manchester") | |
}; | |
var customersByTownQuery = customers | |
.GroupBy(c => c.Town) |
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
\documentclass[12pt]{beamer} | |
\begin{document} | |
\title{Fun With \LaTeX} | |
\author{David Savage} | |
\maketitle | |
\begin{frame} | |
\frametitle{Net Algorythm} | |
Function to calculate net, given the gross amount\textsuperscript{a} and the percentage rate used\textsuperscript{b}. | |
\begin{displaymath} | |
f(a, r) = \frac{a}{(100+r)}\times100 |
NewerOlder