Skip to content

Instantly share code, notes, and snippets.

@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 / 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%
// 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 / 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
@dpraimeyuu
dpraimeyuu / file-operations.purs
Last active November 15, 2016 21:42
Having fun with 'Learn PureScript" - naive 'whereIs' function implementation
module Data.FileOperations where
import Prelude
import Data.Maybe (Maybe(Nothing), Maybe(Just))
import Data.String (contains, Pattern(Pattern))
import Data.Array (foldl)
import Data.Path
whereIs :: Path -> String -> Maybe Path
whereIs path filePattern =