Skip to content

Instantly share code, notes, and snippets.

giuliohome

Block or report user

Report or block giuliohome

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@giuliohome
giuliohome / FP2TheMax.fs
Last active Aug 18, 2018
F# port of John A De Goes "FP to the max"
View FP2TheMax.fs
open System
type Eff<'Ctx, 'T> = 'Ctx -> 'T
type EffBuilder() =
member __.Return x : Eff<'Ctx,'T> =
fun _ -> x
member __.Bind(f : Eff<'Ctx, 'T>, g : 'T -> Eff<'Ctx, 'S>) : Eff<'Ctx, 'S> =
fun c -> g (f c) c
member __.Zero() : Eff<'Ctx, unit> =
View safetraversal.fs
let rec bfs2robust (fanout: Map<'node, 'node seq> -> 'node -> 'node seq) (tree: Map<'node, 'node seq>) (node: 'node) : 'node seq =
let single = seq [node]
match fanout tree node with
| e when e = Seq.empty -> single
| s -> Seq.fold (fun acc item ->
bfs2robust fanout (tree |> Map.remove node) item
|> Seq.append acc) single s |> Seq.distinct
View gotrees.fs
let rec bfs2 (fanout: Map<'node, 'node seq> -> 'node -> 'node seq) (tree: Map<'node, 'node seq>) (node: 'node) : 'node seq =
let single = seq [node]
match fanout tree node with
| e when e = Seq.empty -> single
| s -> Seq.fold (fun acc item ->
bfs2 fanout tree item
|> Seq.append acc) single s
@giuliohome
giuliohome / BindableTextBlock.cs
Created Aug 7, 2018
TextBloacks with colours !!!
View BindableTextBlock.cs
public class BindableTextBlock : TextBlock
{
public ObservableCollection<Inline> InlineList
{
get { return (ObservableCollection<Inline>)GetValue(InlineListProperty); }
set { SetValue(InlineListProperty, value); }
}
public static readonly DependencyProperty InlineListProperty =
DependencyProperty.Register("InlineList", typeof(ObservableCollection<Inline>), typeof(BindableTextBlock), new UIPropertyMetadata(null, OnPropertyChanged));
View view_v2.xaml
<DataGrid Grid.Column="2" ItemsSource="{Binding SelPayment.eur_invoices}" IsReadOnly="True" AutoGenerateColumns="False"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="10,10,10,10" >
<DataGrid.Columns>
<DataGridTextColumn Header="Buy/Sell" Binding="{Binding buysell}" />
<DataGridTextColumn Header="Cpty Name" Binding="{Binding CptyName}" />
<DataGridTextColumn Header="Invoice Nr" Binding="{Binding InvoiceNr}" />
<DataGridTextColumn Header="Amount" Binding="{Binding amount, StringFormat=N}" />
<DataGridTextColumn Header="Curr" Binding="{Binding curr}" />
<DataGridTextColumn Header="Msg" Binding="{Binding ui.msg}" />
</DataGrid.Columns>
@giuliohome
giuliohome / model_v2.fs
Created Aug 2, 2018
Model with composition
View model_v2.fs
type Back2UI() =
inherit SimpleViewModelBase()
let mutable _msg = ""
member this.msg
with get() = _msg
and set value =
_msg <- value
this.OnPropertyChanged(<@ this.msg @>)
type ActivePassive = Active | Passive
@giuliohome
giuliohome / view.xaml
Created Aug 2, 2018
UI binding from an array to a datagrid
View view.xaml
<DataGrid Grid.Column="2" ItemsSource="{Binding SelPayment.eur_invoices}" IsReadOnly="True"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="10,10,10,10" >
@giuliohome
giuliohome / model.fs
Created Aug 2, 2018
F# record type as business model
View model.fs
// business model
type Invoice = { CptyName: string; CptyNum: int; InvoiceNr: string; amount : decimal; curr: string; buysell: ActivePassive}
// array extraction from Excel with type provider
let ActiveInvoice =
ActiveInvoiceExcel.Data
|> Seq.map ( fun line -> { InvoiceNr = line.``Numero documento``; ... })
|> Seq.toArray
View Differ.fs
type DifferenceType<'TKey, 'T> =
| Added of 'TKey * 'T
| Removed of 'TKey * 'T
| Modified of 'TKey * 'T * 'T * seq<string * (string * string)> with
member this.Key =
match this with
| Added (key, _)
| Removed (key, _)
| Modified (key, _, _, _) -> key
View CSharpVsScalaAsync
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
You can’t perform that action at this time.