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
bool theNumberIsEven (int number) => number % 2 == 0; | |
numbers.Where(theNumberIsEven); |
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
int[] numbers = { 1, 4, 7, 2, 8, 6, 9, 7, 1, 6, 10 }; | |
numbers.Where(number => number % 2 == 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
for (let numberToFactorise of numbersToFactorise) { | |
for (let possibleFactor = 1; possibleFactor <= numberToFactorise; possibleFactor++) { | |
if (numberToFactorise % possibleFactor === 0) | |
allFactors.push(numberToFactorise) | |
} | |
} |
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
const numbersToFactorise = [99999, 12, 15] | |
const allFactors = [] | |
for (let number of numbersToFactorise) { | |
for (let i = 1; i <= number; i++) { | |
if (number % i === 0) | |
allFactors.push(number) | |
} | |
} |
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
const numberToFactorise = 99999 | |
const confirmedFactors = [] | |
for (let i = 1; i <= numberToFactorise; i++) | |
{ | |
if(numberToFactorise % i === 0) | |
confirmedFactors.push(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
class PaymentUriBuilder | |
{ | |
private string QueryString => CreateQueryString(_queryStringCache.Exposed); | |
private string SafeQueryString => CreateQueryString(_queryStringCache.Redacted); | |
private readonly DoubleDic<string, string> _queryStringCache = | |
new DoubleDic<string ,string>(new SortedDictionary<string, string>()); | |
private string CreateQueryString(IReadOnlyDictionary<string, string> dic) |
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
class DoubleDic<TKey, TValue> | |
{ | |
public HashSet<TKey> SensitiveKeys { get; } = new HashSet<TKey>(); | |
public IReadOnlyDictionary<TKey, TValue> Exposed => _source; | |
public TValue RedactedValue { get; set; } | |
public IReadOnlyDictionary<TKey, TValue> Redacted | |
{ |
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
private string SafeQueryString => | |
string.Join("&", _queryStringCache.Select( | |
pair => $"{pair.Key}={(_sensitiveParameters.Contains(pair.Key) ? "XXX" : pair.Value)}")); |
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 builder = | |
new PaymentUriBuilder("http://www.paymentprocessor.com/makeapayment", "SECRET") | |
.Append("AMOUNT", paymentModel.Amount) | |
.Append("PASSWORD", Configuration.Password) | |
.Append("USER", Configuration.Username) | |
.Append("CURRENCY", paymentModel.CurrencyCode; | |
Logger.AddInformational($"Generated Payment Page URL: '{builder.SafePaymentUri}'"); |
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
private readonly HashSet<string> _sensitiveParameters = new HashSet<string>() | |
{ | |
"PASSWORD", | |
"NAME", | |
"EMAIL", | |
"ADDRESS" | |
}; | |
public string SafeQueryString | |
{ |