Skip to content

Instantly share code, notes, and snippets.

View fpawel's full-sized avatar

Pavel Filimonenkov fpawel

View GitHub Profile
type CartItem = string
type EmptyState = NoItems
type PaidForState = { PaidItems : CartItem list;
Payment : decimal}
type ActiveState = { UnpaidItems : CartItem list; }
type Cart =
| Empty of EmptyState
| Active of ActiveState
| PaidFor of PaidForState
@fpawel
fpawel / PaymentMethod.cs
Last active November 2, 2020 07:15
PaymentMethod.cs
[CompilationMapping(SourceConstructFlags.SumType), Struct, DebuggerDisplay("{__DebugDisplay(),nq}")]
[Serializable]
[StructLayout(LayoutKind.Auto, CharSet = CharSet.Auto)]
public struct PaymentMethod : IEquatable<Program.PaymentMethod>, IStructuralEquatable, IComparable<Program.PaymentMethod>, IComparable, IStructuralComparable
{
public static class Tags
{
public const int Cash = 0;
public const int Check = 1;
@fpawel
fpawel / ErathosphensSieve.fs
Created April 28, 2017 20:32
Calculate prime numbers using erathosphen method
// Calculate prime numbers using erathosphen method
open System.Collections.Generic
let erathosphensSieve n =
let numbers = ResizeArray [|2..n|]
let mutable p = 2
let mutable ready = false
while not ready do
match Seq.tryFindIndex (fun x -> x >= p * p) numbers with
| None ->
let triples n =
let mutable triples = []
let mutable ones = []
let mutable pairs =
[ for x = 1 to n+1 do
for y = x+1 to n+1 do
yield x,y]
let del k = pairs <- List.filter( (<>) k) pairs
while not pairs.IsEmpty do
let (x,y) as xy = pairs.Head
// Program
public static void f3(Program.Type3 _arg1)
{
if (_arg1 is Program.Type3.Type3Case2)
{
Program.Type3.Type3Case2 type3Case = (Program.Type3.Type3Case2)_arg1;
return;
}
if (!(_arg1 is Program.Type3.Type3Case3))
{
[<AutoOpen>]
module private Helpers1 =
let rec generateFsharpObject (t:Type) : obj =
let fail() = failwithf "generateFsharpObject %A " t
if t.IsValueType then Activator.CreateInstance(t)
elif t = typeof<string> then box ""
elif isEnumerable t then
if t.IsArray then
let valueType = t.GetElementType()
let result = Array.CreateInstance( valueType, 0 )
@fpawel
fpawel / Json.fs
Created May 29, 2017 10:47
Json in F#
namespace Json
open System
open System.Text
open System.Globalization
open FParsec
type Json =
| String of string
| Number of decimal
@fpawel
fpawel / Program.fs
Last active May 29, 2017 16:21
The bag of the initialization of F# modules
(* файл File1.fs *)
//module File1
//
//let x1 =
// printfn "x1"
//
//do
// ()
@fpawel
fpawel / fcount.go
Created June 3, 2017 06:55
Count the line number of files in directory
package main
import (
"flag"
"fmt"
"io/ioutil"
"os"
"path/filepath"
)
@fpawel
fpawel / prices.sql
Last active January 21, 2018 17:17
prices.sql
CREATE TYPE RUNNER_STATUS -- статус опции рынка
AS ENUM ('ACTIVE', 'REMOVED', 'WINNER', 'LOSER', 'HIDDEN', 'UNKNOWN');
CREATE TYPE SIDE -- тип ставки
AS ENUM (
'B', -- ставка ЗА
'L' -- ставка ПРОТИВ
);
CREATE TABLE IF NOT EXISTS teams ( -- команды