Skip to content

Instantly share code, notes, and snippets.

@dlidstrom
dlidstrom / output
Last active November 30, 2023 20:28
Minimal neural network in F# with no dependencies
We couldn’t find that file to show.
@dlidstrom
dlidstrom / Main.elm
Last active August 15, 2019 14:15
Elm counter sample with flags
import Browser
import Html exposing (Html, button, div, text)
import Html.Events exposing (onClick)
type alias Flags =
{ counter : Int }
type Msg = Increment | Decrement
type Model = Model Int
init : Flags -> (Model, Cmd Msg)
@dlidstrom
dlidstrom / Result.fs
Last active September 20, 2019 12:11
Mix of result and applicative
module Result =
let bind f = function
| Ok x -> f x
| Error x -> Error x
let map f = function
| Ok x -> Ok(f x)
| Error err -> Error err
let apply fResult xResult =
module Main where
import Prelude
type Student = {
first :: String,
last :: String,
class :: String
}
@dlidstrom
dlidstrom / keybindings.json
Last active December 17, 2018 15:52
Visual Studio Code Keybindings
// Place your key bindings in this file to overwrite the defaults
[
{
"key": "ctrl+down",
"command": "editorScroll",
"args": {
"to": "down",
"by": "line",
"revealCursor": true
}
public class MessageChecksumConverter : PatternLayoutConverter
{
private static readonly TraceSource Source = new TraceSource(nameof(MessageChecksumConverter));
private static readonly MD5 ChecksumGenerator = MD5.Create();
protected override void Convert(TextWriter writer, LoggingEvent loggingEvent)
{
var output = TryGetHash(loggingEvent);
writer.Write(output);
}
@dlidstrom
dlidstrom / Teachers.cs
Last active October 25, 2018 12:08
Plan teachers week schedule
namespace Csp
{
using System;
using System.Collections.Generic;
using System.Linq;
using Decider.Csp.BaseTypes;
using Decider.Csp.Global;
using Decider.Csp.Integer;
public static class Program
@dlidstrom
dlidstrom / angular-deps.js
Last active December 25, 2022 19:44
Outputs all dependencies in the Angular module in a graphviz friendly format
includeList = {
// put desired module names here
};
skipList = {};
handledList = {};
handleModule(window.app);
function handleModule(module) {

Logging & Meta Tests

Logging

Define the operations being done by the application as discrete units of work. Examples: commands, queries, startup, shutdown. Define explicit boundaries between units of work. This makes it easy to log the operations of the application.

  • Log startup scenario together with settings. I.e. read all settings at application startup, and only there.
  • Log commands and queries. For commands, log command type and eventual return value. For queries, log the query type and the query result.
  • Define a logging gateway with convenience methods for logging application events. Define a class that represents an application event and define all known application events in a single, static and application-specific, class. Application events are lower-level than business events. For example: ExecutingCommand, CommandResult, Starting, Started, ShuttingDown, BeginRequest, EndRequest.
  • Application events should have their own event id.
  • Build infrastructure layer that takes care of applicat
using (var md5 = System.Security.Cryptography.MD5.Create())
{
var hash = md5.ComputeHash(Encoding.ASCII.GetBytes("dlidstrom@gmail.com"));
var sb = new StringBuilder();
for (int i = 0; i < hash.Length; i++)
{
sb.Append(hash[i].ToString("x2"));
}