Skip to content

Instantly share code, notes, and snippets.

View AlgorithmsAreCool's full-sized avatar
💭
🐢

AlgorithmsAreCool

💭
🐢
  • Dallas, Tx
View GitHub Profile
@AlgorithmsAreCool
AlgorithmsAreCool / final-proof.dfy
Last active May 2, 2024 13:42
How to formally specify a lock in Dafny
newtype ThreadId = i: nat | i <= 0xffff_ffff
class Lock
{
static const NULL_THREAD_ID : ThreadId := 0
var ownerThread : ThreadId
constructor()
ensures ownerThread == NULL_THREAD_ID
@AlgorithmsAreCool
AlgorithmsAreCool / basic-types.dfy
Last active January 4, 2024 03:46
Dafny Blog Snippets
type Timestamp = t: int| 0 <= t <= 9223372036854775808 //2^63
class Entity
{
var id : string
predicate isEqual(other : Entity)
reads this, other
{
id == other.id
@AlgorithmsAreCool
AlgorithmsAreCool / controlplane.proto
Created December 12, 2023 01:52
CosmosCompute Snippets
service ControlPlane {
rpc QueryUsage (QueryConsumptionRequest) returns (QueryConsumptionResponse) {}
rpc RegisterHandler (RegisterHandlerRequest) returns (RegisterHandlerResponse) {}
}
@AlgorithmsAreCool
AlgorithmsAreCool / CsCheckTesting.cs
Created February 22, 2023 20:02
Testing CsCheck's coverage of constrained search spaces
// See https://aka.ms/new-console-template for more information
using CsCheck;
Console.WriteLine("Hello, World!");
TestIteratedDirectIntegerSpaceCoverage();
void TestEnumeratedSpaceCoverage()
{
let sum = [1..10] |> List.reduce (+)
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
namespace BatchedAwait
{
public static class EntryPoint

Examples of Sugar since C# 6.0

  • Discards
  • ?.
  • Dictionary Initializers
  • Auto-Property Initializers (heck, Auto Properties in general)
  • Using Static
  • Inline out variables
  • Async Main
  • Non-trailing named arguments
@AlgorithmsAreCool
AlgorithmsAreCool / PoorDataflow.cs
Created December 30, 2019 18:11
Hastily written and incomplete dataflow clone using tasks and channels
using System;
using System.Collections.Concurrent;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
namespace HomebrewDataflow
{
public abstract class WorkflowStageBase<TIn>
@AlgorithmsAreCool
AlgorithmsAreCool / program.cs
Created December 29, 2019 23:03
Repro program
using System;
using System.Threading;
using System.Threading.Tasks;
using System.Threading.Tasks.Dataflow;
namespace randomTPLRepro
{
class Program
{
@AlgorithmsAreCool
AlgorithmsAreCool / gist:68654a12ac7b9d2af49ac052985d556d
Last active December 10, 2019 22:11
Stack Trace of StackOverflow in Trill

Project File

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>