Skip to content

Instantly share code, notes, and snippets.

@ChameleonTartu
ChameleonTartu / beautify_xml_files.sh
Created November 22, 2021 13:49
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
done
@ChameleonTartu
ChameleonTartu / split_xml_file_by_tags.py
Created August 27, 2021 15:20
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'
@ChameleonTartu
ChameleonTartu / remove_docker_containers.sh
Last active January 13, 2021 10:53
Remove all containers
# 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
@ChameleonTartu
ChameleonTartu / git_remove_branches_merged_to_master.sh
Created February 11, 2020 09:39
Remove branches merged into master
# 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
ChameleonTartu / git_push_in_current_branch.sh
Created February 11, 2020 09:34
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):
try:
s = str(symbol).encode(encoding_to)
except:
print('Line: {0}'.format(line))