Skip to content

Instantly share code, notes, and snippets.

ChameleonTartu /
Created Nov 22, 2021
Beautify XML files and make them human-readable in few lines of code
# In my case files resided under empty_files folder
for file in empty_files/*; do
xmllint --format $file --output $file
ChameleonTartu /
Created Aug 27, 2021
Split XML file by tags, it allows to split large files and process atomic files. It helps to find issue with data
from lxml import etree
# Add your xml file here
XML_FILE = 'src/bisection_search.xml'
# Change your tag here by which to split
SPLIT_BY_TAG = 'Invoice'
# Add folder where to store splitted files
# Problem:
# I had a Javadoc which automatically generated extra tags which I didn't need in all *.java files.
# Soltuion:
# Find all occurances and do in-place replacement in all files.
# In my case pattern was "@version $Id: $Id" but it can be anything
grep -rlZ '@version $Id: $Id' . | xargs sed -i '' 's/@version $Id: $Id//g'
# Remove docker containers
docker ps -a | cut -c 1-12 | tail -n +2 | xargs docker rm
# Remove docker images forcibly
docker images -a | cut -c 72-83 | tail -n +2 | xargs docker rmi -f
# Example alias in Bash terminal
# alias rmmb='git branch --merged | egrep -v "(^\*|master)" | xargs git branch -d'
git branch --merged | egrep -v "(^\*|master)" | xargs git branch -d
ChameleonTartu /
Created Feb 11, 2020
Push into the current branch with bash terminal alias example
# Example alias in ~/.bash_profile
# alias pcb='git push origin $(git branch --show-current)'
git push origin $(git branch --show-current)
# -*- coding: utf-8 -*-
def find_non_encodable_symbols(input_file, encoding_from, encoding_to):
with open(input_file, 'r', encoding=encoding_from) as file:
for row, line in enumerate(file):
for pos, symbol in enumerate(line):
s = str(symbol).encode(encoding_to)
print('Line: {0}'.format(line))