Skip to content

Instantly share code, notes, and snippets.

Avatar
🎩
constantly matching the patterns

Aleksei Matiushkin am-kantox

🎩
constantly matching the patterns
View GitHub Profile
@am-kantox
am-kantox / single-multiple-select.bash
Created Jan 27, 2023
Implementation for single and multiple selects in bash
View single-multiple-select.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#*[}; }
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
am-kantox / cyrillic-sorter.ex
Created Apr 12, 2022
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
am-kantox / spelling.md
Created Feb 3, 2022
Spelling Alphabets
View spelling.md

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
am-kantox / wgc.ex
Last active Apr 26, 2021
Wolf + Goat + Cabbage
View wgc.ex
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 Apr 23, 2020
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>>
@am-kantox
am-kantox / silverfish.md
Last active Apr 2, 2020
Карасик
View silverfish.md

The Silverfish Programming Language

Original by @netricks

They say, each professional developer must have done at least three pet projects: a sophisticated logging utility, a smart json parser, and an amazing programming language. Once we have both logger and parser accomplished, we finally decided to reveal our desperate success in creation one of the most innovative programming languages named Silverfish.

Карасик → На самом деле плотвичка

As we all know, the universe is constantly moving around. Evolution of programming languages is not even close to complete. New languages emerge every year, to undergo the laboratory testing on human beings and die in oblivion, sooner ot later. The vast majority of innovations in any new language could barely be considered a result of new development, but as the evolution of well-known approaches or even old good wheels re-invention.

View wc-counters.ex
defmodule Wc do
@prehandle 42
@sink @prehandle + 1
@chunk 1_000_000
@type acc_counters :: 0 | 1
@spec counters(binary) :: acc()
def counters(file) do
cs = :counters.new(3, [:write_concurrency])