Skip to content

Instantly share code, notes, and snippets.

@valtoni
valtoni / char-donot-repeat.py
Created April 18, 2016 11:30
Do not repeat chars in python
word = raw_input()
reduced_word = ''.join(
[char for index, char in enumerate(word) if char not in word[0:index]])
@valtoni
valtoni / extract_cert_keystore.sh
Created May 29, 2016 13:36
Script to export certificate and private key from jks store
#!/bin/bash
FILE=$1
OUTPUT_NAME=$2
# Export to PKCS12 format
keytool -importkeystore -srckeystore "$FILE" -destkeystore "$OUTPUT_NAME".p12 -deststoretype PKCS12
# Export certificate in pem format
openssl pkcs12 -in "$OUTPUT_NAME".p12 -nokeys -out "$OUTPUT_NAME"_cert.pem
# Export certificate in x509 format
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
public class ReferenceToConstructor {
/**
* @param args the command line arguments
*/
@valtoni
valtoni / git-branches-by-commit-date.sh
Created September 2, 2016 18:46 — forked from l15n/git-branches-by-commit-date.sh
List remote Git branches and the last commit's author and author date for each branch. Sort by most recent commit's author date.
# Credit http://stackoverflow.com/a/2514279
for branch in `git branch -r | grep -v HEAD`;do echo -e `git show --format="%ai %ar by %an" $branch | head -n 1` \\t$branch; done | sort -r
@valtoni
valtoni / git-rewrite-source-target.sh
Last active October 18, 2016 11:44
Rewrite target author and commiter name/email/date with data from source commit
#!/bin/sh
# Rewrite's the commit with data from source commit
echo "WARNING: Your TARGET_COMMIT must have in your current branch."
SOURCE_COMMIT=$1
TARGET_COMMIT=$2
SOURCE_COMMIT=$(git rev-parse $SOURCE_COMMIT)
if [ $? -ne 0 ]; then
@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)):
@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 / 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 / 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 / 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