Skip to content

Instantly share code, notes, and snippets.

@bessgeor
bessgeor / SpecWithParametersAndRequestBodySchemas.fs
Created June 15, 2021 15:05
Example of generated server code
[<RequireQualifiedAccess>]
module SpecwithparametersandrequestbodyAPI
open System.ComponentModel.DataAnnotations
open FSharp.Control.Tasks.V2.ContextInsensitive
open Giraffe
open System.Threading.Tasks
open Microsoft.AspNetCore.Http
open Microsoft.Extensions.DependencyInjection
@bessgeor
bessgeor / prepare_commit_msg
Last active June 15, 2021 11:25
Git hook to append ticket name to commit messages from a branch name
#!/bin/sh
#inspired by HellBrick
#author: https://github.com/bessgeor
#license: MIT
#Copyright 2021 George Bessonov
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
@bessgeor
bessgeor / AST_Conversion.fs
Created November 21, 2020 14:20
Convert F# quotation to C# expression including nested lambdas for a subset of closure types
open System
open System.Collections.Generic
open System.Linq
open System.Linq.Expressions
open System.Reflection
open LinqToDB
module AST_Conversion =
type private StubContext() =
interface IDataContext with
@bessgeor
bessgeor / checker.fs
Created October 21, 2020 17:32
null-checking codegen example
(checkForUnexpectedNulls (fun (x: dataSetListInput) ->
(seq {
if isNullReference x then
"body"
else if isNullReference x.nullCheckingTest then
"body.nullCheckingTest"
else
yield!
x.nullCheckingTest
|> Seq.mapi (fun i1 ->
@bessgeor
bessgeor / Extension.Npgsql.cs
Last active December 26, 2019 05:46
C# HList example
using System;
using System.Linq.Expressions;
using ZeroORM.SqlBuilder.Vendor;
namespace ZeroORM.SqlBuilder
{
public static class NpgsqlExtension
{
/// <summary>
/// Single vendor in list overload
@bessgeor
bessgeor / Poor man's option
Created April 2, 2019 06:56
Option<T> C#-way
using System;
namespace PoorMansOption
{
public static class OptionExtensions
{
public static Option<T, T> Some<T>(T value)
where T : class
=> new Option<T, T>(value, true, _ => _);
@bessgeor
bessgeor / codegenValidator.ts
Last active February 1, 2019 18:24
Typescript compile-time codgen reflection validator
import * as moment from 'moment';
type ArrayLike = any[] & { length: number }; // { length?: number } extends any[] == true
type IsNullable<T> = null extends T ? true : false;
type IsUndefinable<T> = undefined extends T ? true : false;
type Unwrap<T> = T extends (infer U)[] ? U : never;
type IsArray<T> = T extends ArrayLike ? true : false;
type EnumLike<T> =
#!/bin/sh
#inspired by HellBrick
function replace_commit_message {
commit_msg=$1
ticket=$2
to_insert=" ( ticket #$ticket )"
# hook should not insert ticket id if it is already inserted
already_ticketed=`grep -c "$to_insert" $commit_msg_file`
#!/bin/sh
#inspired by HellBrick
commit_msg_file=$1
detached_head='unnamed branch'
current_branch="$(git symbolic-ref HEAD 2>/dev/null)" ||
current_branch="$detached_head"
pipe_separated_system_branches="smartgit-temp|bitbucket-temp"