Skip to content

Instantly share code, notes, and snippets.

@dpraimeyuu
dpraimeyuu / handy.fs
Created April 6, 2018 17:49 — forked from kjnilsson/handy.fs
my current favourite handy fsharp helpers
//invaluable for all those Choice<'a, exn> flows
let exnf f = Printf.ksprintf (fun s -> exn s) f
//combine paths
let (</>) x y = System.IO.Path.Combine(x, y)
//allows you to pattern match on values in the current scope rather than just literals
let (|Eq|_|) expected value =
if expected = value then Some ()
else None
// This is am example of an immediate write / random access cursor for Excel with basic formatting options.
// Implementation is based on a concrete, non generic writer monad with no payload ("do!"" only) (only state).
// Instead of directl writing to excel, an alternatives would be a random acces to a
// copy-on-write list (or even a mutable array) and then bulk-write the result to excel in one shot.
// When only forward access would have been required, a simple seq expression with yields would have been enough.
// Anyway, it is a demonstration on how to "hide" pseudo-mutable state that is passed through a computation.
//
// I personally use it for generating reports based on various data sources.
@dpraimeyuu
dpraimeyuu / BatchfileTricks.cmd
Created June 15, 2020 07:19 — forked from jennings/BatchfileTricks.cmd
Stupid batch file tricks
:: Sleep for N seconds:
ping localhost -n N -w 1
:: Get the date and time (US LOCALE ONLY)
set YEAR=%DATE:~-4,4%
set TWOYEAR=%DATE:~-2,2%
@dpraimeyuu
dpraimeyuu / gist:d29f879de3b08c8e842ab75a89b02d46
Created October 19, 2020 13:35 — forked from robertpi/gist:2964793
F# record implementing an interface
namespace MyNamespace
type IMyInterface =
abstract GetValue: unit -> string
type MyRecord =
{ MyField1: int
MyField2: string }
interface IMyInterface with
member x.GetValue() = x.MyField2
@dpraimeyuu
dpraimeyuu / task-msbuild.js
Created September 24, 2021 05:34 — forked from hoangitk/task-msbuild.js
VSCode task with msbuild
{
"version": "0.1.0",
"command": "cmd",
"args": [
"/c"
],
"showOutput": "always",
"echoCommand": true,
"tasks": [
{
@dpraimeyuu
dpraimeyuu / effective-fsharp.md
Created October 25, 2021 18:36 — forked from swlaschin/effective-fsharp.md
Effective F#, tips and tricks

Architecture

  • Use Onion architecture

    • Dependencies go inwards. That is, the Core domain doesn't know about outside layers
  • Use pipeline model to implement workflows/use-cases/stories

    • Business logic makes decisions
    • IO does storage with minimal logic
    • Keep Business logic and IO separate
  • Keep IO at edges

@dpraimeyuu
dpraimeyuu / launch.json
Created November 3, 2021 20:09 — forked from cecilemuller/launch.json
Run ts-node in VSCode Debugger
{
"version": "0.2.0",
"configurations": [
{
"name": "Example",
"type": "node",
"request": "launch",
"runtimeExecutable": "node",
"runtimeArgs": ["--nolazy", "-r", "ts-node/register/transpile-only"],
@dpraimeyuu
dpraimeyuu / _readme.md
Created January 10, 2022 06:56 — forked from andywer/_readme.md
React - Functional error boundaries

React - Functional error boundaries

Thanks to React hooks you have now happily turned all your classes into functional components.

Wait, all your components? Not quite. There is one thing that can still only be implemented using classes: Error boundaries.

There is just no functional equivalent for componentDidCatch and deriveStateFromError yet.

Proposed solution

@dpraimeyuu
dpraimeyuu / outside-in-tdd.md
Created September 11, 2022 07:12 — forked from michaellihs/outside-in-tdd.md
Outside-In TDD
@dpraimeyuu
dpraimeyuu / DOM3D.js
Created March 28, 2024 06:33 — forked from OrionReed/dom3d.js
3D DOM viewer, copy-paste this into your console to visualise the DOM topographically.
// 3D Dom viewer, copy-paste this into your console to visualise the DOM as a stack of solid blocks.
// You can also minify and save it as a bookmarklet (https://www.freecodecamp.org/news/what-are-bookmarklets/)
(() => {
const SHOW_SIDES = false; // color sides of DOM nodes?
const COLOR_SURFACE = true; // color tops of DOM nodes?
const COLOR_RANDOM = false; // randomise color?
const COLOR_HUE = 190; // hue in HSL (https://hslpicker.com)
const MAX_ROTATION = 180; // set to 360 to rotate all the way round
const THICKNESS = 20; // thickness of layers
const DISTANCE = 10000; // ¯\\_(ツ)_/¯