Skip to content

Instantly share code, notes, and snippets.

View leonid-ed's full-sized avatar

Leonid Edrenkin leonid-ed

View GitHub Profile
@leonid-ed
leonid-ed / the_art_of_unix_programming.md
Created October 27, 2024 17:52
The Art of Unix Programming

Rules from Doug McIlroy (Unix developer, the author of the Pipes mechanism):

  1. Make each program do one thing well. To do a new job, build afresh rather than complicate old programs by adding new features.
  2. Expect the output of every program to become the input to another, as yet unknown, program. Don’t clutter output with extraneous information. Avoid stringently columnar or binary input formats. Don’t insist on interactive input.
  3. Design and build software, even operating systems, to be tried early, ideally within weeks. Don’t hesitate to throw away the clumsy parts and rebuild them.
@leonid-ed
leonid-ed / make_record.sh
Last active August 12, 2024 18:07
A short Bash script to make quick records with time spent
# This is a script to make short records about activities with time spent in minutes.
# Dependencies:
# - tac - (install: $ brew install coreutils)
# - align - (install: https://github.com/Guitarbum722/align/tree/master/cmd/align, $ go build -o align && go install)
#
# You can add alias with shortcuts to your bash/zsh config:
# alias mr='/Users/leonid/bash-scripts/make_record.sh add'
# alias mrs='/Users/leonid/bash-scripts/make_record.sh show'
# alias mrsf='/Users/leonid/bash-scripts/make_record.sh show-filter'
# alias mre='/Users/leonid/bash-scripts/make_record.sh edit'

Keybase proof

I hereby claim:

  • I am leonid-ed on github.
  • I am leonided (https://keybase.io/leonided) on keybase.
  • I have a public key ASABKy69asMsnQRSChUTFtYgLtzc0YNEwDeOnCiwJIWBkAo

To claim this, I am signing this object:

@leonid-ed
leonid-ed / .vimrc
Created June 11, 2020 08:57
SelectIndentOn() function for VIM to select all the lines with the same indent level in Python
" Inspired by https://vim.fandom.com/wiki/Visual_selection_of_indent_block
" This version additionaly goes through empty lines to select also separated blocks
" on the same indent level.
function SelectIndentOn()
let temp_var=indent(line("."))
if temp_var is 0 | return | endif
while (line(".") > 1) &&
\ ((indent(line(".")-1) >= temp_var) || (getline(line(".")-1) is ""))
exe "normal k"
@leonid-ed
leonid-ed / static_inline_example.md
Created March 21, 2020 10:36 — forked from htfy96/static_inline_example.md
static inline vs inline vs static in C++

In this article we compared different behavior of static, inline and static inline free functions in compiled binary. All the following test was done under g++ 7.1.1 on Linux amd64, ELF64.

Test sources

header.hpp

#pragma once

inline int only_inline() { return 42; }
static int only_static() { return 42; }
@leonid-ed
leonid-ed / weighted_quick_union_with_path_compression.py
Created July 15, 2019 20:40
Python implementation of weighted quick-union with path compression algorithm
class WeightedQuickUnionWithPathCompressionUF():
"""Weighted quick-union with path compression algorithm
The original Java implementation is introduced at:
https://algs4.cs.princeton.edu/15uf/index.php#1.5
https://www.cs.princeton.edu/~rs/AlgsDS07/01UnionFind.pdf
Time complexity:
constructor: O(n)
union: amortized ~O(1)
@leonid-ed
leonid-ed / clipboard-lines-copier.py
Last active March 16, 2017 08:14
Sublime Text 3 plugin that copies selected lines to the clipboard.
# The MIT License (MIT)
# Copyright (c) 2016 Leonid Edrenkin
#
# This is a Sublime Text 3 plugin that copies selected lines to the clipboard.
# You should select text lines and apply command:
# view.run_command('copy_lines_to_clipboard')
# view.run_command('copy_lines_to_clipboard', {"with_filename": True})
# view.run_command('copy_lines_to_clipboard', {"with_filename": True, "tabsize" : 4})
@leonid-ed
leonid-ed / Text-item-list.py
Last active October 10, 2016 09:55
This is a Sublime Text 3 plugin that makes a numberred list.
# The MIT License (MIT)
# Copyright (c) 2016 Leonid Edrenkin
#
# This is a Sublime Text 3 plugin that makes and unmakes a numberred list.
# You should select text lines and apply one of commands:
# view.run_command('make_numberred_list')
# view.run_command('unmake_numberred_list')
import sublime, sublime_plugin
@leonid-ed
leonid-ed / C-make-multiline-macro.py
Created April 28, 2016 08:15
This is a Sublime Text 3 plugin that makes an adjusted multiline C-macro
# The MIT License (MIT)
# Copyright (c) 2016 Leonid Edrenkin
#
# This is a Sublime Text 3 plugin that makes an adjusted multiline C-macro.
# You should select some code and apply one of commands:
# view.run_command('make_multi_line_macro')
# view.run_command('unmake_multi_line_macro')
import sublime, sublime_plugin
@leonid-ed
leonid-ed / prepare-commit-msg
Last active April 28, 2016 08:00
.git/hooks/prepare-commit-msg showing latest 15 commit messages
# The MIT License (MIT)
# Copyright (c) 2016 Leonid Edrenkin
#
#!/bin/bash
case "$2,$3" in
message,HEAD)
;;
*)