Skip to content

Instantly share code, notes, and snippets.

View mkatychev's full-sized avatar
💭
Убейся в праздники! Раб, твои галеры в огне

Mikhail Katychev mkatychev

💭
Убейся в праздники! Раб, твои галеры в огне
View GitHub Profile
@mkatychev
mkatychev / var_expand.nu
Created December 1, 2025 20:25
Expand enviromental variables right to left
def fill-env-var [] {
let current_prompt = (commandline)
let var_idx = $current_prompt | str index-of "$env." --end
let head = match $var_idx {
# no '$env.' was found
-1 => return
0 => ""
$idx => ($current_prompt | str substring ..($idx - 1))
}
# 5 is the offset for f in '$env.foo`
@mkatychev
mkatychev / prompt.nu
Created November 10, 2025 14:39
Nushell status prompt
def git-icon [
colour # ansi colour argument
one # icon for a match quantity of one
many # icon for a match quantity of two or more
]: int -> oneof<string, nothing> {
let icon = match $in {
1 => $one
2.. => $many
_ => (return null)
}
@mkatychev
mkatychev / fd_sd.nu
Last active November 4, 2025 13:56
Find + Search and Replace Nushell
def is-help []: list<any> -> bool {
('-h' in $in) or ('--help' in $in)
}
export def fd --wrapped [...$args]: nothing -> oneof<list<string>, nothing> {
if ($args | is-help) {
return (^fd ...$args)
}
^fd ...$args | lines
}
@mkatychev
mkatychev / hibernate.nu
Created November 3, 2025 16:30
Hibernate mode toggle macOS
def hmode [] {
let entry = pmget | where setting == "hibernatemode"
let name = match ($entry.mode.0 | into int) {
3 => "off"
25 => "on"
0 => "hard"
$n => $n
}
{hibernate: $name }
}
@mkatychev
mkatychev / wit_doc_comment.rs
Last active October 24, 2025 19:38
To run: `cargo +nightly -Zscript ./wit_doc_comment.rs`
---cargo
[dependencies]
tree-sitter-wit = { git = "https://github.com/bytecodealliance/tree-sitter-wit", version = "1.2.0" }
tree-sitter = "0.25.10"
---
use tree_sitter::{Parser, Point, Query, QueryCursor, StreamingIterator};
const WIT_FILE: &str = "
/// DOC COMMENT `wasmcloud`
@mkatychev
mkatychev / telemetry.md
Last active April 24, 2025 21:51
telemetry.md

Telemetry

What is OpenTelemetry?

OpenTracing   == traces            ( jaeger/tokio-tracing )
OpenCensus    == metrics           ( grafana/prometheus   )
OpenTelemetry == traces && metrics ( et al.               )
@mkatychev
mkatychev / nvim-fmt-buf.lua
Last active December 11, 2024 21:46
Tiny Neovim buffer formatter in lua
local read_buf = function(bufnr)
local bufin = table.concat(vim.api.nvim_buf_get_lines(bufnr, 0, -1, true), "\n")
if vim.api.nvim_get_option_value("eol", { buf = bufnr }) then bufin = bufin .. "\n" end
return bufin
end
local format_buf = function(fmt_cmd)
-- exit early if buffer is not writeable
if vim.bo.modifiable == false or vim.bo.readonly == true then return end
-- save cursor position
@mkatychev
mkatychev / shoe_tray_leg.scad
Created October 17, 2024 14:23
shoe_tray_leg
$fn = 48;
function line(point1, point2, width = 1) =
let(angle = 90 - atan((point2[1] - point1[1]) / (point2[0] - point1[0])))
let(offset_x = 0.5 * width * cos(angle), offset_y = 0.5 * width * sin(angle))
let(offset1 = [-offset_x, offset_y], offset2 = [offset_x, -offset_y])
@mkatychev
mkatychev / record.rs
Created September 7, 2024 23:04
`record!` macro
#[macro_export]
macro_rules! record {
($($fields:tt)+) => {
let fieldset = tracing::fieldset!($($fields)+);
$crate::valueset!(fieldset, $($fields)+);
};
}
#[macro_export]
macro_rules! valueset {
include <relativity.scad/relativity.scad>
$fn = 20;
module base() {
minkowski() {
box([30, 80, 4]);
cylinder(0.5, r = 4);
}
}