Skip to content

Instantly share code, notes, and snippets.

@giacomociti
giacomociti / Fare2FsCheck.fs
Created September 29, 2015 13:03
fsCheck sized generator from fare regex-based generator
#r @"..\packages\Fare.1.0.0\lib\net35\Fare.dll"
#r @"..\packages\FsCheck.2.0.4\lib\net45\FsCheck.dll"
open Fare
open FsCheck
open System.Collections.Generic
// partial and naive implementation of a generator attempting to honor the size
let generator pattern =
// pre-compute a certain amount of values and group them by size
@giacomociti
giacomociti / OrderingTest.cs
Created March 14, 2018 16:34
Ordering behavior of dataflow
[Fact]
public async Task TransformBlockPreserveOrder()
{
const int badItem = 89;
var results = new List<int>();
var input = Enumerable.Range(1, int.MaxValue);
var mapBlock = new TransformBlock<int, int>(
x => x == badItem? throw new Exception("bug") : x,
new ExecutionDataflowBlockOptions {MaxDegreeOfParallelism = 10});
@giacomociti
giacomociti / streamingXml.fsx
Created April 23, 2018 20:52
reading a huge xml as a sequence of XElement
#r "System.Xml.Linq"
open System.Xml
open System.Xml.Linq
let elements ns name uri =
seq {
use reader = XmlReader.Create(inputUri = uri)
let onElement() = reader.LocalName = name && reader.NamespaceURI = ns
while onElement() || reader.ReadToFollowing(name, ns) do
yield XNode.ReadFrom(reader) :?> XElement }
#r "System.Xml.Linq"
open System.Xml.Linq
let htmlSummary primo secondo =
let tag name content = XElement(XName.Get name, content)
let em (text: string) = tag "em" [| text |]
let li key value = tag "li" [| key; em value |]
[|
li "primo" primo
@giacomociti
giacomociti / dotNetRDF_variable_issue.fsx
Created May 27, 2023 08:32
variable renaming affects query result
#r "nuget: dotNetRdf.Core"
open VDS.RDF
open VDS.RDF.Parsing
let graph = new Graph()
StringParser.Parse(graph, "
@prefix : <http://example.org/> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@giacomociti
giacomociti / time.n3
Created July 25, 2024 14:11
N3 rules to derive OWL-Time relations
@prefix log: <http://www.w3.org/2000/10/swap/log#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix math: <http://www.w3.org/2000/10/swap/math#> .
@prefix time: <http://www.w3.org/2006/time#> .
@prefix pred: <http://www.w3.org/2007/rif-builtin-predicate#>.
@prefix : <http://www.w3.org/2006/time/aux#> .
# instant comparison
# TODO: should cover many more cases than just dateTime