Skip to content

Instantly share code, notes, and snippets.

View am-kantox's full-sized avatar
constantly matching the patterns

Aleksei Matiushkin am-kantox

constantly matching the patterns
View GitHub Profile
am-kantox / config.lua
Last active February 11, 2024 07:35
View config.lua
-- Read the docs:
-- Video Tutorials:
-- Forum:
-- Discord:
lvim.format_on_save.enabled = true
lvim.colorscheme = "nord"
-- keymappings [view all the defaults by pressing <leader>Lk]
lvim.leader = "space"
am-kantox / mapset_ex.ex
Created February 4, 2023 09:42
`MapSet` matchers/guards
View mapset_ex.ex
defmodule MapSetEx do
@moduledoc """
The helper functions to work with mapsets.
Mapsets in matches are matched the same way as maps, that said the following would be matched
fn mapset() -> :ok end.(
fn mapset() -> :ok end.([1, 2]))
fn mapset([1]) -> :ok end.([1, 2]))
and the following would not
am-kantox / single-multiple-select.bash
Created January 27, 2023 16:26
Implementation for single and multiple selects in bash
View single-multiple-select.bash
function multiselect {
# credits: (altered with single-choice by me)
# little helpers for terminal print control and key input
ESC=$( printf "\033")
cursor_blink_on() { printf "$ESC[?25h"; }
cursor_blink_off() { printf "$ESC[?25l"; }
cursor_to() { printf "$ESC[$1;${2:-1}H"; }
print_inactive() { printf "$2 $1 "; }
print_active() { printf "$2 $ESC[7m $1 $ESC[27m"; }
get_cursor_row() { IFS=';' read -sdR -p $'\E[6n' ROW COL; echo ${ROW#*[}; }
am-kantox / thinknetica_behaviour.ex
Last active December 15, 2022 04:13
Behaviour Example
View thinknetica_behaviour.ex
defmodule Tracker do
@moduledoc """
The `Tracker` behaviour declaring the interface for tracker backend.
@doc """
The function to be called from tracked entity.
@callback track(binary(), any()) :: :ok
am-kantox / cyrillic-sorter.ex
Created April 12, 2022 03:50
Naïve string sorter for Russian Cyrillic
View cyrillic-sorter.ex
defmodule RuSorter do
def compare(<<"ё", _::binary>>, <<"ё", _::binary>>), do: :eq
def compare(<<"Ё", _::binary>>, <<"Ё", _::binary>>), do: :eq
def compare(<<"ё", _::binary>>, <<c::utf8, _::binary>>) when c in 1072..1077, do: :gt
def compare(<<c::utf8, _::binary>>, <<"ё", _::binary>>) when c in 1072..1077, do: :lt
def compare(<<"ё", _::binary>>, <<c::utf8, _::binary>>) when c in 1078..1103, do: :lt
def compare(<<c::utf8, _::binary>>, <<"ё", _::binary>>) when c in 1078..1103, do: :gt
def compare(<<"Ё", _::binary>>, <<c::utf8, _::binary>>) when c in 1040..1045, do: :gt
def compare(<<c::utf8, _::binary>>, <<"Ё", _::binary>>) when c in 1040..1045, do: :lt
def compare(<<"Ё", _::binary>>, <<c::utf8, _::binary>>) when c in 1046..1071, do: :lt
am-kantox /
Created February 3, 2022 07:52
Spelling Alphabets

English Spelling Alphabet (ICAO/ITU/NATO)

Letter Appellation
A Alfa
B Bravo
C Charlie
D Delta
E Echo
F Foxtrot
View am-kantox-2020.stl
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
am-kantox / wgc.ex
Last active April 19, 2023 19:50
Wolf + Goat + Cabbage
View wgc.ex
defmodule WolfGoatCabbage.State do
defstruct banks: %{true => [], false => []}, ltr: true, history: []
defmodule WolfGoatCabbage.Subj do
defstruct me: nil, incompatible: []
defmodule WolfGoatCabbage do
alias WolfGoatCabbage.{State, Subj}
am-kantox / roman_numerals.ex
Created April 23, 2020 07:41
Roman → Arabic conversion for unlimited numbers
View roman_numerals.ex
defmodule RomanNumerals do
require Integer
@romans 'IVXLCDM'
@spec numeral(pos_integer()) :: String.t()
def numeral(number, romans \\ @romans) do
fours = fn
<<c, c, c, c>>, [last], _f -> <<c, last>>
<<c, c, c, c>>, [c, next | _], _f -> <<c, next>>
<<next, c, c, c, c>>, [c, next, result | _], _f -> <<c, result>>