Skip to content

Instantly share code, notes, and snippets.

View MovGP0's full-sized avatar

Johann Dirry MovGP0

View GitHub Profile
/// <summary>Takes a list of values and scales the values, so that the sum of the result is always 1 (100%).</summary>
/// <param name="values">A list of values that need to be scaled.</param>
/// <returns>Scaled values, from which the sum is 1.</returns>
let scaleSoThatSumIsOne (values:seq<decimal>) =
let Σ = Seq.sum values
match Σ with
| 0.0m ->
let n = decimal (Seq.length values)
seq {
for p in values do
@MovGP0
MovGP0 / Asymmetric Encryption
Created June 30, 2015 13:32
Encryption in .NET
// Used to exchange symmetric keys
private static int RsaKeySize = 2048;
private void CreateKeys()
{
using(var provider = new RSACryptoServiceProvider(RsaKeySize))
{
provider.PersistKeyInCsp = false;
@MovGP0
MovGP0 / IMessageBus
Created July 1, 2015 18:36
MessageBus from ReactiveUI
sing System;
using System.Reactive.Concurrency;
namespace ReactiveUI
{
/// <summary>
/// IMessageBus represents an object that can act as a "Message Bus", a
/// simple way for ViewModels and other objects to communicate with each
/// other in a loosely coupled way.
///
@MovGP0
MovGP0 / Money.cs
Last active August 29, 2015 14:24
Money and Percent types
using System;
using System.Runtime.Serialization;
using System.Xml.Serialization;
namespace CN.Lib.Types
{
[Serializable]
[DataContract]
public struct Money : IEquatable<Money>, IComparable<Money>, IFormattable, ISerializable, IConvertible
{
@MovGP0
MovGP0 / NominalSize.cs
Created August 3, 2015 13:00
Nominal Size
using System;
using System.Linq;
using static System.Math;
namespace NominalSize
{
public sealed class Size
{
public Size(decimal basicValue, decimal upperTolerance, decimal lowerTolerance)
{
@MovGP0
MovGP0 / DNVM_DNU.md
Last active February 10, 2016 20:39
Working with .NET Execution Environment (DNX) Projects

Windows 10

  • Settings
  • Time & Language
  • Region & Language
  • Additional date, time, & regional settings
  • Change date, time, or number formats
  • Short time: HH:mm
  • Long time: HH:mm:ss
  • Administrative
  • Copy Settings
@MovGP0
MovGP0 / IntegerExtensions.cs
Created February 27, 2017 15:53
Common extension methods
public static class IntegerExtensions
{
///<summary>Returns an enumerable range of integers</summary>
///<example><c>5.To(9)</c></example>
///<example><c>5.To(-3)</c></example>
public static IEnumerable<int> To(this int start,int end)
{
var sign = Math.Sign(end - start);
while(start != end)
{
@MovGP0
MovGP0 / FSharp.fs
Created August 16, 2017 18:31
FizzBuzz
// inspired by FizzBuzz in Haskell by Embedding a Domain-Specific Language
// https://themonadreader.files.wordpress.com/2014/04/fizzbuzz.pdf
let fizzbuzz (number:int):string =
let test (d:int) (s:string) (x:string->string) = if number % d = 0 then (fun _ -> s + x("")) else x
let fizz = (fun (x:string->string) -> test 3 "Fizz" x)
let buzz = (fun (x:string->string) -> test 5 "Buzz" x)
((fun z -> z) |> buzz |> fizz) (number.ToString());
@MovGP0
MovGP0 / LoggerExtensions.cs
Created August 1, 2018 12:19
Serilog Extensions
public static class LoggerExtensions
{
public static ILogger Here(this ILogger logger,
[CallerMemberName] string memberName = "",
[CallerFilePath] string sourceFilePath = "",
[CallerLineNumber] int sourceLineNumber = 0) {
return logger
.ForContext("MemberName", memberName)
.ForContext("FilePath", sourceFilePath)
.ForContext("LineNumber", sourceLineNumber);