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 / 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 / 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 / .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"

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 / 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'
@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 / datediff.c
Created January 16, 2025 19:37
`datediff` is a simple C program that calculates the number of days between two dates provided in the format `YYYY-MM-DD`. It is a lightweight and efficient utility for quick date difference calculations
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
// Function to convert a date string to a struct tm
int parse_date(const char *date_str, struct tm *date)
{
memset(date, 0, sizeof(struct tm));