Skip to content

Instantly share code, notes, and snippets.

@valtoni
valtoni / get-latest-tag-on-git.sh
Created August 17, 2018 11:21 — forked from rponte/get-latest-tag-on-git.sh
Getting latest tag on git repository
# The command finds the most recent tag that is reachable from a commit.
# If the tag points to the commit, then only the tag is shown.
# Otherwise, it suffixes the tag name with the number of additional commits on top of the tagged object
# and the abbreviated object name of the most recent commit.
git describe
# With --abbrev set to 0, the command can be used to find the closest tagname without any suffix:
git describe --abbrev=0
# other examples
@valtoni
valtoni / issue-certificate.ssh
Created August 11, 2018 16:28
Complete path to create a certification and PKCS12 format file to be used in tomcat or another server
#!/bin/bash
NAME_KEY=key
FILE=${NAME_KEY}
PRV_KEY_HEX=${FILE}.hex64.key
PRV_KEY=${FILE}.pem
CERT_REQUEST=${FILE}.csr
CERTIFICATE=${FILE}.crt
PKCS12_FILE=${FILE}.pkcs12
@valtoni
valtoni / git-delete-without-upstream.sh
Created July 20, 2018 19:49
Script to delete branches without remote upstream
#!/bin/sh
while read branch; do
upstream=$(git rev-parse --abbrev-ref $branch@{upstream} 2>/dev/null)
if [[ $? == 0 ]]; then
echo $branch tracks $upstream
else
echo $branch has no upstream configured
git branch -D $branch
if [ -z $? ]; then
@valtoni
valtoni / oracle_freespace.sql
Created July 2, 2018 15:31
Shows oracle tablespace free space
select
fs.tablespace_name "Tablespace",
(df.totalspace - fs.freespace) "Used MB",
fs.freespace "Free MB",
df.totalspace "Total MB",
round(100 * (fs.freespace / df.totalspace)) "Pct. Free"
from
(select
tablespace_name,
round(sum(bytes) / 1048576) TotalSpace
@valtoni
valtoni / property_facility.groovy
Created July 2, 2018 10:46
Facility to read and write scaped values to properties file
class Property {
def static Properties instance
public static readProps(String file_name_prop) {
if (!file_name_prop) throw new Exception("You must provide filename to read properties: this is a static method")
def file_prop = new File(file_name_prop)
if (!file_prop.exists()) {
throw new Exception("The file ${file_name_prop} must exists")
}
@valtoni
valtoni / groupjar.sh
Created June 1, 2018 14:03
Nice count and sort jar files grouped by directory
find . -name "*.jar" | rev | cut -d "/" -f 2-10 | rev | uniq -c | sort
@valtoni
valtoni / heatmap.sh
Created April 13, 2018 17:15
Show the top most changed files in git repository
git log --name-status $* | grep -E '^[A-Z]\s+' | cut -c3-500 | sort | uniq -c | grep -vE '^ {6}1 ' | sort -n | tail --lines="$ROW_LIMIT"
@valtoni
valtoni / gist:13e5873d2dc1c8841e1d2a6c0ba0624c
Created March 9, 2018 18:07
Prompt Maroto (put this on .bashrc file)
# Copy https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh into ~/.git-prompt.sh
source ~/.git-prompt.sh
PS1='\n\[\e[30;1m\]\[\016\]l\[\017\](\[\e[34;1m\]\u@\h\[\e[30;1m\])-(\[\e[34;1m\]\j\[\e[30;1m\])-(\[\e[34;1m\]\@ \d\[\e[30;1m\])$(__git_ps1 "-(\[\e[35;1m\]%s\[\e[30;1m\])")->\[\e[30;1m\]\n\[\016\]m\[\017\]-(\[\[\e[32;1m\]\w\[\e[30;1m\])\[\e[0m\]'
@valtoni
valtoni / docker-cleanup-resources.md
Created February 23, 2018 12:31 — forked from bastman/docker-cleanup-resources.md
docker cleanup guide: containers, images, volumes, networks

Docker - How to cleanup (unused) resources

Once in a while, you may need to cleanup resources (containers, volumes, images, networks) ...

delete volumes

// see: https://github.com/chadoe/docker-cleanup-volumes

$ docker volume rm $(docker volume ls -qf dangling=true)

$ docker volume ls -qf dangling=true | xargs -r docker volume rm

@valtoni
valtoni / zip.py
Created November 4, 2017 15:09
Very simple command line zip with python
#!/usr/bin/python
import sys
import os
import zipfile
def main(argv):
zip_file_name = argv[1]
zfi = zipfile.ZipFile(zip_file_name, "w", zipfile.ZIP_DEFLATED)
cur_dir = os.getcwd()
for i in range(2, len(argv)):