Skip to content

Instantly share code, notes, and snippets.

View jgru's full-sized avatar

Jan jgru

View GitHub Profile
@jgru
jgru / repnocc.py
Created April 12, 2021 08:13
A tool for manipulation of text files. It replaces the last n occurences of a given character in each line and prints the result on stdout
#!/bin/python3
import sys
import argparse
def repl_stream(inp, n, inchar, outchar):
"""
Replaces n last inchars in io wrapper with outchars
and prints to stdout.
<#
.SYNOPSIS
This script creates a .xml-file containing the installed choco packages
with their corresponding version numers
.DESCRIPTION
This script creates a .xml-file containing the installed choco packages,
which can be used to automate the install of these packages in the exact same
version on a different system. (Right now you can get this only by using the
choco GUI-tool)
@jgru
jgru / cli_template.py
Last active June 5, 2021 14:24
A minimal template for building a CLI, which reads from a positional file-parameter, if such an argument is existent and from stdin otherwise.
#!/usr/bin/python3
import argparse
import sys
"""
This is a minimal template for building a CLI, which reads from a positional file-parameter, if such a argument is
existent and from stdin otherwise.
Usage:
#!/usr/bin/python3
import sys
import re
import argparse
from http import HTTPStatus
req_pattern = r'\"(GET|POST|PUT|DELETE)\s(.*)\"\s(\d{3})'
ts_pattern = r'\[(.*)\s[-+]\d{4}\]'