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
am-kantox / config.lua
Last active August 4, 2024 10:02
config.lua
-- Read the docs: https://www.lunarvim.org/docs/configuration
-- Example configs: https://github.com/LunarVim/starter.lvim
-- Video Tutorials: https://www.youtube.com/watch?v=sFA9kX-Ud_c&list=PLhoH5vyxr6QqGu0i7tt_XoVK9v-KvZ3m6
-- Forum: https://www.reddit.com/r/lunarvim/
-- Discord: https://discord.com/invite/Xb9B4Ny
lvim.lsp.installer.setup.automatic_installation = false
lvim.format_on_save.enabled = true
lvim.colorscheme = "nord"
@am-kantox
am-kantox / mapset_ex.ex
Created February 4, 2023 09:42
`MapSet` matchers/guards
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
```elixir
fn mapset() -> :ok end.(MapSet.new())
fn mapset() -> :ok end.(MapSet.new([1, 2]))
fn mapset([1]) -> :ok end.(MapSet.new([1, 2]))
```
and the following would not
@am-kantox
am-kantox / single-multiple-select.bash
Created January 27, 2023 16:26
Implementation for single and multiple selects in bash
function multiselect {
# credits: https://unix.stackexchange.com/a/673436/55106 (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
am-kantox / thinknetica_behaviour.ex
Last active December 15, 2022 04:13
Behaviour Example
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
am-kantox / cyrillic-sorter.ex
Created April 12, 2022 03:50
Naïve string sorter for Russian Cyrillic
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
am-kantox / spelling.md
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@am-kantox
am-kantox / wgc.ex
Last active April 19, 2023 19:50
Wolf + Goat + Cabbage
defmodule WolfGoatCabbage.State do
defstruct banks: %{true => [], false => []}, ltr: true, history: []
end
defmodule WolfGoatCabbage.Subj do
defstruct me: nil, incompatible: []
end
defmodule WolfGoatCabbage do
alias WolfGoatCabbage.{State, Subj}
@am-kantox
am-kantox / roman_numerals.ex
Created April 23, 2020 07:41
Roman → Arabic conversion for unlimited numbers
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>>