Skip to content

Instantly share code, notes, and snippets.

View tomvit's full-sized avatar

Tomas Vitvar tomvit

View GitHub Profile
@tomvit
tomvit / simpleargsparser.py
Last active October 14, 2020 08:32
Simple argument parser what works in both Python and Jython
# @author: Tomas Vitvar, https://vitvar.com, tomas@vitvar.com
import sys
import re
def parse_args(args_def):
"""
Simple argument parser. args_def is a dict in the following format.
The multi property can be used to parse comma separated values.
@tomvit
tomvit / argparser.py
Last active July 27, 2020 18:38
Simple argument parser that works in Jython
import sys
import re
def parse_args(args_def):
"""
Simple argument parser. args_def is a dict in the following format.
The multi property can be used to parse comma separated values.
args_def = {
"user" : { "required": False, "default": "weblogic" },
@tomvit
tomvit / tag-num-commits.sh
Created April 5, 2020 10:34
Get all commits; for each commit show a sequence number of a commit after the last tag
#!/bin/bash
# the last tag
tag=$(git tag | head -1)
# number of commits after tag
c=$(git rev-list $tag..HEAD | wc -l)
c=$((c-0))
# header
printf '%-6s' "TAG" && printf '%-4s' "NUM" && printf "COMMIT\n"
@tomvit
tomvit / XML - create xml along the xpath
Last active July 30, 2017 20:37
Create elements and/or an attribute or a text node along a path in xml.
/**
* Create elements and/or an attribute or a text node along a path in xml.
* Examples: let root be a xml element
* <foo/>
*
* To create a sub-element bar with an attribute id set to a value '5':
* Node n = createXmlPath(root, "/foo/bar/@id", "5");
*
* To create a sub-element bar with a text content set to a value '7':
* Node n = createXmlPath(root, "/foo/bar/text()", "7);