Skip to content

Instantly share code, notes, and snippets.

@MatthewVines
MatthewVines / Main.hs
Last active June 24, 2021 18:36
AllMarket
{-# LANGUAGE OverloadedStrings #-}
module Example where
import Language.Marlowe.Extended
main :: IO ()
main = print . pretty $ contract
-- Define the parties involved
seller, buyer, arbiter, market :: Party
@MatthewVines
MatthewVines / Main.hs
Created June 22, 2021 19:13
Simple escrow
{-# LANGUAGE OverloadedStrings #-}
module Escrow where
import Language.Marlowe.Extended
main :: IO ()
main = print . pretty $ contract
-- We can set explicitRefunds True to run Close refund analysis
-- but we get a shorter contract if we set it to False
@MatthewVines
MatthewVines / SystemCheckQueryInterceptor.cs
Last active August 8, 2017 17:38
NPoco Interceptor to inject tenant checks.
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Text;
using Microsoft.SqlServer.TransactSql.ScriptDom;
using NPoco;
public class SystemCheckQueryInterceptor : IExecutingInterceptor
{
###########################################################################
#Install VirtualBox https://www.virtualbox.org/wiki/Downloads
#Install Vagrant https://www.vagrantup.com/downloads.html
#Rename this file to Vagrantfile (no extension)
#In your favorite shell, navigate to the directory with this file
#type >> vagrant up
#wait for process to complete (will take a few minutes)
#once it is done, you can log into the virtual machine with
#username: vagrant password: vagrant
###########################################################################
#Install VirtualBox https://www.virtualbox.org/wiki/Downloads
#Install Vagrant https://www.vagrantup.com/downloads.html
#Rename this file to Vagrantfile (no extension)
#In your favorite shell, navigate to the directory with this file
#type >> vagrant up
#wait for process to complete (will take a few minutes)
#once it is done, you can log into the virtual machine with
#username: vagrant password: vagrant
@MatthewVines
MatthewVines / NodaMapper.cs
Last active August 29, 2015 14:14
Mapper for NodaTime types for peta poco and npoco
using System;
using NodaTime;
using NPoco;
public class NodaMapper : DefaultMapper
{
public override Func<object, object> GetFromDbConverter(Type DestType, Type SourceType)
{
if (DestType == typeof(Instant) || DestType == typeof(Instant?))
{
public static class LevenshteinDistance
{
/// <summary>
/// Compute the distance between two strings.
/// The distance between the strings is defined as the minimum
/// number of edits needed to transform one string into the other,
/// with the allowable edit operations being insertion, deletion,
/// or substitution of a single character.
/// </summary>
public static int CalculateDistance(string s, string t)
@MatthewVines
MatthewVines / GenerateRandomString.cs
Last active August 29, 2015 14:05
Generates a random string from a given set of rules about length and charater sets.
public static string GenerateRandomString(int minLength, int maxLength, int minLCaseCount, int minUCaseCount, int minNumCount, int minSpecialCount)
{
char[] randomString;
const string LCaseChars = "abcdefgijkmnopqrstwxyz";
const string UCaseChars = "ABCDEFGHJKLMNPQRSTWXYZ";
const string NumericChars = "23456789";
const string SpecialChars = "*$-+?_&=!%{}/";
Hashtable charGroupsUsed = new Hashtable();
@MatthewVines
MatthewVines / ELORanker.cs
Last active January 3, 2016 09:09
A set of classes that will calculate the ELO rankings of 2 players after a match.
using System;
namespace ELO
{
public class ELORanker
{
private readonly IKResolver _kResolver;
public ELORanker() : this(new DefaultKResolver()){}