Skip to content

Instantly share code, notes, and snippets.

@ChameleonTartu
ChameleonTartu / beautify_xml_files.sh
Created Nov 22, 2021
Beautify XML files and make them human-readable in few lines of code
View beautify_xml_files.sh
# 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 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
View split_xml_file_by_tags.py
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
View replace_pattern_in_files.sh
# 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'
View remove_docker_containers.sh
# 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
View git_remove_branches_merged_to_master.sh
# 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 Feb 11, 2020
Push into the current branch with bash terminal alias example
View git_push_in_current_branch.sh
# Example alias in ~/.bash_profile
# alias pcb='git push origin $(git branch --show-current)'
git push origin $(git branch --show-current)
View encode_checker.py
# -*- 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))