Skip to content

Instantly share code, notes, and snippets.

View damurashov's full-sized avatar

damurashov

  • Russia, Saint-Petersburg
View GitHub Profile
@damurashov
damurashov / delete_git_submodule.md
Created August 29, 2024 10:40 — forked from myusuf3/delete_git_submodule.md
How effectively delete a git submodule.

To remove a submodule you need to:

  • Delete the relevant section from the .gitmodules file.
  • Stage the .gitmodules changes git add .gitmodules
  • Delete the relevant section from .git/config.
  • Run git rm --cached path_to_submodule (no trailing slash).
  • Run rm -rf .git/modules/path_to_submodule (no trailing slash).
  • Commit git commit -m "Removed submodule "
  • Delete the now untracked submodule files rm -rf path_to_submodule
@damurashov
damurashov / about.md
Last active April 5, 2024 20:13
Fast multiplication of a long word by a known number (multiple of 10)

Testing at godbolt shows that the compiler (ARM GCC none-eabi) generates an efficient code for that.

The gist is the following

a * 10 = (a * 8) + (a * 2) = (a << 3) + (a << 1);

Plus, every number can be represented as a sum of multiples of 2. Proof:

@damurashov
damurashov / oo-replace-sizet.py
Last active March 5, 2024 08:45
`std::size_t` GTFO
#!/usr/bin/python3
import sys
def main():
filename = sys.argv[1]
print('got filename', filename)
with open(filename, 'r') as f:
@damurashov
damurashov / constexprcrc32.cpp
Created November 8, 2022 06:26
C++ 11 (or lower) constexpr conversion of string to CRC32 digest (thanks tower120)
#include <iostream>
// Compile-time CRC32 on strings, courtesy of tower120
// https://stackoverflow.com/questions/2111667/compile-time-string-hashing
// https://stackoverflow.com/users/1559666/tower120
static constexpr unsigned int crc_table[256] = {
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
@damurashov
damurashov / README.md
Created October 7, 2022 11:18
Automatic commit title compilation

Interactive commit message composer.

Usage:

  1. Stage changed files into index
  2. Run the script. It will guide you through commit module and type selection
  • Add --sep option to store each module in a separate commit
  • Add --stem option to replace module enumeration w/ the * symbol
@damurashov
damurashov / file_append.py
Created August 26, 2022 13:59
Append to file, ensure it exists
import os
import pathlib
def file_append(appendix, fname):
if not os.path.exists(fname):
mode = 0o774
path = pathlib.Path(str(fname)).parent.resolve()
@damurashov
damurashov / Makefile
Created August 26, 2022 08:55
Makefile over CMake
build:
mkdir build && cd build && cmake .. && make -j$(shell nproc)
clean:
rm -rf build
.PHONY: clean
import pathlib
import sys
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parent.parent.parent))
@damurashov
damurashov / socat-tty.sh
Created April 22, 2022 07:13 — forked from mathieue/socat-tty.sh
socat read tty serial and provide a server to read serial output
socat -d -d tcp-l:1234,reuseaddr,fork file:/dev/ttyUSB0,nonblock,raw,echo=0,waitlock=/var/run/tty,min=0,b38400
@damurashov
damurashov / logging.py
Created March 8, 2022 07:36
Python logging encapsulation enabling one to print context such as file name, function name, class name.
import logging
import pathlib
import os
import inspect
import time
class Logging:
LEVEL = logging.DEBUG
_logger = None