Skip to content

Instantly share code, notes, and snippets.

View unclechu's full-sized avatar

Viacheslav Lotsmanov unclechu

  • RELEX Solutions
  • Finland
View GitHub Profile
@unclechu
unclechu / postgresql-race-condition-demo.hs
Created December 28, 2021 14:12
Haskell script that reproduces race condition in PostgreSQL database
#! /usr/bin/env nix-shell
#! nix-shell --pure -i runhaskell
#! nix-shell -E "with import (fetchTarball{url=\"https://github.com/NixOS/nixpkgs/archive/d887ac7aee92e8fc54dde9060d60d927afae9d69.tar.gz\";sha256=\"1bpgfv45b1yvrgpwdgc4fm4a6sav198yd41bsrvlmm3jn2wi6qx5\";}) {}; let hs=haskellPackages.ghcWithPackages(p:[p.postgresql-simple p.async p.turtle p.text p.process p.time]); in mkShell{buildInputs=[postgresql hs cacert];}"
{-
Haskell script that reproduces race condition in PostgreSQL database.
This is not considered a bug but rather an expected behavior,
just something you should be aware of.
This test demonstrates that if you have two transactions and data reads in both
@unclechu
unclechu / neovim.nix
Created August 20, 2021 13:34
Neovim 0.5.0 issue reproducible environment to demo that Perl integration is not working
# How to use/test:
# nix-build neovim.nix -o neovim
# neovim/bin/nvim
let
nixpkgs-unstable-pin = fetchTarball {
url = "https://releases.nixos.org/nixos/unstable/nixos-21.11pre308897.e41ba381140/nixexprs.tar.xz";
sha256 = "1smkm0z569lp321m7jsyy1fvnvl2nc8vh2nak946r9fd4hl4px4p";
};
in
@unclechu
unclechu / issue-fix-demo.hs
Created October 4, 2020 02:32
Servant Haskell library issue with Optional ReqBody fix demonstration
#! /usr/bin/env nix-shell
#! nix-shell --pure -i runhaskell -E "import ./shell.nix {}"
{-
This is a demonstration of the fix of the issue
https://github.com/haskell-servant/servant/issues/1346
Run server (make sure there’s “shell.nix” in the same directory):
./issue-fix-demo.hs
@unclechu
unclechu / issue-demo.hs
Created October 3, 2020 15:09
Servant Haskell library issue with Optional ReqBody demonstration
#! /usr/bin/env nix-shell
#! nix-shell --pure -i runhaskell -E "import ./shell.nix {}"
{-
This a demonstration of the issue with Servant library.
ReqBody' '[Optional] doesn’t make the value be optional,
the value of ReqBody isn’t wrapped into Maybe as it supposed to.
Run server (make sure there’s “shell.nix” in the same directory):
./issue-demo.hs
@unclechu
unclechu / TotalFoldable.hs
Created July 27, 2020 21:47
Reimplementation of Haskell’s "Data.Foldable.Foldable" from "Prelude" in order to fix partial functions.
#! /usr/bin/env nix-shell
#! nix-shell -i runhaskell -E
#! nix-shell "let ghc=n.haskellPackages.ghcWithPackages(p:[p.hspec]); n=import(fetchTarball{url=\"https://github.com/NixOS/nixpkgs/archive/db31e48c5c8d99dcaf4e5883a96181f6ac4ad6f6.tar.gz\";sha256=\"1j5j7vbnq2i5zyl8498xrf490jca488iw6hylna3lfwji6rlcaqr\";}){}; in n.mkShell{buildInputs=[ghc];}"
-- Reimplementation of Haskell’s "Data.Foldable.Foldable" from "Prelude" in order to fix partial
-- functions.
--
-- Author: Viacheslav Lotsmanov, 2020
--
-- Still WIP, planning to make a library as soon as it implements all the required stuff.
@unclechu
unclechu / ghc-base-history.html
Created July 23, 2020 01:42
List of “base” package versions attached to specific version of GHC
<style>
table th, table td {
border: 1px solid black;
}
</style>
<table dir="auto">
<tr>
<th><b>8.10.1</b></th>
<th><b>8.8.3</b></th>
@unclechu
unclechu / haskell-nix-shell-script.hs
Last active July 20, 2020 01:59
Safe nix-shell Haskell script (with sha1sum validation of nixpkgs pick)
#! /usr/bin/env nix-shell
#! nix-shell --pure -i runhaskell
#! nix-shell -E "with import (fetchTarball { url = \"https://github.com/NixOS/nixpkgs/archive/db31e48c5c8d99dcaf4e5883a96181f6ac4ad6f6.tar.gz\"; sha256 = \"1j5j7vbnq2i5zyl8498xrf490jca488iw6hylna3lfwji6rlcaqr\"; }) {}; mkShell { buildInputs = [(haskellPackages.ghcWithPackages (p: [p.servant p.servant-server]))]; }"
{-# LANGUAGE UnicodeSyntax #-}
import Servant
main ∷ IO ()
main = putStrLn "foo"
@unclechu
unclechu / backfill-report
Created July 13, 2020 05:23
Tickspot report hours automation script (written in Raku)
#! /usr/bin/env raku
use v6.d;
# Author: Viacheslav Lotsmanov, 2020
constant report-note = q«Working on some project»;
sub report-day(Str \date, Rat \hours) {
my Str @cmd = './report', "--date={date}", 'hours', hours.fmt(q/%0.1f/), report-note;
my Str @logcmd = @cmd.map({ .match(/\s/) ?? "'$_'" !! $_ });
"[{@cmd.elems}] {@logcmd.join: ' '}".note;
@unclechu
unclechu / default.nix
Created February 23, 2020 16:34
Nix Docker workshop
{
nixpkgs ? import <nixpkgs> {},
name,
tag,
}:
let
inherit (nixpkgs) pkgs;
inherit (pkgs) dockerTools;
in
@unclechu
unclechu / denull.ts
Created December 17, 2019 00:30
TypeScript experiment with immitating Haskell's Maybe Monad behavior
/*!
* Date: December 2019
* Author: Viacheslav Lotsmanov
* License: Public Domain
*
* Special thanks to Gerrit Birkeland @gitter_gerrit0:matrix.org
* from https://riot.im/app/#/room/#typescript:matrix.org
* for good working examples and explanation!
*
* This module provides "deNull" which tries to