Skip to content

Instantly share code, notes, and snippets.

View unclechu's full-sized avatar

Viacheslav Lotsmanov unclechu

  • RELEX Solutions
  • Finland
View GitHub Profile
#!/usr/bin/env stack
-- stack script --resolver lts-11.22 --package singletons
{-# OPTIONS_GHC -Wall -Werror=incomplete-patterns #-}
{-# LANGUAGE UnicodeSyntax, TemplateHaskell, RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables, RankNTypes, TypeApplications #-}
{-# LANGUAGE DataKinds, TypeFamilies, GADTs, KindSignatures #-}
{-# LANGUAGE FlexibleContexts, FlexibleInstances #-}
import Data.Kind
import Data.Singletons
@unclechu
unclechu / serialize-postgresql-db-structure.pl
Last active December 10, 2018 23:31
Script for generating representations of PostgreSQL database tables/views with foreign references (supported export types: json, markdown, html)
#!/usr/bin/env perl
# serialize-postgresql-db-structure.pl
# (see bottom of this script for license and usage info)
use v5.10; use warnings; use strict; use autodie qw(:all);
use utf8; no warnings 'utf8';
use Encode qw(decode_utf8);
use Pod::Usage;
use Getopt::Long;
use Scalar::Util qw(openhandle);
use List::Util qw(first);
@unclechu
unclechu / studying-singletons-part-1.hs
Last active October 14, 2018 14:14
Haskell singletons studying
#!/usr/bin/env stack
{- stack script
--resolver=lts-12.12
--package=hspec
-}
-- See for details: https://blog.jle.im/entry/introduction-to-singletons-1.html
{-# LANGUAGE GADTs, DataKinds, KindSignatures, RankNTypes, TypeFamilies #-}
{-# LANGUAGE PolyKinds, ConstraintKinds #-}
@unclechu
unclechu / matrix-room-notifications-mentions-only.sh
Created August 10, 2018 21:30
A script that helps to switch [Matrix] notifications for a room to "mentions only" mode from CLI
#!/usr/bin/env bash
#
# A script that helps to switch [Matrix] notifications for a room
# to "mentions only" mode from CLI.
#
# Author: Viacheslav Lotsmanov
# License: Public Domain
#
set -e
@unclechu
unclechu / jack-simple-app.hs
Last active January 1, 2018 21:57
Haskell: Working with JACK (JACK Audio Connection Kit)
#!/usr/bin/env stack
{- stack script --resolver=lts-10.2
--package=base-unicode-symbols
--package=jack
-}
{-# OPTIONS_GHC -threaded #-}
{-# LANGUAGE UnicodeSyntax #-}
import Prelude.Unicode
import Control.Arrow
import Sound.JACK.Audio
@unclechu
unclechu / Dockerfile
Created December 19, 2017 12:10
My own Docker container for Haskell Stack
FROM debian:stretch
RUN apt-get update -y \
&& apt-get install -y --allow-unauthenticated \
git vim libipc-system-simple-perl libautodie-perl curl wget parallel \
postgresql-server-dev-9.6 libssl-dev libpcre2-dev libpcre3-dev \
pkg-config icu-devtools libicu-dev libxml2-dev \
libx11-dev libxtst-dev libxrandr-dev libxinerama-dev \
rsyslog locales \
&& sed -i -e \
@unclechu
unclechu / algebraic_data_types_experiment.nim
Last active March 14, 2025 17:10
Nim: algebraic data types (Maybe and Either), kinda Eq typeclass instances, kinda functors
type
MaybeKind = enum Just, Nothing
Maybe[T] = object
case kind: MaybeKind
of Just: value: T
of Nothing: discard
EitherKind = enum Left, Right
Either[L, R] = object
case kind: EitherKind
@unclechu
unclechu / stubborn-zombie.hs
Last active October 5, 2017 22:48
stubborn-zombie.hs
#!/usr/bin/env stack
-- stack runghc --resolver=lts-9.6 --install-ghc --package=unix
{-# LANGUAGE UnicodeSyntax #-}
{-# LANGUAGE PackageImports #-}
import "base" Control.Monad (forever)
import "base" Control.Concurrent (threadDelay)
import "unix" System.Posix.Signals
(Handler (Catch), installHandler, sigHUP, sigINT, sigTERM, sigPIPE)
@unclechu
unclechu / kbd.pl6
Last active December 28, 2017 09:40
kbd.pl6
#!/usr/bin/env perl6
use v6.c;
close $*IN;
my $HOME := IO::Path.new: '/home/unclechu';
my $BINDIR := $HOME.child: '.local/bin';
my $LOCKFILE := %*ENV{'HOME'}.IO.child: '.kbd.pl6.lock';
sub MAIN( Bool :f(:$force) = False
, Bool :v(:$verbose) = False
@unclechu
unclechu / docker-copy-volume.sh
Last active July 27, 2017 10:17
docker-copy-volume.sh
#!/bin/bash
if [[ -z $1 ]] || [[ -z $2 ]]; then
echo Usage: "$(basename -- "$0")" \
SOURCE-VOLUME-ID DESTINATION-VOLUME-ID 1>&2
exit 1
fi
docker run --rm -it -v "$1:/vol-src" -v "$2:/vol-dst" alpine \
ash -c 'cp -r /vol-src/* /vol-dst/' || exit $?