Skip to content

Instantly share code, notes, and snippets.

View cartermp's full-sized avatar
🦫
reject modernity, become a beaver

Phillip Carter cartermp

🦫
reject modernity, become a beaver
View GitHub Profile
https://github.com/honeycombio/zipkin-python-opentracing
https://github.com/honeycombio/dynsampler-js
https://github.com/honeycombio/chef-honeytail
https://github.com/honeycombio/leakybucket
https://github.com/honeycombio/influx2hny
https://github.com/honeycombio/prom2hny
https://github.com/honeycombio/opentelemetry-exporter-go
https://github.com/honeycombio/opentelemetry-exporter-python
https://github.com/honeycombio/opentelemetry-dotnet
https://github.com/honeycombio/zipkin-python-opentracing
open System.Threading.Tasks
open System.Text.RegularExpressions
let regex s = Regex(s, RegexOptions.Compiled)
let input = System.IO.File.ReadAllText($"{__SOURCE_DIRECTORY__}/regexredux-input5000000.txt")
let text = (regex ">.*\n|\n").Replace(input, "")
let regexCount pattern text =
let rec loop c (m:Match) =
// Notes:
// 0. Immediately thrown off by `{` and `}` being colorized as the string literal
// 1. Bad expression diagnostic in the interpolation is correct
// 2. String literal in non-triple-quoted string diagnostic is good
// 3. Typing these out works well, editor doesn't freak out
// 4. symbol-based operations all work (symbol highlight, find refs, go to def) for symbols in interpolated stuff
// 5. Breakpoint can be set in the interp string on a single line
// 6. Using interp string with %d/%s/etc. specifiers adjusts the argument's type as expected (e.g., %d{whom} infers a valid type for 'whom')
// 7. Error recoviery for splitting the interpolated expression into a new line matches other rules for splitting things out into new lines
// 8. Quick fix to rename misspelled identifier in interpolation works
public class SomeClassInMyCode
{
public void SomeMethodIHave()
{
HelloWorldGenerated.HelloWorld.SayHello(); // calls Console.WriteLine("Hello World!") and then prints out syntax trees
}
}
<!-- This goes in the top-level property group -->
<PropertyGroup>
<LangVersion>preview</LangVersion>
</PropertyGroup>
<!-- Add this as a new ItemGroup, replacing paths and names appropriately -->
<ItemGroup>
<!-- Note that this is not a "normal" ProjectReference.
It needs the additional 'OutputItemType' and 'ReferenceOutputAssmbly' attributes. -->
<ProjectReference Include="path-to-sourcegenerator-project.csproj"
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Text;
namespace SourceGeneratorSamples
{
[Generator]
public class HelloWorldGenerator : ISourceGenerator
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Text;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml;
namespace MyGenerator
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>preview</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.8.0-3.final" PrivateAssets="all" />
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.0.0" PrivateAssets="all" />
@cartermp
cartermp / mixed-applicative-mondaic-result-ce.fsx
Last active March 19, 2020 23:07
Shows mixing of monadic and applicative CEs with a result builder
// First, define a 'zip' function
module Result =
let zip x1 x2 =
match x1,x2 with
| Ok x1res, Ok x2res -> Ok (x1res, x2res)
| Error e, _ -> Error e
| _, Error e -> Error e
type ResultBuilder() =
member _.MergeSources(t1: Result<'T,'U>, t2: Result<'T1,'U>) = Result.zip t1 t2
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.