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 March 20, 2024 07:33
config.lua
-- Read the docs: https://www.lunarvim.org/docs/configuration
-- 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.format_on_save.enabled = true
lvim.colorscheme = "nord"
-- keymappings [view all the defaults by pressing <leader>Lk]
lvim.leader = "space"
@am-kantox
am-kantox / digest_benchmark.rb
Created March 29, 2017 14:28
Ruby :: benchmark of different digests
require 'benchmark/ips'
n = 500000
require 'digest/md5'
require 'digest/sha1'
require 'digest/sha2'
require 'digest/sha3' # https://github.com/phusion/digest-sha3-ruby
INPUT = [5, "Hello, world", nil]
@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 / 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 / .pryrc
Created October 27, 2018 05:37
.pryrc
# === EDITOR ===
Pry.editor = 'vi'
# === PROMPT ===
Pry.prompt = [ ->(obj, nest_level, _) { "✎ " }, ->(obj, nest_level, _) { "#{' ' * nest_level} " } ]
# === COLORS ===
unless ENV['PRY_BW']
Pry.color = true
Pry.config.theme = "railscasts"
@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